Build an agent that uses custom tools to take actions.
Create an agent with multiple tools. The agent decides which tools to call based on the user’s message.
1
Create the agent
agent_tools.py
from definable.agent import Agentfrom definable.tool.decorator import tool@tooldef search_web(query: str) -> str: """Search the web for information.""" return f"Top result for '{query}': Example search result."@tooldef get_weather(city: str) -> str: """Get the current weather for a city.""" return f"The weather in {city} is sunny, 72F."@tooldef calculate(expression: str) -> str: """Evaluate a math expression.""" return str(eval(expression))agent = Agent( model="gpt-4o", tools=[search_web, get_weather, calculate], instructions="You are a helpful assistant. Use tools when needed.",)output = agent.run("What's 42 * 17, and what's the weather in Paris?")print(output.content)
2
Install dependencies
pip install definable
3
Export your API key
export OPENAI_API_KEY=sk-***
4
Run
python agent_tools.py
The agent will call calculate and get_weather in parallel, then combine the results into a single response.