0

๐Ÿค Tutorial 8: Handoffs & Delegation

awesome-llm-apps8_handoffs_delegation

Master agent-to-agent task delegation! This tutorial teaches you how to use the OpenAI Agents SDK's handoff system to create specialized agents that can intelligently delegate tasks to each other, building powerful multi-agent workflows.

Sign in to save downloads to your library and vote.

Preview

๐Ÿค Tutorial 8: Handoffs & Delegation

Master agent-to-agent task delegation! This tutorial teaches you how to use the OpenAI Agents SDK's handoff system to create specialized agents that can intelligently delegate tasks to each other, building powerful multi-agent workflows.

๐ŸŽฏ What You'll Learn

  • Agent Handoffs: Delegating tasks between specialized agents
  • Handoff Configuration: Custom tool names, descriptions, and callbacks
  • Input Filtering: Controlling what context gets passed between agents
  • Triage Patterns: Building intelligent routing and delegation systems

๐Ÿง  Core Concept: What Are Handoffs?

Handoffs enable agent specialization and delegation where agents can transfer tasks to other agents with specific expertise. Think of handoffs as a smart routing system that:

  • Creates specialized agents for different domains (support, billing, technical)
  • Allows intelligent task delegation based on user needs
  • Maintains conversation context across agent transfers
  • Provides custom routing logic and input filtering
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    HANDOFF WORKFLOW                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                             โ”‚
โ”‚  USER REQUEST                                               โ”‚
โ”‚       โ”‚                                                     โ”‚
โ”‚       โ–ผ                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    1. ANALYZE REQUEST                      โ”‚
โ”‚  โ”‚   TRIAGE    โ”‚                                            โ”‚
โ”‚  โ”‚   AGENT     โ”‚    2. DECIDE DELEGATION                    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                            โ”‚
โ”‚       โ”‚                                                     โ”‚
โ”‚       โ–ผ                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    3. CALL HANDOFF TOOL                    โ”‚
โ”‚  โ”‚   HANDOFF   โ”‚    "transfer_to_billing_agent"             โ”‚
โ”‚  โ”‚    TOOL     โ”‚                                            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                            โ”‚
โ”‚       โ”‚                                                     โ”‚
โ”‚       โ–ผ                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    4. TRANSFER CONTEXT                     โ”‚
โ”‚  โ”‚  BILLING    โ”‚    (with optional filtering)               โ”‚
โ”‚  โ”‚   AGENT     โ”‚                                            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    5. PROCESS REQUEST                      โ”‚
โ”‚       โ”‚                                                     โ”‚
โ”‚       โ–ผ                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    6. RETURN RESPONSE                      โ”‚
โ”‚  โ”‚  RESPONSE   โ”‚                                            โ”‚
โ”‚  โ”‚   TO USER   โ”‚                                            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Tutorial Overview

This tutorial demonstrates key handoff patterns:

1. Basic Handoffs (basic_handoffs.py)

  • Simple agent-to-agent delegation
  • Customer support triage example
  • Automatic tool creation from handoff definitions

2. Advanced Handoffs (advanced_handoffs.py)

  • Custom handoff configuration with callbacks
  • Input filtering and context management
  • Handoff with structured input data

๐Ÿ“ Project Structure

8_handoffs_delegation/
โ”œโ”€โ”€ README.md                # This file - concept explanation
โ”œโ”€โ”€ requirements.txt         # Dependencies
โ”œโ”€โ”€ basic_handoffs.py        # Simple agent handoffs (40 lines)
โ”œโ”€โ”€ advanced_handoffs.py     # Advanced handoff patterns (50 lines)
โ”œโ”€โ”€ app.py                  # Streamlit handoff demo (optional)
โ””โ”€โ”€ env.example             # Environment variables template

๐ŸŽฏ Learning Objectives

By the end of this tutorial, you'll understand:

  • โœ… How to create agent handoffs for task delegation
  • โœ… Configuring handoff tools with custom names and descriptions
  • โœ… Using input filters to control context transfer
  • โœ… Building intelligent triage systems with multiple agents
  • โœ… When and how to use handoffs vs direct agent orchestration

๐Ÿš€ Getting Started

  1. Install OpenAI Agents SDK:

    pip install openai-agents
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Set up environment variables:

    cp env.example .env
    # Edit .env and add your OpenAI API key
    
  4. Test basic handoffs:

    python basic_handoffs.py
    
  5. Try advanced patterns:

    python advanced_handoffs.py
    

๐Ÿ”ง Key Handoff Patterns

1. Basic Handoff Setup

from agents import Agent, handoff

billing_agent = Agent(name="Billing Agent")
support_agent = Agent(name="Support Agent")

triage_agent = Agent(
    name="Triage Agent",
    handoffs=[billing_agent, support_agent]  # Creates tools automatically
)

2. Custom Handoff Configuration

from agents import Agent, handoff

def on_handoff_callback(ctx):
    print(f"Handoff to {ctx.agent.name} initiated")

custom_handoff = handoff(
    agent=billing_agent,
    tool_name_override="escalate_to_billing",
    tool_description_override="Transfer complex billing issues",
    on_handoff=on_handoff_callback
)

3. Input Filtering

from agents.extensions import handoff_filters

filtered_handoff = handoff(
    agent=support_agent,
    input_filter=handoff_filters.remove_all_tools  # Clean context
)

๐Ÿ’ก Handoff Design Best Practices

  1. Clear Specialization: Each agent should have a distinct area of expertise
  2. Intelligent Routing: Use descriptive tool names and instructions for LLM
  3. Context Management: Consider what context should transfer between agents
  4. Callback Integration: Use callbacks for logging, metrics, and workflows
  5. Input Validation: Structure inputs when passing specific data

๐Ÿ”— Next Steps

After completing this tutorial, you'll be ready for:

๐Ÿ’ก Pro Tips

  • Start Simple: Begin with basic handoffs, add complexity gradually
  • Clear Instructions: Make agent roles and handoff triggers obvious
  • Test Routing: Verify LLM chooses correct agents for different scenarios
  • Monitor Handoffs: Use callbacks and tracing to track delegation patterns
  • Context Strategy: Plan what information should transfer between agents

Ingestion metadata

Source catalog
awesome-llm-apps
Repository
Shubhamsaboo/awesome-llm-apps ยท main
File path
ai_agent_framework_crash_course/openai_sdk_crash_course/8_handoffs_delegation/README.md
Last refreshed
7/24/2026, 3:00:13 AM (53m ago)
Refresh schedule
Daily ยท 03:00 UTC
Dedupe status
Unique ยท deduped by (source, url)