How It Works
How to Create a Simple Tool Function
1
Define Tool Function
2
Use with Agent
How to Create Tools with Multiple Parameters
1
Define Multi-Parameter Tool
2
Use with Agent
How to Create Tools as Classes
1
Define Tool Class
2
Use Class Methods as Tools
How to Create Async Tools
1
Define Async Tool
2
Use with Async Agent
How to Use Optional, Literal, and Enum Parameters
1
Create Tool with Choice Parameters
Tool Function Requirements
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

