Skip to main content
Multi-agent systems enable sophisticated workflows where specialized agents collaborate, transfer conversations, and handle different aspects of complex tasks.

Overview

The Multi-Agent primitive allows you to orchestrate multiple specialized agents within a single workflow or conversation. Instead of one generalist agent handling everything, you can deploy domain experts that collaborate, transfer work between each other, and provide specialized capabilities for different parts of your application. Multi-agent systems are essential for:
  • Specialized Expertise: Different agents with deep knowledge in specific domains
  • Conversation Routing: Intelligent transfer between support, sales, technical agents
  • Complex Workflows: Breaking down large tasks across multiple specialized agents
  • Parallel Processing: Multiple agents working simultaneously on different subtasks
  • Scalable Architecture: Add new agent specialists without modifying existing ones

Seamless Handoffs

Agents can transfer conversations to other specialists while maintaining full context

Domain Experts

Each agent can have specialized knowledge, tools, and behavioral patterns

Automatic Routing

Main agent intelligently determines which specialist should handle each request

Shared Context

All agents in a session share conversation history and can build on each other’s work

How Multi-Agent Works

When you configure multiple agents:
  1. Main Agent: Acts as coordinator, receives initial requests
  2. Agent Discovery: Main agent knows about available specialists and their capabilities
  3. Intelligent Routing: Determines which specialist is best suited for the current task
  4. Transfer: Hands off conversation to specialist while preserving full context
  5. Specialist Handling: Specialist agent takes over and handles the request
  6. Return or Continue: Specialist can return control to main agent or continue handling
Context Preservation: When agents transfer conversations, the entire message history and context is preserved. The specialist agent has full visibility into everything that was discussed before.

Code Examples

Basic Multi-Agent Setup

Sales and Support Routing

Multi-Agent with Custom Tools

Continuing Multi-Agent Conversations

Use Cases

1. Customer Service Hub

Multi-tier support with specialized agents:

2. Sales Pipeline

Route through sales stages with specialized agents:

3. Content Production Workflow

Coordinate content creation across specialists:

4. Development Team Simulation

Specialized development agents:

5. Healthcare Triage System

Medical domain specialists:

6. Financial Advisory Service

Financial domain specialists:

Best Practices

Agent Design

Routing Strategy

Main Agent Guidance: Give your main/coordinator agent clear instructions on when to route to each specialist and how to handle edge cases.

Performance Optimization

Limit Agent Count

Use 3-5 specialized agents per workflow for optimal performance

Smart Routing

Design clear routing criteria to minimize unnecessary transfers

Session Reuse

Keep multi-agent sessions alive for related conversations

Tool Scoping

Give each agent access only to tools they need

Error Handling

Integration with Other Primitives

With Prompts

Each agent can have specialized system prompts:
Learn more: Prompts Primitive

With Custom Tools

Different agents can access different tools:
Learn more: Custom Tools Primitive

With Sessions

All agents in a session share context:
Learn more: Sessions Primitive

With Parallelization

Run multiple agents in parallel:
Learn more: Parallelization Primitive

Performance Considerations

Agent Count Impact

  • 2-3 Agents: Optimal performance, clear routing
  • 4-6 Agents: Good performance, more specialization
  • 7+ Agents: Consider if all are necessary, may slow routing decisions

Routing Efficiency

Clear routing reduces transfer overhead:

Tool Access Optimization

Only provide tools relevant to each agent:

Troubleshooting

Problem: Main agent not routing to specialistsSolutions:
  • Make agent descriptions more specific
  • Add explicit routing guidance in system prompt
  • Ensure agent names clearly indicate their purpose
Problem: Requests routed to incorrect specialistSolutions:
  • Improve agent descriptions to be more distinct
  • Add routing examples in system prompt
  • Use clear, non-overlapping specializations
Problem: Specialist doesn’t seem to have previous contextSolution: This shouldn’t happen - verify you’re using same session
Problem: Request bounces between multiple agentsSolutions:
  • Design clear, non-overlapping specializations
  • Give guidance on edge cases
  • Use a generalist fallback agent

Prompts

Specialized system prompts for each agent

Sessions

Shared context across all agents

Custom Tools

Domain-specific tools for specialists

Parallelization

Run multiple agents concurrently

Additional Resources

API Reference

Agents parameter documentation

Use Cases

Multi-agent implementation examples
Remember: Design agents as specialists with clear, non-overlapping domains. Let the main agent handle routing, and give each specialist deep expertise in their area.