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.
Hypertic provides ready-to-use tools for common tasks:
More built-in tools are coming soon.
Hypertic supports two ways to create tools:
Create tools using the @tool decorator on functions:
from hypertic.agents import Agent
from hypertic.tools import tool
@tool
def get_weather(city: str) -> str:
"""Get weather for a given city."""
return f"Sunny, 72°F in {city}"
@tool
def calculate(expression: str) -> str:
"""Calculate a mathematical expression."""
return str(eval(expression))
# Create agent with tools
agent = Agent(
model=model,
tools=[get_weather, calculate],
)
response = agent.run("What's the weather in SF and calculate 15 * 3?")
print(response.content)
Create toolkits by inheriting from BaseToolkit. This lets you group related tools together and add configuration:
import os
from dotenv import load_dotenv
from hypertic.agents import Agent
from hypertic.tools import BaseToolkit, tool
from hypertic.models import OpenAIChat
from tavily import TavilyClient
load_dotenv()
class TavilyTools(BaseToolkit):
api_key: str = None
max_results: int = 5
@tool
def search(self, query: str) -> str:
"""Search the web using Tavily API.
Args:
query: The query to search for.
Returns:
JSON string containing search results with citations.
"""
client = TavilyClient(api_key=os.getenv("TAVILY_API_KEY"))
response = client.search(query=query, max_results=self.max_results)
return str(response)
# Use the toolkit with your agent
tavily = TavilyTools(max_results=3)
tools = [tavily]
print(f"Tools: {tools}")
agent = Agent(
model=OpenAIChat(model="gpt-5.2"),
tools=tools,
)
response = agent.run("Search for latest AI news")
print(response.content)
Tool descriptions are crucial for the agent to understand when to use them. Write clear, descriptive docstrings:
@tool
def 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...
Best Practices:
- Write clear, concise docstrings
- Describe parameters and return values
- Include examples when helpful
- Be specific about what the tool does