Skip to main content
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

Basic Tool Integration

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:

Multiple Tools Example

Agents can use multiple tools in a single workflow:

Tool Types

1. Python Functions

Simple Python functions with type hints and docstrings:

2. Custom Tool with Configuration

For tools that need configuration such as an API key, read it inside a plain function and pass the function directly:

3. External Tool Libraries

Integrate tools from external libraries:

Advanced Tool Patterns

Tool with Error Handling

Stateful Tool

Best Practices

1. Clear Tool Documentation

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:

Tool Configuration

Dynamic Tool Loading

Tool Registry

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