Python: re-role trailing assistant message to user for Anthropic compatibility (fixes #5008)#6207
Open
hanhan761 wants to merge 5 commits into
Open
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 tool invocation argument handling to preserve None values, adds regression coverage, and adjusts Anthropic message preparation to satisfy its “last message must be user” constraint.
Changes:
- Preserve explicit
Nonetool arguments by disablingexclude_noneduring Pydantic dumps. - Add a regression test for tool invocation with explicit
None. - Ensure Anthropic message lists end with a user message by re-labeling a trailing assistant message.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| python/packages/core/tests/core/test_tools.py | Adds a regression test around invoke() handling of explicit None arguments. |
| python/packages/core/agent_framework/_tools.py | Changes Pydantic serialization to keep None values when building invocation kwargs. |
| python/packages/anthropic/agent_framework_anthropic/_chat_client.py | Adjusts message preparation to ensure the final message role is user for Anthropic. |
…ynthetic user turn)
eavanvalkenburg
approved these changes
Jun 2, 2026
Member
|
please address the comments @hanhan761 |
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||
Author
|
All Copilot review comments have been addressed and resolved:
@eavanvalkenburg This is ready for re-review. |
eavanvalkenburg
requested changes
Jun 2, 2026
Member
eavanvalkenburg
left a comment
There was a problem hiding this comment.
There are changes unrelated to the stated goal of this PR in here, touching the core package, please remove
The exclude_none/exclude_unset changes in the core package are out of scope for this Anthropic-specific fix. This PR now only contains the Anthropic chat client docstring fix and the synthetic user turn append.
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
When two agents backed by Anthropic are connected via WorkflowBuilder, the first agent's output (assistant-role messages) is passed as context to the second agent. Anthropic's API rejects this with:
\
This model does not support assistant message prefill. The conversation must end with a user message.
\\
Changes
Modified _prepare_messages_for_anthropic\ in the Anthropic chat client:
Related
Fixes #5008