trading_agent.tools.tool_registry
¶
Holds a desk's tools and runs them by name.
The registry is the one place where a tool call from the model meets real code. It checks the arguments, applies a time limit, catches failures and caps the size of the output, so a misbehaving tool cannot crash the desk or flood the model's context.
Typical usage example:
registry = ToolRegistry([GetTimeTool()], timeout_seconds=60) result = await registry.run(tool_call)
ToolRegistry
¶
The tools available to one desk.
Creates a registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools
|
Sequence[Tool]
|
The tools, each with a unique name. |
required |
timeout_seconds
|
float
|
How long one tool call may run before it is stopped. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Two tools have the same name. |
Source code in src/trading_agent/tools/tool_registry.py
definitions
¶
Describes every tool in the function-calling format Ollama and OpenAI share.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
One {"type": "function", "function": {...}} entry per tool. |
Source code in src/trading_agent/tools/tool_registry.py
run
async
¶
Runs one tool call and always returns a result, never raises.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
call
|
ToolCall
|
The call the model made. |
required |
Returns:
| Type | Description |
|---|---|
ToolResult
|
The tool's output, or an error result the model can act on. |