Skip to content

trading_agent.terminal.widgets.tool_call_view

One tool call, folded to a line with its name and state, opening to its arguments and result.

Typical usage example:

view = ToolCallView(step) view.show(step)

ToolCallView

ToolCallView(step)

Bases: Collapsible

A tool call's card.

Creates the card.

Parameters:

Name Type Description Default
step ToolStep

The tool call.

required
Source code in src/trading_agent/terminal/widgets/tool_call_view.py
def __init__(self, step: chat_items.ToolStep):
    """Creates the card.

    Args:
        step (chat_items.ToolStep): The tool call.
    """
    self._arguments = widgets.Static(
        step.arguments_text(), markup=False, classes='tool-arguments'
    )
    self._result = widgets.Static('', markup=False, classes='tool-result')
    self._step = step
    super().__init__(
        containers.Vertical(
            widgets.Static('Arguments', classes='tool-heading'),
            self._arguments,
            widgets.Static('Result', classes='tool-heading'),
            self._result,
            classes='tool-body',
        ),
        title=self._title_content(step),
        collapsed=True,
        classes='tool-call',
    )

on_mount

on_mount()

Fills the card once it is on screen.

Source code in src/trading_agent/terminal/widgets/tool_call_view.py
def on_mount(self) -> None:
    """Fills the card once it is on screen."""
    self.show(self._step)

show

show(step)

Updates the card from the tool call.

Parameters:

Name Type Description Default
step ToolStep

The tool call, perhaps now with its result.

required
Source code in src/trading_agent/terminal/widgets/tool_call_view.py
def show(self, step: chat_items.ToolStep) -> None:
    """Updates the card from the tool call.

    Args:
        step (chat_items.ToolStep): The tool call, perhaps now with its result.
    """
    self._step = step
    self.title = self._title_content(step)
    result = step.result_text
    if result is None and step.ended_early:
        result = 'No result: the turn ended before the tool answered.'
    elif result is None:
        result = 'running…'
    elif len(result) > _MOST_RESULT_CHARACTERS:
        result = (
            result[:_MOST_RESULT_CHARACTERS]
            + f'\n… {len(result) - _MOST_RESULT_CHARACTERS} more characters'
        )
    self._result.update(result)
    self.set_class(step.is_error, 'failed')