Skip to content

Commit c218592

Browse files
committed
fix: enhance output item conversion logic to preserve non-function call types in RunState
1 parent 57b700b commit c218592

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/agents/run_state.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -744,17 +744,27 @@ def _serialize_item(self, item: RunItem) -> dict[str, Any]:
744744
return result
745745

746746
def _convert_output_item_to_protocol(self, raw_item_dict: dict[str, Any]) -> dict[str, Any]:
747-
"""Convert API-format tool output items to protocol format."""
747+
"""Convert API-format tool output items to protocol format.
748+
749+
Only converts function_call_output to function_call_result (protocol format).
750+
Preserves computer_call_output and local_shell_call_output types as-is.
751+
"""
748752
converted = dict(raw_item_dict)
749-
call_id = cast(Optional[str], converted.get("call_id") or converted.get("callId"))
753+
original_type = converted.get("type")
750754

751-
converted["type"] = "function_call_result"
755+
# Only convert function_call_output to function_call_result (protocol format)
756+
# Preserve computer_call_output and local_shell_call_output types
757+
if original_type == "function_call_output":
758+
converted["type"] = "function_call_result"
759+
call_id = cast(Optional[str], converted.get("call_id") or converted.get("callId"))
752760

753-
if not converted.get("name"):
754-
converted["name"] = self._lookup_function_name(call_id or "")
761+
if not converted.get("name"):
762+
converted["name"] = self._lookup_function_name(call_id or "")
755763

756-
if not converted.get("status"):
757-
converted["status"] = "completed"
764+
if not converted.get("status"):
765+
converted["status"] = "completed"
766+
# For computer_call_output and local_shell_call_output, preserve the type
767+
# No conversion needed - they should remain as-is
758768

759769
return converted
760770

0 commit comments

Comments
 (0)