-
Notifications
You must be signed in to change notification settings - Fork 436
Open
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
GroupChatManager
that checksmessage.AuthorName
for routing - Run workflow with multiple sequential agent responses
- Intermittently,
SelectNextAgentAsync
receives messages with incorrectAuthorName
values - 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
AuthorName
is set from agent'sName
property during initial response- Role-switching changes
Role
but losesAuthorName
- Restored messages have correct
Role
butAuthorName
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 correctAuthorName
values - But
ChatMessage
history passed toSelectNextAgentAsync
shows incorrect values - Suggests the issue is in how messages are modified/restored between event emission and history building
- Adding debug logging to
ChangeAssistantToUserForOtherParticipants
andResetUserToAssistantForChangedRoles
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 stableName
property
I'm preparing a PR with fixes for these issues.