Quick Overview
Type Inference
Extract parameter types and descriptions from function signatures automatically.
Docstring Parsing
Use docstrings to enrich tool descriptions and parameter guidance.
JSON Schema Generation
Generate schemas compatible with modern function-calling APIs.
Multiple Return Types
Support plain text, structured values, and multimodal results.
Two Creation Modes
Use either the decorator style or the class-based style.
Long Output Truncation
Persist oversized results to disk and return only a safe preview.
Supported Parameter Types
Supported parameter types
Supported parameter types
- Primitive types:
str,int,float,bool - Container types:
List[T],Dict[K, V] - Multimodal types:
Text,ImgPath,ImgUrl - Multimodal lists:
List[Text],List[ImgPath],List[ImgUrl] - Pydantic models
- Optional parameters with defaults
- Nested container structures
Important restriction
Important restriction
Tool arguments must ultimately be representable as JSON-compatible values. Containers such as
Tuple and Set are therefore not good tool parameter types.Supported Return Types
Tool functions can return several output formats, and the framework will convert them into a model-friendly representation.Basic return types
Basic return types
str- JSON-serializable values such as
dict,list,int,float,bool,None - Pydantic models
Multimodal return types
Multimodal return types
ImgUrlImgPathTuple[str, ImgUrl]Tuple[str, ImgPath]
Return Type Examples
How Return Values Are Processed
Framework behavior
Framework behavior
- Primitive values are serialized directly
ImgUrlis used as a web image referenceImgPathis converted into a base64 data URL- Text + image pairs become multimodal message content
- Unsupported values fall back to strings
Multimodal special case
Multimodal special case
When a tool returns images or text-plus-image content, the framework uses a multimodal
assistant + user message pair instead of a plain tool message, because OpenAI-style tool messages cannot directly carry multimodal payloads.Return type notes
Return type notes
- Local image paths must exist and be readable
- Remote image URLs should be publicly accessible
- Combination types must be
(str, ImgPath)or(str, ImgUrl) - Avoid returning very large data structures
Long Output Truncation
When a tool may return a very large string, such as a code execution result or a long search response, you can enabletoo_long_to_file.
Persist oversized output
If the output exceeds 20,000 tokens, the full result is written to a temporary file.
The function wrapped by
@tool must itself be defined as async def.too_long_to_file only when a tool may return a lot of plain text, and only when the Agent also has a way to read files, such as FileToolset or PyRepl.
Built-in Tools
FileToolset
FileToolset provides safe file reading, searching, and editing with hash validation to avoid stale writes. By default, it only allows access to non-hidden files inside the workspace.
Available tools
Available tools
read_file: Read file content with optional line ranges and line numbersgrep: Run regex search in the workspace and require apath_patternsed: Replace content in a line range after reading the file firstecho_into: Overwrite the entire file after reading it first
Notes
Notes
- Always call
read_filebefore modifying a file grepmust be constrained withpath_pattern- Hidden files and hidden directories are blocked by default
Usage
Decorator style
Class-based style
Tool Flow
Extract schema and metadata
The framework reads the signature and docstring and generates a tool schema.
Model chooses the tool
The LLM decides whether to call the tool based on the generated tool description.
Best Practices
- Keep tool names short, clear, and action-oriented
- Add explicit type annotations and useful docstrings
- Return structured values when possible
- Avoid huge payloads unless you intentionally enable truncation
- Keep tools focused on one clear responsibility