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 abagentsdk 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]
)Example#
Python
response = agent.run("What's the weather in Karachi?")
print(response.content)The SDK automatically decides when to call the tool and returns the result before generating the 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.