Skip to content

Commit 052339a

Browse files
Restore agent tool fallback output after nested cancellation
Co-authored-by: Codex <noreply@openai.com>
1 parent 7abbed9 commit 052339a

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/agents/agent.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,24 @@ async def dispatch_stream_events() -> None:
850850
if custom_output_extractor:
851851
return await custom_output_extractor(run_result)
852852

853+
if run_result.final_output is not None and (
854+
not isinstance(run_result.final_output, str) or run_result.final_output != ""
855+
):
856+
return run_result.final_output
857+
858+
from .items import ItemHelpers
859+
860+
text_output = ItemHelpers.text_message_outputs(run_result.new_items)
861+
if text_output:
862+
return text_output
863+
864+
for item in reversed(run_result.to_input_list()):
865+
if item.get("type") != "function_call_output":
866+
continue
867+
output = item.get("output")
868+
if isinstance(output, str) and output:
869+
return output
870+
853871
return run_result.final_output
854872

855873
run_agent_tool = _build_wrapped_function_tool(

0 commit comments

Comments
 (0)