You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Have you searched for related issues? Others may have had similar requests : YES
Question
I am trying to do hand-offs in my production code, but I am facing a peculiar issue. I am simplifying the code here to show what I am getting.
Here's my code:
importasyncioimportrandomfromagentsimportAgent, Runner, function_toolfromagents.extensions.handoff_promptimportRECOMMENDED_PROMPT_PREFIXfromopenai.types.responsesimportResponseTextDeltaEventfrompydanticimportBaseModel@function_tooldefhow_many_jokes() ->int:
returnrandom.randint(1, 5)
classJokeFormat(BaseModel):
joke: list[str]
language: strasyncdefmain():
format_agent=Agent(
name="Format Agent",
instructions=f"""{RECOMMENDED_PROMPT_PREFIX} You will format the received joke as a Markdown. You will only return the formatted jokes.""",
model="gpt-4.1",
handoff_description="You are a joke formatter. You will format the jokes in Markdown.",
)
english_agent=Agent(
name="English Joker",
instructions=f"""{RECOMMENDED_PROMPT_PREFIX} First call the `how_many_jokes` tool. Then, tell those many jokes in English. The jokes should be very short! Once you have the jokes, you will pass them to the Format Agent """,
tools=[how_many_jokes],
model="gpt-4.1",
handoff_description="You are a joke teller. You will tell jokes ONLY in English.",
output_type=JokeFormat,
handoffs=[format_agent]
)
marathi_agent=Agent(
name="Marathi Joker",
instructions=f"""{RECOMMENDED_PROMPT_PREFIX} First call the `how_many_jokes` tool. Then, tell those many jokes in Marathi. The jokes should be very short! Once you have the jokes, you will pass them to the Format Agent """,
tools=[how_many_jokes],
model="gpt-4.1",
handoff_description="You are a joke teller. You will tell jokes ONLY in Marathi.",
output_type=JokeFormat,
handoffs=[format_agent]
)
agent=Agent(
name="Triage Agent",
instructions="You determine which agent to use based on the user joke language preference.",
handoffs=[english_agent, marathi_agent],
model="gpt-4.1",
)
result=Runner.run_streamed(
agent,
input="Hello, tell me a joke in English.",
)
print("=== Run starting ===")
asyncforeventinresult.stream_events():
# We'll ignore the raw responses event deltasifevent.type=="raw_response_event":
# print(f"** -- Type of event data: {type(event.data)}")ifisinstance(event.data, ResponseTextDeltaEvent):
print(event.data.delta, end="", flush=True)
continue# When the agent updates, print thatelifevent.type=="agent_updated_stream_event":
print(f"\nAgent updated: {event.new_agent.name}")
continue# When items are generated, print themelifevent.type=="run_item_stream_event":
ifevent.item.type=="tool_call_item":
print("-- Tool was called")
elifevent.item.type=="tool_call_output_item":
print(f"-- Tool output: {event.item.output}")
elifevent.item.type=="message_output_item":
passelse:
print(f"** -- Skipped Event Item type: {event.item.type}")
if__name__=="__main__":
asyncio.run(main())
For this, consistently, I am getting the following output:
=== Run starting ===
Agent updated: Triage Agent
Agent updated: English Joker
{"joke":["Why did the scarecrow win an award? Because he was outstanding in his field!"],"language":"English"}%
Problem
As you see, neither the tool is called, nor the format_agent is called. How do I ensure (not enforce, but ensure) that tools and the handoffs will work as expected? I have tried changing the prompts a little bit, the max I have gotten is that the how_many_jokes is called - but the format_agent is never called.
Example:
=== Run starting ===
Agent updated: Triage Agent
Agent updated: English Joker
-- Tool was called
-- Tool output: 2
{"joke":["Why did the scarecrow win an award? Because he was outstanding in his field!","Why don’t skeletons fight each other? They don’t have the guts."],"language":"English"}%
@rm-openai Could you help me with please? I am running the latest version of the SDK.
The text was updated successfully, but these errors were encountered:
tools=[
spanish_agent.as_tool(
tool_name="translate_to_spanish",
tool_description="Translate the user's message to Spanish",
),
french_agent.as_tool(
tool_name="translate_to_french",
tool_description="Translate the user's message to French",
),
],
Please read this first
Question
I am trying to do hand-offs in my production code, but I am facing a peculiar issue. I am simplifying the code here to show what I am getting.
Here's my code:
For this, consistently, I am getting the following output:
Problem
As you see, neither the tool is called, nor the
format_agent
is called. How do I ensure (not enforce, but ensure) that tools and the handoffs will work as expected? I have tried changing the prompts a little bit, the max I have gotten is that thehow_many_jokes
is called - but theformat_agent
is never called.Example:
@rm-openai Could you help me with please? I am running the latest version of the SDK.
The text was updated successfully, but these errors were encountered: