Skip to content

Python: Preserve structured output on streaming harness tool-approval path - #7800

Closed
Shivani . (Shivani767) wants to merge 2 commits into
microsoft:mainfrom
Shivani767:fix/7418-harness-streaming-structured-value
Closed

Python: Preserve structured output on streaming harness tool-approval path#7800
Shivani . (Shivani767) wants to merge 2 commits into
microsoft:mainfrom
Shivani767:fix/7418-harness-streaming-structured-value

Conversation

@Shivani767

@Shivani767 Shivani . (Shivani767) commented Aug 20, 2026

Copy link
Copy Markdown

Motivation & Context

Streaming harness runs that go through ToolApprovalMiddleware re-wrap the inner ResponseStream with AgentResponse.from_updates and did not forward output_format_type. AgentResponse.value is only parsed when _response_format is set, so structured-output streaming runs returned response.value is None. The non-streaming path is unaffected because it returns the inner AgentResponse directly.

Description & Review Guide

  • What are the major changes? ToolApprovalMiddleware._process_stream now finalizes with AgentResponse.from_updates(..., output_format_type=...), using run options["response_format"] and falling back to the agent's default_options.
  • What is the impact of these changes? Streaming harness / tool-approval runs parse structured output the same way as non-streaming runs. Approval queuing and auto-approval behavior is unchanged.
  • What do you want reviewers to focus on? That the schema is taken from the invocation (options then default_options) at wrap time, and that auto-approved tool calls still parse the final JSON message.

Related Issue

Fixes #7418

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.

… path

Forward response_format through ToolApprovalMiddleware's stream finalizer
so AgentResponse.value is parsed the same way as the non-streaming path.

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

Preserves structured outputs when streaming responses pass through tool-approval middleware.

Changes:

  • Forwards the effective response format to the outer stream finalizer.
  • Adds streaming, auto-approval, and non-streaming regression tests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
python/packages/core/agent_framework/_harness/_tool_approval.py Propagates structured-output format during stream finalization.
python/packages/core/tests/core/test_harness_tool_approval.py Adds structured-output regression coverage.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread python/packages/core/tests/core/test_harness_tool_approval.py Outdated
Comment thread python/packages/core/agent_framework/_harness/_tool_approval.py Outdated
Return the last inner AgentResponse from the streaming tool-approval
finalizer so coalesced preamble text cannot clobber response.value.
@Shivani767

Copy link
Copy Markdown
Author

Closing this in favor of keeping a single open PR: #7798

The harness structured-output work remains on fix/7418-harness-streaming-structured-value if it should be reopened later. Further review follow-ups will go on #7798.

@Shivani767
Shivani . (Shivani767) deleted the fix/7418-harness-streaming-structured-value branch August 20, 2026 18:44
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]: Harness Agent drops structured value on the streaming path with tool approval

2 participants