Tools
Tools are async functions that the LLM can call. They’re the bridge between model reasoning and real-world actions.Basic @tool
Key Rules
- Must be async —
@toolenforcesasync def. No sync functions. - Docstring is the spec — The model sees your docstring as the tool description.
- Best Practices matter — The
Best Practicessection is injected into the system prompt as<tool_best_practices>. Use it to guide the model on when/how to use the tool. - Type annotations define the schema — Parameter types become the tool’s JSON schema.
Docstring Structure
Composing Toolsets
Pass multiple tools to an agent:Built-in Toolsets
FileToolset
Workspace-scoped file operations with stale-write protection:read_file, read_image, grep, sed, echo_into.
PyRepl
Persistent Python REPL with runtime primitives:execute_code, reset_repl.
Multimodal Returns
Tools can return images and mixed content:Tuple Returns (mixed content)
Return both text and images:Long Output Handling
For tools that produce very long output:too_long_to_file=True, if the result exceeds ~20,000 tokens, the framework:
- Writes the full output to a temporary file
- Sends a truncated version + file path to the model
- The model can then read specific sections if needed
Dynamic Tool Creation
Create tools programmatically:System Prompt Injection
Each tool’sBest Practices section is collected and injected as a <tool_best_practices> block at the top of the system prompt. This is automatic — you don’t need to reference tools in your docstring.
Additionally, tools can provide dynamic prompt injection via prompt_injection_builder: