Handoffs and Multi-Agent Triage

Ma Mahalakshmi V Updated 16 Sep 2026
7 min read ·Lesson 50 of 224

The Problem With One Agent Doing Everything

An agent with instructions covering billing questions, technical troubleshooting, and account changes all at once tends to produce worse results at each individual task than three separate agents, each with narrow, focused instructions covering exactly one area — the same reasoning behind why Unit 8, Lesson 4 grouped related custom functions together (ORDER_TOOLS, POLICY_TOOLS) rather than dumping every available function into one undifferentiated list. A handoff is the Agents SDK's mechanism for a triage agent to recognize which specialized area a request actually belongs to and transfer the conversation to the agent built specifically for that area, rather than trying to be good at everything within a single set of instructions.

Defining Specialist Agents

from agents import Agent, Runner

billing_agent = Agent(
    name="Billing Agent",
    instructions="You help customers with billing questions, charges, and refunds.",
    model="gpt-5.6-terra",
)

technical_agent = Agent(
    name="Technical Agent",
    instructions="You help customers troubleshoot technical issues with the product.",
    model="gpt-5.6-terra",
)

Each specialist agent here is defined exactly as Lesson 2 introduced — a name, a set of instructions, a model — with instructions scoped narrowly to one specific area rather than covering everything the overall system needs to handle.

Defining a Triage Agent With Handoffs

A triage agent is given a list of handoffs — the other agents it's allowed to transfer a conversation to — alongside its own instructions describing how to decide between them.

triage_agent = Agent(
    name="Triage Agent",
    instructions=(
        "Determine whether the customer's question is about billing or a "
        "technical issue, and hand off to the appropriate specialist agent. "
        "Do not attempt to answer billing or technical questions yourself."
    ),
    model="gpt-5.6-terra",
    handoffs=[billing_agent, technical_agent],
)

result = Runner.run_sync(triage_agent, "I was charged twice for my last order.")
print(result.final_output)
print(f"Handled by: {result.last_agent.name}")

Note: The exact parameter name (handoffs here) and the mechanics of how a handoff is triggered and executed can vary by SDK version. Confirm the current interface against the current official documentation.

The triage agent's own instructions explicitly tell it not to answer the underlying question itself, only to route it — this is deliberate: a triage agent that both tries to route and tries to answer tends to do a worse job of each than one that's scoped purely to classification and handoff, mirroring Lesson 3's guidance that narrow, focused instructions generally outperform broad, do-everything ones. result.last_agent.name reports which specialist actually produced the final answer, confirming the handoff to billing_agent occurred as expected.

How a Handoff Actually Works

When the triage agent decides a handoff is appropriate, control of the conversation transfers to the target agent, which then continues the interaction — including using its own tools and its own instructions — as though it had been the one handling the request from that point forward. This is conceptually similar to Unit 8, Lesson 4's dispatch pattern (dispatch_function_call() routing a function call to the right handler), except a handoff transfers the entire ongoing conversation to a different agent with its own distinct instructions and tools, rather than routing a single function call to a specific handler function within one agent's scope.

from agents import function_tool

@function_tool
def issue_refund(order_id: str, amount: float) -> str:
    """Issue a refund for a specific order.

    Args:
        order_id: The order identifier to refund.
        amount: The refund amount in US dollars.
    """
    return f"Refunded ${amount:.2f} for order {order_id}."

billing_agent_with_tools = Agent(
    name="Billing Agent",
    instructions="You help customers with billing questions, charges, and refunds.",
    model="gpt-5.6-terra",
    tools=[issue_refund],
)

triage_agent = Agent(
    name="Triage Agent",
    instructions="Route billing questions to the Billing Agent, technical questions to the Technical Agent.",
    model="gpt-5.6-terra",
    handoffs=[billing_agent_with_tools, technical_agent],
)

Once a handoff to billing_agent_with_tools occurs, that agent's own tools=[issue_refund] become available for the rest of the interaction, even though the triage agent that initially received the message had no access to issue_refund at all — each agent in a handoff chain brings its own distinct capabilities, rather than sharing one combined pool of tools across every agent in the system.

Why Scoping Tools to Specific Agents Matters

Giving the triage agent access to every tool every specialist might need would defeat much of the purpose of triage in the first place — it would need instructions broad enough to know when to use each one, reintroducing the "one agent doing everything" problem this lesson opened with. Scoping tools narrowly to the specific agent that needs them follows the same least-privilege reasoning Unit 8, Lesson 5 established for custom function access generally: the billing agent can issue a refund; the triage agent, whose entire job is classification and routing, has no ability to do so at all, which is also a meaningful safety property — a routing mistake in triage can misdirect a conversation, but it can't accidentally trigger a consequential action a narrowly-scoped triage agent was never given the tools to perform.

Handoffs Can Chain

A handoff isn't limited to a single triage-to-specialist transfer; a specialist agent can itself have handoffs to further, more specific agents, when a domain benefits from more than one level of routing.

refund_specialist = Agent(
    name="Refund Specialist",
    instructions="You handle refund requests specifically, applying the full refund policy.",
    model="gpt-5.6-terra",
    tools=[issue_refund],
)

billing_agent = Agent(
    name="Billing Agent",
    instructions=(
        "You handle general billing questions. Hand off refund requests "
        "specifically to the Refund Specialist."
    ),
    model="gpt-5.6-terra",
    handoffs=[refund_specialist],
)

triage_agent = Agent(
    name="Triage Agent",
    instructions="Route billing questions to the Billing Agent, technical questions to the Technical Agent.",
    model="gpt-5.6-terra",
    handoffs=[billing_agent, technical_agent],
)

This produces a two-level routing structure: triage decides billing-versus-technical, and the billing agent itself decides whether a specific request needs the more specialized refund agent. Chaining handoffs like this is worth the added structure specifically when a domain has meaningfully distinct sub-areas with different instructions or tools — introducing a chain purely for its own sake, when a single specialist agent would have handled the whole domain perfectly well, adds complexity without a corresponding benefit.

Improving Routing Accuracy With Examples

A triage agent's routing decision is only as reliable as its instructions are clear about how to distinguish between the specialists it can hand off to. For a genuinely ambiguous case — a question that could plausibly be either billing or technical — a few concrete examples in the instructions, following Unit 3, Lesson 3's few-shot guidance, typically improves routing accuracy more than a purely abstract description of each category.

triage_agent = Agent(
    name="Triage Agent",
    instructions=(
        "Route the customer's message to the correct specialist agent.\n\n"
        "Examples:\n"
        "- 'I was charged twice' -> Billing Agent\n"
        "- 'The app crashes on startup' -> Technical Agent\n"
        "- 'My subscription renewed but I want a refund' -> Billing Agent\n"
        "- 'I can't log in after the last update' -> Technical Agent\n\n"
        "Do not attempt to answer the question yourself."
    ),
    model="gpt-5.6-terra",
    handoffs=[billing_agent, technical_agent],
)

This applies Unit 3's few-shot principle to a routing decision specifically: rather than trusting the triage agent to correctly infer the boundary between "billing" and "technical" from category names alone, a handful of concrete examples spanning the genuinely ambiguous cases — a refund request that's really about a subscription renewal, a login failure that's really an application bug — gives it something more concrete to generalize from than the category labels by themselves.

Common Mistakes

Giving a triage agent instructions to both route and answer questions itself, producing worse routing decisions than a triage agent scoped purely to classification and handoff.

Giving every agent in a handoff chain access to every tool any agent might need, rather than scoping tools narrowly to the specific agent responsible for using them, which undermines both clarity and the least-privilege safety property handoffs can otherwise provide.

Introducing multiple levels of handoff chaining for a domain that doesn't actually have meaningfully distinct sub-areas, adding structural complexity without a real routing benefit.

Failing to check result.last_agent after a run involving handoffs, losing track of which specialist actually produced the final answer.

Best Practices

Keep a triage agent's instructions narrowly scoped to classification and routing, explicitly telling it not to attempt to answer questions outside its routing role.

Scope each specialist agent's tools to only what that specific agent needs, following the same least-privilege reasoning Unit 8, Lesson 5 applied to custom function access.

Introduce handoff chaining only when a domain genuinely has distinct sub-areas that benefit from separate instructions or tools, rather than adding routing levels without a clear corresponding need.

Check result.last_agent when debugging or logging a multi-agent interaction, to confirm which specialist ultimately handled a given request.

0 Comments

Reviewed before they appear

No comments yet.

OpenAI SDK
Introduction to the OpenAI SDK Setting Up Python Creating an API Key Your First Call — client.responses.create() and response.output_text Understanding Billing, Credits, and What a Request Costs Why Responses Replaced Chat Completions Anatomy of a Request: model, input, and instructions Anatomy of a Response: The Typed output Array, Not Just Text Roles: User, Assistant, and Developer/System Choosing a Model, and Reading the Models Page Instead of Memorizing Names Instructions vs. Input Writing Prompts That Get Consistent Results Few-Shot Examples Reasoning Models and the reasoning Parameter Debugging a Prompt That Misbehaves Why Streaming Matters for User Experience stream=True and Iterating Over Events Handling the Event Types You Actually Care About Background Mode for Long-Running Jobs Project — Add Live Streaming to Your Chatbot The Problem With Parsing Free Text JSON Schema and Strict Mode Pydantic Models With the SDK's Parse Helpers Handling Refusals and Validation Failures Project — A Resume-to-JSON Extractor Working With input_image input_file, PDFs, and the Files API Image Generation Speech-to-Text and Text-to-Speech Project: A PDF Question-Answering Script What Function Calling Is Defining a Tool Schema The Full Loop Multiple Tools Errors, Timeouts, and Untrusted Arguments Project: A Weather Assistant Web Search File Search and Vector Stores Code Interpreter Remote MCP Servers and Connectors Project: A Research Assistant What an Embedding Is, Without the Maths Generating and Storing Embeddings Similarity Search From Scratch Hosted Vector Stores vs. Rolling Your Own A Small RAG App Over a Folder of Notes Agents vs. a Single API Call — When You Need One pip install openai Giving Agents Tools Handoffs and Multi-Agent Triage Guardrails and Approvals Tracing and Observing What Your Agent Did A Multi-Agent Support Desk Error Codes and What Each One Means Retries, Timeouts, and Backoff Rate Limits and Spend Limits Prompt Caching and Cost Optimisation The Batch API for Bulk Work Async Clients and Concurrency Moderation and Safety Best Practices Designing the App Backend With FastAPI Streaming to a Simple Frontend Deploying and a Cost/Safety Checklist Why Web Search Is Useful for Current Information Using the Web Search Tool with the Responses API Configuring Search Behavior for Application Use Cases Understanding Citations and Source Attribution Where to Go Next Building a Research Assistant with Web Search Combining Web Search with Structured Outputs Handling Conflicting or Low-Quality Web Sources Reducing Unsupported Claims with Grounded Generation Testing Freshness-Sensitive AI Answers Production Considerations for Web-Grounded Applications Understanding File Search and Retrieval-Augmented Generation Creating and Organizing Vector Stores Uploading Documents for Retrieval Connecting Vector Stores to Responses API Requests Designing Document Metadata and Filtering Strategies Building a PDF Question-Answering Application Improving Retrieval Quality With Better Document Preparation Handling Missing Evidence and Retrieval Failures Combining File Search With Web Search Building a Production Knowledge-Base Assistant What the Code Interpreter Tool Is Designed For Running Python-Based Analysis Through the OpenAI SDK Uploading Datasets for Analysis Analyzing CSV and Spreadsheet Data Generating Charts and Data Summaries Handling Generated Files and Downloadable Artifacts Building a Data-Analysis Assistant Combining Code Execution with Structured Outputs Validating Generated Calculations and Results Security and Sandbox Considerations for Code Execution Understanding Multimodal Input with the OpenAI SDK Sending Images to a Model Image Analysis from URLs and Uploaded Files Extracting Text and Information from Screenshots Building an Image-Question-Answering Application Combining Image Input with Structured Output Analyzing Multiple Images in One Request Handling Image Quality and Input Limitations Designing Multimodal Prompts for Reliable Results Building a Practical Vision-Powered Python Application Understanding Speech-to-Text and Text-to-Speech Workflows Transcribing Audio with the OpenAI SDK Working with Uploaded Audio Files Handling Timestamps and Transcription Metadata Building a Meeting Transcription Workflow Generating Spoken Responses from Text Handling Long Audio and Processing Failures Combining Audio with Text and Tool Calling Building an End-to-End Python Voice Application What Embeddings Are and When to Use Them Generating Embeddings With the OpenAI API Preparing Text for Embedding Comparing Vectors With Cosine Similarity Building a Simple Semantic Search Engine in Python Storing Embeddings in a Database Metadata Filtering for Semantic Search Chunking Strategies for Better Retrieval Evaluating Semantic Search Quality Building a Document Similarity Application When Batch Processing Makes Sense Designing Large-Volume AI Processing Pipelines Using Asynchronous Python with the OpenAI SDK Running Concurrent Requests Safely Controlling Concurrency and Avoiding Rate Limits Tracking Batch Job Progress Handling Partial Failures in Bulk Workloads Retrying Failed Items Without Duplicating Successful Work Designing Resumable AI Processing Jobs Building a Production Batch-Processing Pipeline Batch Processing Makes Sense Large-Scale AI Processing Pipelines Async Python with OpenAI SDK Safe Concurrent Requests Concurrency & Rate Limits Batch Progress Tracking Partial Failure Handling Safe Retry Handling Resumable AI Jobs Production Batch Pipeline System–User Data Separation Reusable App Instructions Prompt Templates & Variables Extraction & Classification Prompts Summarization & Transformation Prompts Explicit Output Requirements Prompt Version Management Prompt Testing & Evaluation Reusable Python Prompt Library API Key Security Secure API Key Storage Secure Secret Management Prompt Injection Prevention Trusted vs. Untrusted Content Tool Argument Validation Sensitive Data Handling Secure Logging AI Action Authorization Production AI Security Checklist Why AI Applications Need Evaluation Beyond Unit Tests Unit Testing OpenAI SDK Integration Code Mocking API Responses in Python Tests Testing Structured Outputs Against Schemas Testing Tool-Calling Workflows Building a Small Evaluation Dataset Measuring Accuracy, Consistency, and Failure Rates Regression Testing Prompts and Model Changes Human Evaluation Versus Automated Evaluation Creating a Repeatable Evaluation Pipeline AI Request Monitoring Token Cost Management Usage Metrics Design Reducing Model Calls Prompt & Context Optimization Model Selection & Optimization AI Caching Strategies Interactive Latency Optimization Usage Dashboards & Budget Alerts Performance & Cost Checklist Every API Call Starts Fresh Fixing API Statelessness Server-Side Conversation Memory Limits of Response Chaining What We're Building Conversation Memory Challenges Preparing an OpenAI SDK Application for Deployment Environment-Specific Configuration for Development and Production Deploying a Python AI Service with Docker Container Health Checks and Startup Configuration Managing Secrets in Cloud Deployments Background Workers for Long-Running AI Tasks Queues and Asynchronous Job Architectures Scaling AI Workloads Horizontally Monitoring Production Incidents and Failures Production Deployment Checklist for OpenAI SDK Applications Reusable OpenAI Service Classes AI Client Dependency Injection Typed AI Responses Python Configuration Management AI Request Decorators Centralized AI Error Handling Clean SDK Abstractions Reusable OpenAI Utilities Internal AI Python Libraries SDK Integration Maintenance Production AI Chatbot Document Q&A System Web Research Assistant Customer Support Agent AI Data Analysis Assistant Image Analysis App Meeting Transcription & Summary Semantic Document Search Multi-Tool AI Agent Production OpenAI SDK App Why "It Looked Fine When I Tested It" Isn't Enough Timing Note Status Note Pre-Decision Status Note Current Availability Note
Ask about this post
AI Ask about this post

Ask questions about Handoffs and Multi-Agent Triage and get answers drawn from it.

Signed-in readers only.