Python: fix: keep reasoning with hosted MCP calls#6110
Closed
he-yufeng wants to merge 1 commit into
Closed
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates OpenAI chat message preparation to optionally keep inline reasoning content when it accompanies a hosted MCP tool call (when service-side storage is disabled), and adds tests covering the new behavior.
Changes:
- Adjust
_prepare_message_for_openaito retaintext_reasoningitems only when paired with a hosted MCP call and request storage is off. - Add tests ensuring reasoning is preserved/dropped depending on
request_uses_service_side_storage. - Add a test ensuring reasoning is preserved when an MCP call/result is coalesced.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/packages/openai/agent_framework_openai/_chat_client.py | Changes reasoning serialization rules based on presence of hosted MCP calls and storage flag. |
| python/packages/openai/tests/openai/test_openai_chat_client.py | Adds regression tests for reasoning + hosted MCP call behavior (with/without storage and with coalesced results). |
Comment on lines
+1487
to
1503
| # without its required following item"), so only keep reasoning inline when it is paired | ||
| # with a hosted MCP call in the same assistant message. | ||
| has_hosted_mcp_call = any( | ||
| item.type == "mcp_server_tool_call" and getattr(item, "call_id", None) for item in message.contents | ||
| ) | ||
| for content in message.contents: | ||
| match content.type: | ||
| case "text_reasoning": | ||
| if not request_uses_service_side_storage and has_hosted_mcp_call: | ||
| prepared_reasoning = self._prepare_content_for_openai( | ||
| message.role, | ||
| content, | ||
| replays_local_storage=replays_local_storage, | ||
| ) | ||
| if prepared_reasoning: | ||
| all_messages.append(prepared_reasoning) | ||
| continue |
|
|
||
| result = client._prepare_messages_for_openai(messages, request_uses_service_side_storage=False) | ||
|
|
||
| types = [item.get("type") for item in result if isinstance(item, dict)] |
4bb178b to
33377bc
Compare
Contributor
Author
|
Closing this in favor of #6139. The newer PR carries the current version of the same hosted MCP reasoning preservation fix, so keeping both open just splits review attention. |
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.
Fixes #6074
Summary
text_reasoningitems when replaying a hosted MCP call without service-side storageTests
python -m pytest python\packages\openai\tests\openai\test_openai_chat_client.py -q -p no:cacheprovider -k "hosted_mcp_call_storage_off or hosted_mcp_call_with_storage or coalesced_hosted_mcp_result or mcp_server_tool_call or coalesces_mcp_call"python -m pytest python\packages\openai\tests\openai\test_openai_chat_client.py -q -p no:cacheprovider -k "reasoning or mcp_server_tool"python -m ruff check python\packages\openai\agent_framework_openai\_chat_client.py python\packages\openai\tests\openai\test_openai_chat_client.pypython -m ruff format --check python\packages\openai\agent_framework_openai\_chat_client.py python\packages\openai\tests\openai\test_openai_chat_client.pypython -m py_compile python\packages\openai\agent_framework_openai\_chat_client.py python\packages\openai\tests\openai\test_openai_chat_client.pygit diff --check