Skip to main content
Swarms provides a comprehensive tool system that allows agents to execute custom functions, interact with APIs, and perform specialized tasks. The framework supports multiple tool integration patterns with automatic schema generation and validation.

Overview

The Swarms tool system provides:
  • Automatic Schema Generation: Convert Python functions to OpenAI-compatible tool schemas
  • Type Safety: Full type hint support with validation
  • Tool Registry: Centralized management of available tools
  • Pydantic Integration: Use Pydantic models for structured tool inputs
  • Batch Execution: Execute multiple tools concurrently
  • Error Handling: Comprehensive error handling and validation

Quick Start

Basic Tool Usage

Add a simple function as a tool:
Tools must have:
  1. Type hints for all parameters
  2. A docstring describing the function
  3. Return type annotation

BaseTool Class

Core Tool Management

The BaseTool class provides comprehensive tool management:

Multiple Tools

Manage multiple tools with validation:

Pydantic Model Tools

Structured Tool Inputs

Use Pydantic models for complex tool schemas:

Multiple Pydantic Models

Tool Registry

Centralized Tool Management

Use the ToolStorage registry for managing tools:

Batch Tool Registration

Tool Execution

Execute Tools Dynamically

Execute by Name

Advanced Patterns

Tool Validation

Validate tools before execution:

Dynamic Tool Generation

Tool Composition

Combine multiple tools into workflows:

Best Practices

Documentation

Always include comprehensive docstrings with parameter descriptions

Type Hints

Use type hints for all function parameters and return values

Error Handling

Implement robust error handling in your tools

Validation

Validate inputs using Pydantic models for complex schemas

Common Patterns

API Integration Tool

Database Tool

File Processing Tool

Troubleshooting

Common Issues

Missing Type Hints
Missing Documentation

Next Steps

MCP Integration

Connect to MCP servers for more tools

Marketplace

Share and discover prompts on the marketplace