In the latest version, tools can be created using the
Feel free to explore the v0.x section of this page to find the method that suits you best.
@function_tool
decorator with async functions; however, the BaseTool approach is still supported.Feel free to explore the v0.x section of this page to find the method that suits you best.
Step-by-step Guide
1
Add Import Statements
Import the necessary modules for the new function-based approach.
2
Define Args Schema
Create a Pydantic model to define your tool’s input parameters.
3
Create the Tool Function
Define an async function with the
@function_tool
decorator.All parameters of the function tool, except for
ctx
, are treated as input parameters and included in the tool’s schema.For example, in the tool above, the input model CalculatorArgs
is passed as the args
parameter, so the input JSON would look like:args
is an example name, you can name your input parameters however you like, and you may define more than one input parameter if needed.This example mentions tool context, which can be used as a shared storage for all agents and tools.
For more info on agent context, refer to this page
4
Test the Tool
Test your tool function independently.
5
Add Tool to Agent
Pass the function directly to the agent’s tools list.
Full Code Example
Next Steps
- Checkout Best Practices & Tips
- Learn why PyDantic is all you need