Python: Enhance _OutputItemTracker to prevent duplicate function call streaming - #7486
Python: Enhance _OutputItemTracker to prevent duplicate function call streaming#7486cecheta wants to merge 2 commits into
Conversation
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
Fixes a Foundry Hosting streaming bug in the Python implementation where a declaration-only tool invocation can result in a duplicate function_call output item being streamed to the client. The change extends the streaming output-item tracker to recognize and suppress the metadata-only duplicate call, and adds a regression test covering the scenario.
Changes:
- Track previously-streamed function call
call_ids during a streaming response. - Suppress streaming of metadata-only duplicate function-call updates for already-seen
call_ids. - Add a regression test ensuring only one
function_calloutput item is emitted for declaration-only metadata follow-ups.
Show a summary per file
| File | Description |
|---|---|
| python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py | Adds duplicate-detection logic in _OutputItemTracker to prevent streaming a second metadata-only function call item. |
| python/packages/foundry_hosting/tests/test_responses.py | Adds a regression test reproducing the declaration-only metadata duplication scenario in streaming mode. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9b232bff-6a8c-4b02-addd-89de57a82f6a
| yield self._summary_part.emit_text_delta(content.text) | ||
|
|
||
| elif content.type == "function_call" and content.call_id is not None: | ||
| if content.user_input_request and not content.arguments and content.call_id in self._seen_function_call_ids: |
There was a problem hiding this comment.
Could we scope this suppression to the current logical occurrence instead of retaining every call_id for the full response? call_id reuse after completion is supported, so a later zero-argument user_input_request with that ID is silently dropped here as metadata. In a workflow, the request remains pending but the client never receives it and cannot resume. How about we retire the ID on its matching terminal result or otherwise distinguish the metadata replay?
Motivation & Context
Fixes bug where function call was duplicated when streaming response from declaration-only tool,
Description & Review Guide
When the agent invokes the declaration-only tool, there is a second function call emitted containing just metadata. Both of these tools were being streamed to the user.
Related Issue
Fixes #7485
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.