-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Open
Labels
Description
Please read this first
- Have you read the docs?Agents SDK docs
- Have you searched for related issues? Others may have faced similar issues.
Describe the bug
Using custom_tool_behavior_handler with ToolsToFinalOutputResult in tool_use_behavior allows an agent to directly return a tool’s result when certain conditions are met, effectively bypassing the agent’s reasoning time. However, this mechanism fails when the agent is used as a tool by another agent.
In such cases, the tool-agent correctly returns the tool’s function output when the conditions are met, but the main agent receives only an empty string. This behavior is unexpected.
Please check the minimal code example below.
Debug information
- Agents SDK version: (e.g.
v0.4.2) - Python version (e.g. Python 3.10)
Repro steps
from agents import Agent, function_tool
from agents.agent import ToolsToFinalOutputResult
@function_tool
def add_numbers_tool(a: int, b: int) -> int:
return a + b
def custom_tool_behavior_handler(
context, tool_results,
) -> ToolsToFinalOutputResult:
"""Processes tool results to decide final output."""
for result in tool_results:
if result.output > 0:
return ToolsToFinalOutputResult(
is_final_output=True, final_output=result.output
)
return ToolsToFinalOutputResult(is_final_output=False, final_output=None)
adding_agent = Agent(
name="Sub Agent",
instructions="You are a helpful assistant that adds two numbers.",
model="gpt-5-mini",
tools=[add_numbers_tool],
tool_use_behavior=custom_tool_behavior_handler,
)
main_agent = Agent(
name="Main Agent",
instructions="You are a helpful assistant.",
model="gpt-5-mini",
tools=[adding_agent.as_tool(name="sub_agent_tool")],
)Expected behavior
The main agent will get the proper value rather than an empty string returned by the tool agent (sub tool agent, use Agent.as_tool()).
stevenleeRNC