Tools extend agent capabilities by enabling interactions with external systems, APIs, and functions. They allow agents to perform actions beyond text generation, such as fetching real-time data, executing code, querying databases, and taking actions in external systems.The agent understands tools through their function signatures (type hints) and docstrings, which describe what each tool does and when it should be used.
Create tools using the @tool decorator on functions:
from hypertic.agents import Agentfrom hypertic.tools import tool@tooldef get_weather(city: str) -> str: """Get weather for a given city.""" return f"Sunny, 72°F in {city}"@tooldef calculate(expression: str) -> str: """Calculate a mathematical expression.""" return str(eval(expression))# Create agent with toolsagent = Agent( model=model, tools=[get_weather, calculate],)response = agent.run("What's the weather in SF and calculate 15 * 3?")print(response.content)
Tool descriptions are crucial for the agent to understand when to use them. Write clear, descriptive docstrings:
@tooldef get_weather(city: str, units: str = "celsius") -> str: """Get current weather for a given city. Args: city: The name of the city to get weather for units: Temperature units - 'celsius' or 'fahrenheit' Returns: Current weather conditions as a string """ # Implementation...