Function Tools
Turn any Python function into a tool with one decorator.
Function Tools allow your agent to execute your own Python functions.
Instead of only generating text, your agent can call Python code to perform actions.
Create a Function Tool#
Python
from abzagent import function_tool
@function_tool
def get_weather(city: str):
return f"The weather in {city} is sunny."Register a Tool#
Python
agent = Agent(
name="Weather Assistant",
instructions="Help users with weather information.",
model="gemini-2.5-flash",
tools=[get_weather]
)Examples#
Python
result = agent.run("What's the weather in Karachi?")
print(result.content)How It Works#
- The
@function_tooldecorator inspects your function's signature and turns it into a tool the model can call. - During
run(), the model decides on its own whether calling the tool would help answer the prompt. - If it does, the SDK executes your Python function with the arguments the model chose and feeds the result back to the model.
- The model then uses that result to generate its final response.
What Can You Build?#
- Weather APIs
- Calculators
- Database Queries
- File Management
- Email Automation
- Web Search
- External APIs
- Custom Business Logic
Best Practices#
- Keep each tool focused on one task.
- Give tools descriptive names.
- Return predictable results.
- Keep tool logic reusable.
Next Step#
Continue to Built-in Tools.