Skip to content

trading_agent.terminal.screens.skills_screen

The Skills page: the skills a desk can follow, with their use counts, and the skills hidden from it with what each is missing.

It copies the web page's SkillsPage.tsx.

Typical usage example:

app.push_screen(SkillsScreen('general'))

SkillsScreen

SkillsScreen(desk_name)

Bases: PageScreen

The Skills page.

Source code in src/trading_agent/terminal/screens/page_screen.py
def __init__(self, desk_name: str):
    """Creates the page.

    Args:
        desk_name (str): The desk the chat shows, which a desk's page starts on.
    """
    super().__init__(classes='page')
    self.desk_name = desk_name

compose_page

compose_page()

Builds the two tables.

Yields:

Type Description
Widget

The sections, in a scroll area.

Source code in src/trading_agent/terminal/screens/skills_screen.py
def compose_page(self):
    """Builds the two tables.

    Yields:
        Widget: The sections, in a scroll area.
    """
    with containers.VerticalScroll(classes='page-body'):
        yield widgets.Static('[b]Usable[/b]', classes='page-heading')
        yield widgets.DataTable(id='skills-available', cursor_type='row')
        yield widgets.Static(
            '[b]Hidden[/b] [dim]a skill is hidden while something it needs is missing[/dim]',
            classes='page-heading',
        )
        yield widgets.DataTable(id='skills-hidden', cursor_type='row')

on_mount

on_mount()

Sets up the tables, then reads the skills.

Source code in src/trading_agent/terminal/screens/skills_screen.py
def on_mount(self) -> None:
    """Sets up the tables, then reads the skills."""
    self.table('skills-available').add_columns(
        'Skill',
        'What it is for',
        'Origin',
        'Uses',
        'With trouble',
        'Last used',
    )
    self.table('skills-hidden').add_columns('Skill', 'Missing')
    super().on_mount()

refresh_page async

refresh_page()

Reads the desk's skills.

Source code in src/trading_agent/terminal/screens/skills_screen.py
@work(exclusive=True, group='page')
async def refresh_page(self) -> None:
    """Reads the desk's skills."""
    try:
        answer = await self.app.gateway.skills(self.desk_name)
    except gateway_client.GatewayError as error:
        self.problem(error.message)
        return
    clock = formatter.Formatter()
    table = self.table('skills-available')
    table.clear()
    for skill in answer.get('available') or []:
        origin = 'yours'
        if skill.get('origin') == 'agent':
            origin = 'written by the desk'
        last_used = '—'
        if skill.get('last_used'):
            last_used = clock.day_time(str(skill['last_used']))
        table.add_row(
            str(skill.get('name', '')),
            str(skill.get('description', ''))[:70],
            origin,
            str(skill.get('uses', 0)),
            str(skill.get('troubled_uses', 0)),
            last_used,
        )
    hidden = self.table('skills-hidden')
    hidden.clear()
    for skill in answer.get('hidden') or []:
        missing = skill.get('missing') or []
        hidden.add_row(
            str(skill.get('name', '')),
            ', '.join(str(item) for item in missing),
        )