Skip to content

.NET: Agent AuthorName not preserved during group chat role-switching #1413

@ltwlf

Description

@ltwlf

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.

  1. Create a group chat workflow with multiple agents (5+ agents increases likelihood)
  2. Implement custom GroupChatManager that checks message.AuthorName for routing
  3. Run workflow with multiple sequential agent responses
  4. Intermittently, SelectNextAgentAsync receives messages with incorrect AuthorName values
  5. 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.

Metadata

Metadata

Assignees

Labels

.NETworkflowsRelated to Workflows in agent-framework

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions