Skip to content

trading_agent.terminal.widgets.tool_run_view

Tool calls in a row, folded into one summary line as Claude Code shows them.

Pictures the tools showed the model stay visible under the summary even while the run is folded, as on the web page.

Typical usage example:

view = ToolRunView('general', run) view.show(run)

ToolRunView

ToolRunView(desk_name, run)

Bases: Vertical

A run of tool calls, with their pictures.

Creates the run's view.

Parameters:

Name Type Description Default
desk_name str

The desk, whose folder the pictures are in.

required
run ToolRun

The tool calls.

required
Source code in src/trading_agent/terminal/widgets/tool_run_view.py
def __init__(self, desk_name: str, run: chat_items.ToolRun):
    """Creates the run's view.

    Args:
        desk_name (str): The desk, whose folder the pictures are in.
        run (chat_items.ToolRun): The tool calls.
    """
    super().__init__(classes='tool-run')
    self._desk_name = desk_name
    self._run = run
    self._calls: list[tool_call_view.ToolCallView] = []
    self._fold = widgets.Collapsible(
        title=self._title_content(run), collapsed=True
    )
    self._pictures = containers.Vertical(classes='tool-pictures')
    self._shown_pictures: set[str] = set()

compose

compose()

Builds the view.

Yields:

Type Description
Widget

The folded run and the pictures under it.

Source code in src/trading_agent/terminal/widgets/tool_run_view.py
def compose(self):
    """Builds the view.

    Yields:
        Widget: The folded run and the pictures under it.
    """
    yield self._fold
    yield self._pictures

on_mount

on_mount()

Adds the cards once the run is on screen.

Source code in src/trading_agent/terminal/widgets/tool_run_view.py
def on_mount(self) -> None:
    """Adds the cards once the run is on screen."""
    self.show(self._run)

show

show(run)

Updates the summary, the cards and the pictures, adding new ones.

Parameters:

Name Type Description Default
run ToolRun

The tool calls, perhaps with more of them or more results.

required
Source code in src/trading_agent/terminal/widgets/tool_run_view.py
def show(self, run: chat_items.ToolRun) -> None:
    """Updates the summary, the cards and the pictures, adding new ones.

    Args:
        run (chat_items.ToolRun): The tool calls, perhaps with more of them or more results.
    """
    self._run = run
    self._fold.title = self._title_content(run)
    for index, step in enumerate(run.steps):
        if index < len(self._calls):
            self._calls[index].show(step)
        else:
            card = tool_call_view.ToolCallView(step)
            self._calls.append(card)
            self._fold.query_one(widgets.Collapsible.Contents).mount(card)
        if (
            step.picture_path
            and step.picture_path not in self._shown_pictures
        ):
            self._shown_pictures.add(step.picture_path)
            self._pictures.mount(
                picture_view.PictureView(
                    self._desk_name, picture_path=step.picture_path
                )
            )

expand_all

expand_all(expanded)

Opens or folds the run and every card in it.

Parameters:

Name Type Description Default
expanded bool

True to open, False to fold.

required
Source code in src/trading_agent/terminal/widgets/tool_run_view.py
def expand_all(self, expanded: bool) -> None:
    """Opens or folds the run and every card in it.

    Args:
        expanded (bool): True to open, False to fold.
    """
    self._fold.collapsed = not expanded
    for card in self._calls:
        card.collapsed = not expanded