-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Open
Copy link
Labels
.NETbugSomething isn't workingSomething isn't workingtriagev1.0Features being tracked for the version 1.0 GAFeatures being tracked for the version 1.0 GA
Description
Description
When a workflow agent (uses agent-framework) invokes a prompt agent, the user's input message appears twice in the prompt agent's input messages. This happens because ChatClientAgent.PrepareSessionAndMessagesAsync() retrieves chat history (which may already contain the input message) and then unconditionally appends the input messages again.
What happened?
- User sends a single message (e.g., "test") to a workflow agent
- Workflow agent calls CopyConversationMessages to persist the message before invoking a child agent
- Workflow invokes the prompt agent with the same message as inputMessages
- ChatClientAgent.PrepareSessionAndMessagesAsync retrieves history (now containing the message)
- It then adds inputMessages unconditionally → duplicate message
What did you expect to happen?
The user's input message should appear exactly once in the agent's input, not duplicated.
Steps to reproduce the issue
- Create a workflow agent that invokes a prompt agent
- Send a single user message to the workflow
- Observe the prompt agent receives the input message twice
Code Sample
Bug location: `dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs`, method `PrepareSessionAndMessagesAsync()`, lines 711-723
// Lines 714-720: Retrieve history from ChatHistoryProvider
if (chatHistoryProvider is not null)
{
var providerMessages = await chatHistoryProvider.InvokingAsync(...);
inputMessagesForChatClient.AddRange(providerMessages); // History may contain input message
}
// Lines 722-723: Add input messages AGAIN
inputMessagesForChatClient.AddRange(inputMessages); // Duplicates if message was already in history!
Proposed fix:
// After getting chat history, filter out messages already present before adding inputMessages
if (chatHistoryProvider is not null)
{
// ... existing code ...
}
// Only add input messages that are not already in history
HashSet<string?> existingMessageIds = inputMessagesForChatClient
.Where(m => !string.IsNullOrEmpty(m.MessageId))
.Select(m => m.MessageId)
.ToHashSet();
inputMessagesForChatClient.AddRange(
inputMessages.Where(m => string.IsNullOrEmpty(m.MessageId) || !existingMessageIds.Contains(m.MessageId)));Error Messages / Stack Traces
none. just happens.Package Versions
latest utilized by workflow agents
.NET Version
No response
Additional Context
No response
Metadata
Metadata
Assignees
Labels
.NETbugSomething isn't workingSomething isn't workingtriagev1.0Features being tracked for the version 1.0 GAFeatures being tracked for the version 1.0 GA
Type
Projects
Status
No status