trading_agent.tools.tool_call_executor
¶
Runs one tool call the same way for every backend.
Whether the call comes from the agent loop (Gemma, Qwen, OpenAI) or from Claude Code, it is published, checked by the loop guard and the permission gate, run through the registry, and its result published. Keeping that in one place means every backend gets the same protections.
Typical usage example:
executor = ToolCallExecutor('main', registry, event_bus, loop_guard) executor.start_turn() result = await executor.execute(trigger, call)
CompletedCall
dataclass
¶
A tool call that ran, or was held for permission, during a turn.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The tool. |
arguments |
dict[str, Any]
|
The arguments it was called with. |
result_text |
str
|
What it returned. |
is_error |
bool
|
Whether it failed. |
ToolCallExecutor
¶
Runs a desk's tool calls through the loop guard and the registry.
Attributes:
| Name | Type | Description |
|---|---|---|
tool_registry |
The desk's tools. |
Creates the executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk the calls belong to, used to tag events. |
required |
tool_registry
|
ToolRegistry
|
The desk's tools. |
required |
event_bus
|
EventBus
|
Where calls and results are published. |
required |
loop_guard
|
LoopGuard
|
The guard against repeated identical calls. |
required |
permission_gate
|
PermissionGate | None
|
Holds calls that need the user's permission, or None when none do. |
None
|
Source code in src/trading_agent/tools/tool_call_executor.py
start_turn
¶
execute
async
¶
Publishes a call, runs it unless the guard refuses it, and publishes the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trigger
|
Trigger
|
The trigger of the current turn. |
required |
call
|
ToolCall
|
The call to run. |
required |
Returns:
| Type | Description |
|---|---|
ToolResult
|
The tool's result, the guard's refusal, or a note that the call waits for the user's permission. |
Source code in src/trading_agent/tools/tool_call_executor.py
completed_calls
¶
The calls that ran, or were held for permission, for one trigger, oldest first.
The model router reads them when a backend fails partway through a turn, so the next backend does not repeat them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trigger_id
|
str
|
The trigger. |
required |
Returns:
| Type | Description |
|---|---|
list[CompletedCall]
|
The calls; empty when none ran or the trigger is too old to be remembered. |