-
Notifications
You must be signed in to change notification settings - Fork 758
Closed
Labels
Description
Summary
In group chat workflows using AgentWorkflowBuilder, agent responses lose their original AuthorName during role-switching between ChatRole.Assistant and ChatRole.User. This causes routing failures and incorrect message attribution in multi-agent conversations.
Reproduction
Note: This is a timing-dependent issue that may not reproduce consistently. It appears to be a race condition in how ChatMessage objects are modified during role-switching.
- Create a group chat workflow with multiple agents (5+ agents increases likelihood)
- Implement custom
GroupChatManagerthat checksmessage.AuthorNamefor routing - Run workflow with multiple sequential agent responses
- Intermittently,
SelectNextAgentAsyncreceives messages with incorrectAuthorNamevalues - Messages that should have
AuthorName="agentA"instead showAuthorName="facilitator"or other incorrect values
Expected Behavior
Agent responses should maintain their original AuthorName throughout the workflow, regardless of role-switching operations.
Actual Behavior
AuthorNameis set from agent'sNameproperty during initial response- Role-switching changes
Rolebut losesAuthorName - Restored messages have correct
RolebutAuthorNameremains incorrect or null - Causes routing failures when checking message author for turn-taking logic
- Timing-dependent: Appears to be a race condition where message modifications aren't fully synchronized
- Inconsistent: Same workflow may work correctly on some runs, fail on others
Impact
- Custom routing managers cannot reliably identify message authors
- Multi-agent conversations fail or route incorrectly
- Conversation history shows incorrect attribution
- Affects any workflow using
AgentWorkflowBuilder.CreateGroupChatBuilderWith()
Additional Notes
Debugging: The issue is difficult to trace because:
- Streaming events (
AgentRunUpdateEvent) show correctAuthorNamevalues - But
ChatMessagehistory passed toSelectNextAgentAsyncshows incorrect values - Suggests the issue is in how messages are modified/restored between event emission and history building
- Adding debug logging to
ChangeAssistantToUserForOtherParticipantsandResetUserToAssistantForChangedRoleshelps identify when attribution is lost
Related issues discovered:
- Agent name comparison uses case-sensitive string matching (should be case-insensitive)
DisplayNameproperty used for routing instead of stableNameproperty
I'm preparing a PR with fixes for these issues.