From e95758743cf9d59801765dcaaeba7486b462063a Mon Sep 17 00:00:00 2001 From: MUHAMMAD SALMAN HUSSAIN <160324527+mshsheikh@users.noreply.github.com> Date: Sat, 26 Jul 2025 02:22:46 +0500 Subject: [PATCH 1/2] fix tool response handling in translation example The agents_as_tools.py example was filtering on MessageOutputItem, but tool calls emit ToolResponseItem. Update the loop to check for ToolResponseItem and extract its inner content, so that intermediate translation steps are correctly printed via ItemHelpers. --- examples/agent_patterns/agents_as_tools.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/agent_patterns/agents_as_tools.py b/examples/agent_patterns/agents_as_tools.py index 9fd118efb..a059e2dbc 100644 --- a/examples/agent_patterns/agents_as_tools.py +++ b/examples/agent_patterns/agents_as_tools.py @@ -1,6 +1,6 @@ import asyncio -from agents import Agent, ItemHelpers, MessageOutputItem, Runner, trace +from agents import Agent, ItemHelpers, Runner, trace, ToolResponseItem """ This example shows the agents-as-tools pattern. The frontline agent receives a user message and @@ -63,10 +63,11 @@ async def main(): orchestrator_result = await Runner.run(orchestrator_agent, msg) for item in orchestrator_result.new_items: - if isinstance(item, MessageOutputItem): - text = ItemHelpers.text_message_output(item) + if isinstance(item, ToolResponseItem): + text = ItemHelpers.text_message_output(item.content) if text: - print(f" - Translation step: {text}") + lang = item.tool_name.replace("translate_to_", "").capitalize() + print(f" - {lang}: {text}") synthesizer_result = await Runner.run( synthesizer_agent, orchestrator_result.to_input_list() From 205a987d01116e50e2d7440f4cd7e002b8cdf343 Mon Sep 17 00:00:00 2001 From: MUHAMMAD SALMAN HUSSAIN <160324527+mshsheikh@users.noreply.github.com> Date: Sat, 26 Jul 2025 02:38:52 +0500 Subject: [PATCH 2/2] Fix translation step display in agents_as_tools example The example was filtering on MessageOutputItem but wasn't correctly identifying translation tool responses. Updated the loop to use ItemHelpers.text_message_output() on all items and check for tool_name attribute to properly display intermediate translation steps, while removing unused imports that caused linter errors. --- examples/agent_patterns/agents_as_tools.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/agent_patterns/agents_as_tools.py b/examples/agent_patterns/agents_as_tools.py index a059e2dbc..e87405c08 100644 --- a/examples/agent_patterns/agents_as_tools.py +++ b/examples/agent_patterns/agents_as_tools.py @@ -1,6 +1,6 @@ import asyncio -from agents import Agent, ItemHelpers, Runner, trace, ToolResponseItem +from agents import Agent, ItemHelpers, Runner, trace """ This example shows the agents-as-tools pattern. The frontline agent receives a user message and @@ -63,11 +63,13 @@ async def main(): orchestrator_result = await Runner.run(orchestrator_agent, msg) for item in orchestrator_result.new_items: - if isinstance(item, ToolResponseItem): - text = ItemHelpers.text_message_output(item.content) - if text: + text = ItemHelpers.text_message_output(item) + if text: + if hasattr(item, 'tool_name') and 'translate_to_' in getattr(item, 'tool_name', ''): lang = item.tool_name.replace("translate_to_", "").capitalize() print(f" - {lang}: {text}") + else: + print(f" - Translation step: {text}") synthesizer_result = await Runner.run( synthesizer_agent, orchestrator_result.to_input_list()