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. BaseTool Class

For more complex tools, use the BaseTool class:

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

Output Examples

When an agent uses tools, you’ll see output like:

Next Steps

Learn More