0

Advanced Handoffs

awesome-llm-apps8_2_advanced_handoffs

Demonstrates advanced handoff configuration including callbacks, structured inputs, and custom tool naming.

Sign in to save downloads to your library and vote.

Preview

Advanced Handoffs

Demonstrates advanced handoff configuration including callbacks, structured inputs, and custom tool naming.

๐ŸŽฏ What This Demonstrates

  • Custom Handoff Configuration: Using the handoff() function
  • Callback Functions: Executing code when handoffs are triggered
  • Structured Input Data: Passing specific data with handoffs
  • Tool Customization: Custom tool names and descriptions

๐Ÿš€ Quick Start

  1. Install OpenAI Agents SDK:

    pip install openai-agents
    
  2. Set up environment:

    cp ../env.example .env
    # Edit .env and add your OpenAI API key
    
  3. Run the agent:

    import asyncio
    from agent import main
    
    # Test advanced handoffs
    asyncio.run(main())
    

๐Ÿ’ก Key Concepts

  • handoff() Function: Custom handoff configuration
  • Callback Execution: on_handoff functions for tracking
  • Structured Input: Pydantic models for handoff data
  • Tool Overrides: Custom tool names and descriptions

๐Ÿงช Advanced Features

Escalation with Structured Data

class EscalationData(BaseModel):
    reason: str
    priority: str
    customer_id: str

escalation_handoff = handoff(
    agent=escalation_agent,
    tool_name_override="escalate_to_manager",
    input_type=EscalationData
)

Callback Functions

async def on_escalation_handoff(ctx, input_data):
    print(f"๐Ÿšจ ESCALATION: {input_data.reason}")
    # Log to monitoring system
    # Send notifications
    # Update tickets

Custom Tool Configuration

  • tool_name_override: Custom tool names
  • tool_description_override: Custom tool descriptions
  • input_filter: Control what context transfers
  • is_enabled: Dynamic handoff enabling/disabling

๐Ÿ’ป Advanced Patterns

Escalation Handoff

  • Angry customer scenarios
  • High-value refund requests
  • Complex technical issues

Callback Integration

  • Logging and monitoring
  • Notification systems
  • Metric tracking

Input Filtering

  • Context cleaning
  • Sensitive data removal
  • Conversation sanitization

๐Ÿ”— Next Steps

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/8_2_advanced_handoffs/README.md
Last refreshed
10/24/2026, 3:00:14 AM (5h ago)
Refresh schedule
Daily ยท 03:00 UTC
Dedupe status
Unique ยท deduped by (source, url)