Skip to content

.NET: [Bug]: AG-UI endpoint sends duplicate conversation messages to providers #7930

Description

@SergeyMenshykh

Description

When an AG-UI client sends the full chat history on every turn, MapAGUIServer (AGUIEndpointRouteBuilderExtensions) forwards RunAgentInput.Messages (full chat history) together with the session - which was restored from the session store and already carries the previous turns, either as locally persisted chat history or as a provider conversation id - to the underlying agent. As a result, duplicates are sent to the inference service/model regardless of whether provider storage is enabled or disabled.

Provider storage disabled (store = false)

The session keeps chat history locally. On each turn the agent loads the persisted chat history from the session and prepends it to the incoming messages. Because the incoming messages are the full chat history from the AG-UI client and the session already contains the previous messages, every earlier message appears twice in the request sent to the model. That merged, already-duplicated list is then written back into the session's chat history, so the duplication compounds on every subsequent turn.

Provider storage enabled (store = true)

The session is bound to a provider-side conversation, so local chat history is not used and only the incoming messages are sent. Since the incoming messages are the full chat history from the AG-UI client, all previously sent messages are re-submitted on each turn to a conversation that already contains them, and the provider appends them again.

In both cases the underlying model receives duplicated prior messages, which increases token usage and can degrade response quality.

Package Versions

Microsoft.Agents.AI.Hosting.AGUI.AspNetCore (main)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

.NETUsage: [Issues, PRs], Target: .Net

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions