Python: Fix Foundry reasoning MCP compaction#6907
Open
godququ5-code wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Python response-history reconstruction and core compaction behavior so Foundry reasoning items and subsequent MCP tool calls remain correctly paired and valid for downstream APIs (avoiding “orphaned mcp_call” 400s in multi-turn reasoning flows).
Changes:
- Preserve Foundry reasoning summaries as
text_reasoningcontent (instead of plaintext) while retaining the provider reasoningid. - Treat
mcp_server_tool_callassistant messages as tool-call items during compaction grouping so reasoning + MCP call pairs stay atomic. - Add targeted regression tests covering both Foundry reasoning reconstruction paths and sliding-window MCP compaction grouping.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py | Reconstruct reasoning summaries as text_reasoning while preserving reasoning IDs. |
| python/packages/foundry_hosting/tests/test_responses.py | Adds assertions ensuring reconstructed reasoning content type and ID are preserved. |
| python/packages/core/agent_framework/_compaction.py | Expands tool-call detection to include MCP server tool calls for proper grouping/compaction. |
| python/packages/core/tests/core/test_compaction.py | Adds regression ensuring sliding-window compaction keeps reasoning + MCP calls in the same group. |
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
text_reasoningwith the provider reasoning id when reconstructing response history.mcp_server_tool_callas a tool-call assistant item during compaction so reasoning + MCP call pairs stay atomic.Fixes #6883
Root cause
Foundry response reconstruction converted reasoning summaries into ordinary text content, dropping the reasoning id. Core compaction also only recognized
function_callassistant messages as tool-call items, so an MCP call following a reasoning item could be grouped separately and survive after its reasoning prefix was excluded.Test plan
uv run pytest packages/core/tests/core/test_compaction.py packages/foundry_hosting/tests/test_responses.py -quv run prek run --files packages/core/agent_framework/_compaction.py packages/core/tests/core/test_compaction.py packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py packages/foundry_hosting/tests/test_responses.pyNote: the pytest command exits 0, but the local environment emits unrelated OpenTelemetry exporter shutdown noise against
127.0.0.1:7897after the tests finish.