Demote system messages in handoff context - #8244
Open
DDDonut (daleselaji-dev) wants to merge 1 commit into
Open
DDDonut (daleselaji-dev) wants to merge 1 commit into
DDDonut (daleselaji-dev) wants to merge 1 commit into
Conversation
Contributor
|
DDDonut (@daleselaji-dev) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
This branch has not been deployed
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.
Problem
A
HandoffMessagecan carry arbitraryLLMMessagecontext from one participant to another. The receive path inserted that context into the target agent's model context without changing message roles, so peer-authoredSystemMessagecontent reached the target model with system authority.Root Cause
The handoff receive logic in
AssistantAgent,CodeExecutorAgent, andSelectorGroupChatManagerdirectly calledmodel_context.add_message()for every context entry. Normal peer messages are converted toUserMessage, but handoff context bypassed that boundary.Solution
Normalize handoff context at the receive boundary. System messages from peer-provided handoff context are converted to
UserMessage(source="handoff"); assistant and function-result messages retain their existing representation for the supported tool-call handoff flow.Changes
demote_handoff_context_message()conversion helper.Testing
python -m pytest packages/autogen-agentchat/tests/test_messages.py -q— 9 passed.python -m pytest packages/autogen-agentchat/tests/test_messages.py packages/autogen-agentchat/tests/test_assistant_agent.py::TestAssistantAgentMessageContext -q— 12 passed.ruff checkon all changed files — passed.ruff format --checkon all changed files — passed.uv run poe pyrightforautogen-agentchatandautogen-core— 0 errors.autogen-extdependencies are not installed (cv2,ffmpeg,whisper,chromadb,graphrag, and related diagnostics).git diff --check— passed.Compatibility/Risk
Only peer-provided
SystemMessageentries insideHandoffMessage.contextchange role, which prevents privileged-role injection at the receive boundary. Existing assistant/tool-result handoff context remains unchanged. No public constructor or serialized schema changes are introduced.Notes for Reviewer
The conversion is shared so the AssistantAgent, CodeExecutorAgent, and selector receive paths cannot drift. The
source="handoff"marker makes the trust-boundary conversion explicit in downstream model context. This is intentionally limited to receive-side role demotion; tool capability policy is outside this PR.Linked Issue
Fixes #8238