@@ -967,7 +967,7 @@ def __init__(self, stream: ResponseEventStream) -> None:
967967 self ._reasoning_encrypted_content : str | None = None
968968 self ._fc_builder : OutputItemFunctionCallBuilder | None = None
969969 self ._mcp_builder : OutputItemMcpCallBuilder | None = None
970- self ._seen_function_call_ids : set [str ] = set ()
970+ self ._outstanding_function_calls : dict [str , str | None ] = {}
971971 self .needs_async = False
972972
973973 def handle (self , content : Content ) -> Generator [ResponseStreamEvent ]:
@@ -996,7 +996,14 @@ def handle(self, content: Content) -> Generator[ResponseStreamEvent]:
996996 yield self ._summary_part .emit_text_delta (content .text )
997997
998998 elif content .type == "function_call" and content .call_id is not None :
999- if content .user_input_request and not content .arguments and content .call_id in self ._seen_function_call_ids :
999+ # Declaration-only calls replay request metadata after the streamed call. Scope suppression to the
1000+ # outstanding occurrence because a call_id may be reused after its terminal result.
1001+ if (
1002+ content .user_input_request
1003+ and content .arguments is None
1004+ and content .call_id in self ._outstanding_function_calls
1005+ and self ._outstanding_function_calls [content .call_id ] == content .name
1006+ ):
10001007 return
10011008 if self ._active_type != "function_call" or self ._active_id != content .call_id :
10021009 yield from self ._close ()
@@ -1006,6 +1013,12 @@ def handle(self, content: Content) -> Generator[ResponseStreamEvent]:
10061013 if self ._fc_builder is not None :
10071014 yield self ._fc_builder .emit_arguments_delta (args_str )
10081015
1016+ elif content .type == "function_result" :
1017+ yield from self ._close ()
1018+ if content .call_id is not None :
1019+ self ._outstanding_function_calls .pop (content .call_id , None )
1020+ self .needs_async = True
1021+
10091022 elif content .type == "mcp_server_tool_call" and content .tool_name :
10101023 key = content .call_id or f"{ content .server_name or 'default' } ::{ content .tool_name } "
10111024 if self ._active_type != "mcp_server_tool_call" or self ._active_id != key :
@@ -1083,7 +1096,7 @@ def _open_function_call(self, content: Content) -> Generator[ResponseStreamEvent
10831096 )
10841097 self ._active_type = "function_call"
10851098 self ._active_id = content .call_id
1086- self ._seen_function_call_ids . add ( content .call_id or "" )
1099+ self ._outstanding_function_calls [ content .call_id or "" ] = content . name
10871100 yield self ._fc_builder .emit_added ()
10881101
10891102 def _open_mcp_call (self , content : Content ) -> Generator [ResponseStreamEvent ]:
0 commit comments