How It Works
How to Create a Simple Tool Function
How to Create Tools with Multiple Parameters
How to Create Tools as Classes
How to Create Async Tools
How to Use Optional, Literal, and Enum Parameters
See the Tool Parameter Types page for complete reference on using Optional, Union, Literal, Enum, List, and Dict types.Tool Function Requirements
| Requirement | Description |
|---|---|
| Type hints | All parameters must have type hints. Supports Optional, Union, Literal, Enum, List[T] and Dict[K, V] with proper JSON Schema translation |
| Docstring | Must include description and Args section |
| Return type | Must specify return type |
| Serializable | Return value must be JSON-serializable |
Best Practices
Describe arguments in the docstring
Describe arguments in the docstring
The Args section becomes the parameter schema the model reads. Spell out each argument so calls are accurate.
Use Literal and Enum to constrain choices
Use Literal and Enum to constrain choices
Typing a parameter as
Literal["draft", "active"] or an Enum stops the model from passing invalid values.Return JSON-serializable values
Return JSON-serializable values
Return
str, dict, or list rather than custom objects so the result flows back through the model cleanly.Reach for astart with async tools
Reach for astart with async tools
Async tools need
await agent.astart(...). Keep sync and async tools separated by how the agent is run.Related
Different Ways to Create
Other ways to build tools
Debug Tools
Troubleshoot tool calls

