How It Works
How to Create Tools as Functions
How to Create Tools as Lambda Functions
How to Create Tools from External Libraries
How to Create Tools in tools.py File
How to Create Tools in a Package
How to Create Tools with Decorators
How to Add Tools via CLI
How to Create Tools with Choice Parameters
See the Tool Parameter Types page for complete guide on using Optional, Union, Literal, Enum, List, and Dict types.Tool Creation Methods Comparison
| Method | Best For | Complexity |
|---|---|---|
| Function | Simple tools | Low |
| Lambda | One-liners | Low |
| Class | Stateful tools | Medium |
| Package | Reusable tools | Medium |
| Decorator | Enhanced tools | Low |
| External wrap | Library integration | Medium |
| CLI add | Quick setup | Low |
Best Practices
Start with a plain function and @tool
Start with a plain function and @tool
The function-plus-decorator path has the lowest complexity and covers most tools — reach for classes only when you need shared state.
Use classes for stateful tools
Use classes for stateful tools
When a tool holds a connection or cache, a class keeps that state tidy; pass the bound methods to the agent’s
tools list.Wrap external libraries thinly
Wrap external libraries thinly
Adapt a library call into a typed, docstringed function so the model gets a clean schema without the library’s full surface.
Related
Create Custom Tools
Detailed walkthrough per tool style
Remote Tools from GitHub
Load tools from remote sources

