Skip to main content

Integrating Tools with Agents

AutoGen agents can use tools to interact with external systems, execute code, search databases, and more. Learn how to integrate tools effectively.

Basic Tool Integration

The simplest way to add tools is by passing Python functions to agents:

Async Tools

Tools can be async for I/O operations:

Tool Call Behavior

Control how agents handle tool calls:

Reflect on Tool Use

When reflect_on_tool_use=True, the agent makes another LLM call to generate a natural language response:

Direct Tool Results

When reflect_on_tool_use=False, tool results are returned directly:

Multiple Tool Iterations

Control how many tool call rounds an agent can make:

Function Tool Class

For more control, use the FunctionTool class:

Structured Tool Inputs

Use Pydantic models for complex tool inputs:

Tools in Multi-Agent Teams

Different agents can have different tools:
In v0.4, you don’t need a separate executor agent for tools. The AssistantAgent calls and executes tools automatically.

Code Execution

For code execution, use CodeExecutorAgent:

Docker Code Execution

Execute code in isolated Docker containers:

Custom Tool Results

Return rich tool results:

Error Handling in Tools

Handle errors gracefully:

Tool Call Summary Format

Customize how tool results are formatted:

Parallel Tool Calls

By default, multiple tool calls execute in parallel:

Best Practices

Be cautious with code execution tools. Always use Docker or sandboxed environments for untrusted code.

Advanced: Custom Tool Classes

Implement custom tool classes for complex behavior: