Skip to content

Python: Enhance _OutputItemTracker to prevent duplicate function call streaming - #7486

Open
cecheta wants to merge 3 commits into
microsoft:mainfrom
cecheta:tool-fix-streaming
Open

Python: Enhance _OutputItemTracker to prevent duplicate function call streaming#7486
cecheta wants to merge 3 commits into
microsoft:mainfrom
cecheta:tool-fix-streaming

Conversation

@cecheta

@cecheta cecheta commented Aug 3, 2026

Copy link
Copy Markdown
Member

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

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI review requested due to automatic review settings August 3, 2026 13:35
@cecheta
cecheta temporarily deployed to github-app-auth August 3, 2026 13:35 — with GitHub Actions Inactive
@cecheta
cecheta temporarily deployed to github-app-auth August 3, 2026 13:35 — with GitHub Actions Inactive
@cecheta
cecheta temporarily deployed to github-app-auth August 3, 2026 13:35 — with GitHub Actions Inactive
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Aug 3, 2026
@cecheta
cecheta temporarily deployed to github-app-auth August 3, 2026 13:35 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/foundry_hosting/agent_framework_foundry_hosting
   _responses.py9359090%199–202, 270, 275, 299, 354–355, 369, 372–373, 405–406, 440, 456, 518, 639, 653, 701, 761, 764, 770, 772, 849, 936–937, 1071, 1302, 1315, 1806–1808, 1810, 1857–1858, 1860–1861, 1863–1864, 1866–1867, 1872, 1881, 1884–1886, 1888, 1898, 1902, 2006–2007, 2022–2023, 2025, 2030–2034, 2036, 2043–2044, 2046–2047, 2053, 2055–2059, 2066, 2072, 2094, 2100, 2106, 2108, 2110–2113, 2121, 2123, 2184–2186, 2200–2201, 2204–2205
TOTAL44477411190% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9115 34 💤 0 ❌ 0 🔥 2m 21s ⏱️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_call output 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

@cecheta
cecheta temporarily deployed to github-app-auth August 3, 2026 13:56 — with GitHub Actions Inactive
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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be resolved now

cecheta added 3 commits August 4, 2026 10:10
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 9b232bff-6a8c-4b02-addd-89de57a82f6a

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Duplicate function call in Foundry Hosted agent when streaming

3 participants