fix: use active agent name for streaming message sender after handoff - #105
Open
Osamaali313 wants to merge 1 commit into
Open
fix: use active agent name for streaming message sender after handoff#105Osamaali313 wants to merge 1 commit into
Osamaali313 wants to merge 1 commit into
Conversation
In run_and_stream, the per-turn assistant message dict was initialized with "sender": agent.name -- the original starting agent, bound once at entry. Handoffs reassign active_agent but never agent, so every assistant message stored in streaming mode after a handoff is stamped with the starting agent's name. This contradicts the streamed delta on the next line (delta["sender"] = active_agent.name) and the non-streaming run() (message.sender = active_agent.name). Use active_agent.name. Add a streaming-handoff regression test.
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
In
Swarm.run_and_stream(swarm/core.py), the per-turn assistantmessagedict is initialized with the wrong sender:agentis the original starting agent, bound once at entry. During the loop, handoffs reassignactive_agent(active_agent = partial_response.agent) but neveragent. So every assistant message stored in streaming mode after a handoff is stamped with the starting agent's name.This is a wrong-variable bug — the same method already uses the correct variable everywhere else:
delta["sender"] = active_agent.namerun:message.sender = active_agent.nameOnly the streaming
messagedict usesagent.name.Impact
Consumers reading
Response.messages[*]["sender"]in streaming mode get the wrong agent for any assistant turn after a handoff — including the shippedrepl.pretty_print_messages, which printsmessage["sender"]. Within a single response the streamed delta says one agent while the stored message says another.Reproduction
Driving
run(..., stream=True)through a handoff (agent1 → agent2):['Agent 1', 'Agent 2']['Agent 1', 'Agent 1']— the agent2 turn is mislabeled['Agent 1', 'Agent 2']— matches the deltasFix
Test
Added
test_streaming_message_sender_after_handofftotests/test_core.py(there was no streaming test). It fails before the fix (stored sender'Agent 1') and passes after; the full suite is green (7 passed).