Skip to content

Multiple handoffs requested Error tracing platform #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
malinphy opened this issue May 14, 2025 · 1 comment
Open

Multiple handoffs requested Error tracing platform #694

malinphy opened this issue May 14, 2025 · 1 comment
Labels
question Question about using the SDK stale

Comments

@malinphy
Copy link

malinphy commented May 14, 2025

Please read this first

  • Have you read the docs?Agents SDK docs Yes
  • Have you searched for related issues? Others may have had similar requests

Question

I have such a setup.


f_agent = Agent(name="Flight Assistant agent",
              instructions=f"""
Always answer in given language. Return all the given flight information

departure_id : Parameter defines the departure airport code or location kgmid. An airport code is an uppercase 3-letter code. For example, CDG is Paris Charles de Gaulle Airport and AUS is Austin-Bergstrom International Airport.

arrival_id : Parameter defines the arrival airport code or location kgmid. An airport code is an uppercase 3-letter code. You can search for it on Google Flights or IATA. For example, CDG is Paris Charles de Gaulle Airport and AUS is Austin-Bergstrom International Airport.

outbound_date : Parameter defines the outbound date. The format is YYYY-MM-DD. e.g. 2025-04-09

return_date : Parameter defines the return date. The format is YYYY-MM-DD. e.g. 2025-04-15
Today : {datetime.now().strftime("%Y-%m-%d")}
""",
              model="gpt-4o-mini",
              # model = 'gpt-4o',
              model_settings=ModelSettings(temperature= 0.0,
                                #  max_tokens = 4096*8
                                 ),
            tools= [flight_search_2]
              )
              
h_agent = Agent(
    name = "Hotels Assistant agent",
    instructions= """Returns google hotels information.     
    q : Location
    gl : Country""",
    model = 'gpt-4o-mini',
    tools=[hotels_search2],
    model_settings=ModelSettings(temperature= 0.0,
                                #  max_tokens = 4096*2
                                 ),
)



y_agent = Agent(
    name = "Yelp Search information",
    instructions= """Returns Yelp search results.     
    search_term: str, 
    location: str
    """.strip(),
    model = 'gpt-4o-mini',
    tools=[yelp_search2],
    model_settings=ModelSettings(temperature= 0.0,
                                #  max_tokens = 4096*2
                                 ),
)              


# agents are described above with tools from serp API. 

import os
import sys
import uuid
import datetime
from dotenv import load_dotenv
from pydantic import BaseModel
from typing import List, Optional
from openai import OpenAI
import pandas as pd
import numpy as np


script_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.join(script_dir, "..")
sys.path.append(parent_dir)

from agents import Agent, Runner, trace
from helpers.travel_agents import f_agent, h_agent, y_agent
from helpers.helper_functions import assemble_conversation
from agents.extensions.handoff_prompt import RECOMMENDED_PROMPT_PREFIX 
load_dotenv()

myuuid = str(uuid.uuid4())
print(f"Session UUID: {myuuid}")

main_agent = Agent(
    name="Main Agent",

    model="gpt-4.1", 
    instructions=f"""{RECOMMENDED_PROMPT_PREFIX}
You are a helpful travel planning assistant. Guide the user through planning their trip.
If the user asks about flights or flight search, handoff to the Flight Assistant agent.
If the user asks about accommodation, hotels, or places to stay, handoff to the Hotels Assistant agent.
If the user asks about restaurants, food, or places to eat, handoff to the Yelp Assistant agent.
For general conversation or other requests, respond yourself.
Remember to be friendly and helpful!
""", 
    handoffs=[f_agent, h_agent, y_agent],
    handoff_description=(
        "Handoff to the relevant assistant (Flights, Hotels, Yelp) for specific search or booking queries."
    ),
)

if __name__ == "__main__":
    print("Hello! I'm your travel planning assistant.")
    print("What can I help you plan today?")
    print("Type 'quit' or 'exit' to end the conversation.")

    last_response = None


    while True:
        user_input = input("> ")

        # Check for the quit condition
        if user_input.lower() in ['quit', 'exit']:
            print("Okay, goodbye! Happy travels!")
            break # Exit the loop

        # If the user didn't quit, process the input
        print("\nProcessing your request...")
        current_turn_input = assemble_conversation(last_response, user_input) if last_response else user_input

        try:
            with trace(myuuid):
                res = Runner.run_sync(main_agent, current_turn_input)

            print("\n--- Assistant Response ---")
            print(res.final_output)
            print("------------------------")

            last_response = res

        except Exception as e:
            print(f"\nAn error occurred during agent execution: {e}")
            last_response = None
        print("\nWhat else can I help with? (Type 'quit' or 'exit' to end)")


Although the program runs without any exceptions, the OpenAI platform displays the following error:

Image

on the other hand. following setup works without error

help_agent =Agent(
    name= 'help desk agent', 
    instructions=f"""You are an experienced and kind help desk agent. Help users in terms of their needs, if the question about travel. 
    You may need to call multiple agents to get all answers.
    Today : {datetime.now().strftime("%Y-%m-%d")}""",
    model='gpt-4.1',
    tools=[
        f_agent.as_tool(
            tool_name="flight_information_agent", 
            tool_description="Search the flight information"
        ),
        h_agent.as_tool(
            tool_name="hotel_information_agent", 
            tool_description="Search the hotel information"
        ),
        y_agent.as_tool(
            tool_name="food_information_agent",  
            tool_description="Search the restaurants and place for food information"
        ),
        # recommender_agent.as_tool(
        #     tool_name="travel_recommendation_agent",  
        #     tool_description="gives recommendation about the travel if necessary"
        # ),
        # information_gathering_agent.as_tool(
        #     tool_name="info_gathering_agent", 
        #     tool_description="Kindly asks for travel details"
        # )
    ]
)

question : I'm considering a trip to Rome (FCO) sometime in late September or early October.     I'm pretty flexible with the exact dates, maybe around a week-long trip.     I'd like to get an idea of flight ticket prices and some well-located hotels.     I'm also a big foodie, so any recommendations for great local restaurants would be fantastic!

I suspect the issue is related to the handoff method. It seems that using handoff method provides more flexibility (e.g., with RunContextWrapper, input_type, etc.), which might helpful for advanced usage.

Any insights or clarification on this would be greatly appreciated. Thank you!

@malinphy malinphy added the question Question about using the SDK label May 14, 2025
Copy link

This issue is stale because it has been open for 7 days with no activity.

@github-actions github-actions bot added the stale label May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about using the SDK stale
Projects
None yet
Development

No branches or pull requests

1 participant