Learn how to create powerful agents that can use external tools to interact with APIs, search the web, process data, and perform complex operations.
Overview
Tools extend agent capabilities beyond language generation, allowing them to:
- Search the web for real-time information
- Execute code and scripts
- Query databases
- Make API calls
- Process files and data
- Perform calculations
Here’s a simple example of creating a tool and using it with an agent:
Real-World Example: Web Search Agent
Here’s a production-ready example using the Exa search API:
Agents can use multiple tools in a single workflow:
1. Python Functions
Simple Python functions with type hints and docstrings:
For tools that need configuration such as an API key, read it inside a plain function and pass the function directly:
Integrate tools from external libraries:
Best Practices
Always provide detailed docstrings:
2. Type Hints
Use proper type hints for better tool discovery:
3. Error Handling
Handle errors gracefully:
4. Logging
Add logging for debugging:
swarms.tools.tool_registry provides ToolStorage, a named registry of tool callables. Tools are keyed by their function name — add_tool reads func.__name__, so there is no separate label to pass.
The tool_registry decorator registers a function into a ToolStorage at definition time:
ToolStorage.list_tools() returns a JSON string of registry metadata, not a list of callables — build the agent’s tools list with get_tool(name) as shown above.
Output Examples
When an agent uses tools, you’ll see output like:
Next Steps
Learn More