Agent Tools
Tools extend agent capabilities by allowing them to call external functions, APIs, and services. Swarms supports OpenAI-style function calling with automatic schema generation.Basic Tool Usage
Define a Simple Tool
Tools are Python functions with type hints and docstrings:Tool Requirements
Type Hints and Docstrings
For reliable tool execution, functions must have:- Type hints for all parameters and return value
- Docstring describing the function’s purpose
- Parameter descriptions in the docstring
Multiple Tools
Add Multiple Tools to an Agent
Real-World Tool Examples
Web Search Tool
Database Query Tool
File Operations Tool
Tool Configuration
Tool Schema Control
List of tool functions to make available to the agent.
Control when tools are used. Options: “auto”, “required”, “none”.
Display tool execution results.
Number of retry attempts for failed tool executions.
Advanced Tool Patterns
Tool with State
Async Tools
BaseTool API
Swarms uses theBaseTool class internally to manage tools:
MCP Tools
Model Context Protocol (MCP) enables connecting to external tool servers:Best Practices
1. Always Include Type Hints
2. Write Descriptive Docstrings
3. Handle Errors Gracefully
4. Use Specific Parameter Names
5. Return Structured Data When Possible
Next Steps
Agent Skills
Learn about the Agent Skills system
Structured Outputs
Get structured responses from agents
Reference
- Tool handling:
swarms/structs/agent.py:972-1059 - BaseTool class:
swarms/tools/base_tool.py:69 - Function schema generation:
swarms/tools/py_func_to_openai_func_str.py