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
GroupChatManager that checks message.AuthorName for routing
- Run workflow with multiple sequential agent responses
- Intermittently,
SelectNextAgentAsync receives messages with incorrect AuthorName values
- Messages that should have
AuthorName="agentA" instead show AuthorName="facilitator" or other incorrect values
Expected Behavior
Agent responses should maintain their original AuthorName throughout the workflow, regardless of role-switching operations.
Actual Behavior
AuthorName is set from agent's Name property during initial response
- Role-switching changes
Role but loses AuthorName
- Restored messages have correct
Role but AuthorName remains 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 correct AuthorName values
- But
ChatMessage history passed to SelectNextAgentAsync shows incorrect values
- Suggests the issue is in how messages are modified/restored between event emission and history building
- Adding debug logging to
ChangeAssistantToUserForOtherParticipants and ResetUserToAssistantForChangedRoles helps identify when attribution is lost
Related issues discovered:
- Agent name comparison uses case-sensitive string matching (should be case-insensitive)
DisplayName property used for routing instead of stable Name property
I'm preparing a PR with fixes for these issues.
Summary
In group chat workflows using
AgentWorkflowBuilder, agent responses lose their originalAuthorNameduring role-switching betweenChatRole.AssistantandChatRole.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
ChatMessageobjects are modified during role-switching.GroupChatManagerthat checksmessage.AuthorNamefor routingSelectNextAgentAsyncreceives messages with incorrectAuthorNamevaluesAuthorName="agentA"instead showAuthorName="facilitator"or other incorrect valuesExpected 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 responseRolebut losesAuthorNameRolebutAuthorNameremains incorrect or nullImpact
AgentWorkflowBuilder.CreateGroupChatBuilderWith()Additional Notes
Debugging: The issue is difficult to trace because:
AgentRunUpdateEvent) show correctAuthorNamevaluesChatMessagehistory passed toSelectNextAgentAsyncshows incorrect valuesChangeAssistantToUserForOtherParticipantsandResetUserToAssistantForChangedRoleshelps identify when attribution is lostRelated issues discovered:
DisplayNameproperty used for routing instead of stableNamepropertyI'm preparing a PR with fixes for these issues.