trading_agent.terminal.chat_items
¶
The pieces of a chat: turns, the steps inside them, and events that belong to no turn.
They mirror the web page's chatTurnBuilder.ts types, and ChatTranscript fills them in from gateway events.
Typical usage example:
turn = ChatTurn(trigger_id='t1', source='user_message', text='Hello') turn.status_text() # 'waiting in the queue'
ToolStep
dataclass
¶
ToolStep(call_id, name, arguments, result_text=None, is_error=False, picture_path=None, ended_early=False)
One tool call inside a turn, with its result once it arrives.
Attributes:
| Name | Type | Description |
|---|---|---|
call_id |
str
|
The call's id, which its result carries too. |
name |
str
|
The tool's name. |
arguments |
dict[str, Any]
|
The call's arguments. |
result_text |
str | None
|
The tool's answer, or None while it runs. |
is_error |
bool
|
Whether the tool reported a failure. |
picture_path |
str | None
|
A picture the tool showed the model, relative to the desk folder, or None. |
ended_early |
bool
|
Whether the turn ended, for example by a stop, before the tool answered. |
arguments_text
¶
The arguments as indented JSON.
Returns:
| Type | Description |
|---|---|
str
|
The JSON text. |
EventStep
dataclass
¶
Any other event shown inside a turn, such as a risk decision or a model switch.
Attributes:
| Name | Type | Description |
|---|---|---|
event |
dict[str, Any]
|
The event, with kind, desk, payload and created_at. |
SteeringStep
dataclass
¶
A message the user sent while the turn was running, at the point it arrived.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
ChatTurn
|
The message's own turn, which says whether it reached the running turn. |
RequestStep
dataclass
¶
A question, plan or permission request the desk made during a turn, with its latest status.
Attributes:
| Name | Type | Description |
|---|---|---|
request |
dict[str, Any]
|
The request, as GET /api/requests returns it. |
ToolRun
dataclass
¶
Tool calls in a row, shown as one folded line.
Attributes:
| Name | Type | Description |
|---|---|---|
steps |
list[ToolStep]
|
The tool calls, in order. |
ChatTurn
dataclass
¶
ChatTurn(trigger_id, source, text, attachments=list(), received_at='', started_at=None, finished_at=None, started=False, finished=False, steps=list(), answer=None, silent=False, error=None, backend=None, steering_into=None, steering_outcome=None, stopped=False, request_id=None, streaming_text='')
One trigger and everything the desk did about it.
Attributes:
| Name | Type | Description |
|---|---|---|
trigger_id |
str
|
The trigger's id. |
source |
str
|
What woke the desk, such as "user_message" or "cron". |
text |
str
|
The trigger's text. |
attachments |
list[dict[str, Any]]
|
The files the user sent with it. |
received_at |
str
|
When the gateway received it, as ISO text. |
started_at |
str | None
|
When the turn started, or None. |
finished_at |
str | None
|
When the turn finished, or None. |
started |
bool
|
Whether the turn has started. |
finished |
bool
|
Whether the turn has finished. |
steps |
list[ToolStep | EventStep | SteeringStep | RequestStep]
|
Tool calls, events, steering messages and requests, in order. |
answer |
str | None
|
The desk's final answer, or None until it arrives. |
silent |
bool
|
Whether the desk decided there was nothing to say. |
error |
str | None
|
Why the turn failed, or None. |
backend |
str | None
|
The backend that answered, or None. |
steering_into |
str | None
|
The running turn this message was handed to, or None. |
steering_outcome |
str | None
|
"waiting", "delivered" or "queued" for a steering message, otherwise None. |
stopped |
bool
|
Whether the user stopped the turn. |
request_id |
str | None
|
The question, plan or permission this trigger answers, or None. |
streaming_text |
str
|
The text the desk is writing now, before the final answer arrives. |
status_text
¶
Where the turn has got to, in the web page's words.
Returns:
| Type | Description |
|---|---|
str
|
A short status line, such as "answered by claude" or "waiting in the queue". |
Source code in src/trading_agent/terminal/chat_items.py
running_tool
¶
The tool call still waiting for its result, if any.
Returns:
| Type | Description |
|---|---|
ToolStep | None
|
The newest tool call when it has no result yet, otherwise None. |
Source code in src/trading_agent/terminal/chat_items.py
segments
¶
The steps, with tool calls in a row grouped into one run.
Returns:
| Type | Description |
|---|---|
list[ToolRun | EventStep | SteeringStep | RequestStep]
|
The segments, in order. |
Source code in src/trading_agent/terminal/chat_items.py
LooseEvent
dataclass
¶
An event that belongs to no turn, such as a fill reported while the desk was idle.
Attributes:
| Name | Type | Description |
|---|---|---|
event |
dict[str, Any]
|
The event. |