8000 Python: Fix structured_output propagation in ClaudeAgent by amitmukh · Pull Request #4137 · microsoft/agent-framework · GitHub
[go: up one dir, main page]

Skip to content

Python: Fix structured_output propagation in ClaudeAgent#4137

Merged
dmytrostruk merged 5 commits intomicrosoft:mainfrom
amitmukh:fix/claude-structured-output
Feb 23, 2026
Merged

Python: Fix structured_output propagation in ClaudeAgent#4137
dmytrostruk merged 5 commits intomicrosoft:mainfrom
amitmukh:fix/claude-structured-output

Conversation

@amitmukh
Copy link
Contributor

Summary

  • Fix structured_output from ResultMessage not being propagated to AgentResponse.value
  • When ClaudeAgent is configured with output_format, the CLI returns structured_output in ResultMessage but _get_stream() was silently discarding it
  • This change captures structured_output and makes it available via response.value

Fixes #4095

Changes

  • _agent.py: Capture structured_output from ResultMessage, yield as final AgentResponseUpdate with additional_properties, custom finalizer to set response.value
  • test_claude_agent.py: Add 4 tests for structured output propagation (present, absent, streaming, error case)

Test plan

  • All 49 existing + new unit tests pass
  • New tests cover: propagation, None case, streaming, error case

Capture structured_output from ResultMessage in _get_stream() and
propagate it to AgentResponse.value via a custom finalizer. Previously
structured_output was silently discarded, making output_format unusable.

Fixes microsoft#4095
Copilot AI review requested due to automatic review settings February 20, 2026 19:43
@github-actions github-actions bot changed the title Fix structured_output propagation in ClaudeAgent Python: Fix structured_output propagation in ClaudeAgent Feb 20, 2026
@markwallace-microsoft
Copy link
Member
markwallace-microsoft commented Feb 20, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _types.py9988791%49, 58–59, 113, 118, 137, 139, 143, 147, 149, 151, 153, 171, 175, 201, 223, 228, 233, 237, 263, 267, 615–616, 987, 1049, 1066, 1084, 1089, 1107, 1117, 1134–1135, 1137, 1155–1156, 1158, 1165–1166, 1168, 1203, 1214–1215, 1217, 1255, 1482, 1534, 1625–1630, 1652, 1657, 1823, 1835, 2078, 2087, 2108, 2203, 2432, 2639, 2709, 2721, 2739, 2937–2939, 2942–2944, 2948, 2953, 2957, 3041–3043, 3072, 3126, 3145–3146, 3149–3153, 3159
TOTAL22149347284% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4265 240 💤 0 ❌ 0 🔥 1m 17s ⏱️

Copy link
Contributor
Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where structured_output from Claude's CLI was not being propagated to AgentResponse.value, making the output_format feature unusable. When ClaudeAgent is configured with output_format (JSON Schema), the Claude CLI correctly returns a ResultMessage with a structured_output field, but the agent framework was silently discarding it.

Changes:

  • Modified _get_stream() to capture structured_output from ResultMessage and yield it as a final AgentResponseUpdate with additional_properties
  • Added custom _finalize_response() method that extracts structured_output from updates and sets it as response.value
  • Added comprehensive test coverage with 4 new tests covering propagation, absence, streaming, and error scenarios

Reviewed changes

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

File Description
python/packages/claude/agent_framework_claude/_agent.py Adds structured_output capture in _get_stream(), custom _finalize_response() finalizer that propagates structured_output to response.value
python/packages/claude/tests/test_claude_agent.py Adds 4 comprehensive tests for structured output propagation in various scenarios (present, absent, streaming, error)

@amitmukh
Copy link
Contributor Author

@microsoft-github-policy-service agree company="Microsoft"

Amit Mukherjee added 2 commits February 23, 2026 11:41
…rties

- Extend AgentResponse.from_updates() to accept optional value parameter
- Remove structured_output yield from _get_stream()
- Update _finalize_response() to pass value via public API
- Update streaming test to use get_final_response()
Add value parameter to both @overload signatures of
AgentResponse.from_updates() so mypy recognizes the argument.
@dmytrostruk dmytrostruk added this pull request to the merge queue Feb 23, 2026
Merged via the queue into microsoft:main with commit 11628c3 Feb 23, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

5 participants

0