close
Skip to content

.NET: fix: preserve AG-UI session history - #5904

Merged
Evan Mattson (moonbox3) merged 3 commits into
microsoft:mainfrom
he-yufeng:fix/agui-session-preserve-history
Jun 9, 2026
Merged

.NET: fix: preserve AG-UI session history#5904
Evan Mattson (moonbox3) merged 3 commits into
microsoft:mainfrom
he-yufeng:fix/agui-session-preserve-history

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Summary

  • keep ChatClientAgent's local history provider active for AG-UI thread ids
  • avoid treating AG-UI ConversationId as service-managed model history
  • add a two-turn AG-UI regression test for sessions after the thread id is set

Fixes #5898

Verified

  • dotnet test --project tests\Microsoft.Agents.AI.AGUI.UnitTests\Microsoft.Agents.AI.AGUI.UnitTests.csproj -f net10.0 --filter-method '*RunStreamingAsync_WithSession_SendsFullHistoryAfterThreadIdIsSetAsync'
  • dotnet test --project tests\Microsoft.Agents.AI.AGUI.UnitTests\Microsoft.Agents.AI.AGUI.UnitTests.csproj -f net10.0 --filter-class Microsoft.Agents.AI.AGUI.UnitTests.AGUIAgentTests
  • dotnet test --project tests\Microsoft.Agents.AI.UnitTests\Microsoft.Agents.AI.UnitTests.csproj -f net10.0 --filter-class Microsoft.Agents.AI.UnitTests.ChatClientAgent_ChatHistoryManagementTests
  • dotnet test --project tests\Microsoft.Agents.AI.AGUI.UnitTests\Microsoft.Agents.AI.AGUI.UnitTests.csproj -f net472 --filter-class Microsoft.Agents.AI.AGUI.UnitTests.AGUIAgentTests
  • dotnet test --project tests\Microsoft.Agents.AI.UnitTests\Microsoft.Agents.AI.UnitTests.csproj -f net472 --filter-class Microsoft.Agents.AI.UnitTests.ChatClientAgent_ChatHistoryManagementTests
  • dotnet test --project tests\Microsoft.Agents.AI.AGUI.UnitTests\Microsoft.Agents.AI.AGUI.UnitTests.csproj -f net10.0
  • dotnet test --project tests\Microsoft.Agents.AI.AGUI.UnitTests\Microsoft.Agents.AI.AGUI.UnitTests.csproj -f net472

Copilot AI review requested due to automatic review settings May 15, 2026 21:09
@moonbox3 Evan Mattson (moonbox3) added the .NET Usage: [Issues, PRs], Target: .Net label May 15, 2026
@github-actions github-actions Bot changed the title fix: preserve AG-UI session history .NET: fix: preserve AG-UI session history May 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Comment thread dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs Outdated
@moonbox3
Evan Mattson (moonbox3) added this pull request to the merge queue Jun 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 9, 2026
@moonbox3
Evan Mattson (moonbox3) added this pull request to the merge queue Jun 9, 2026
Merged via the queue into microsoft:main with commit d222079 Jun 9, 2026
26 checks passed
github-actions Bot added a commit to microsoft/agent-framework-go that referenced this pull request Jun 9, 2026
The AG-UI provider assigns a thread ID to the session on the first run by
calling session.SetServiceID(threadID). The agent's history machinery
interpreted any non-empty ServiceID as a signal that the service manages
history server-side, and therefore disabled the local HistoryProvider for
every subsequent run. This caused conversation history to be dropped after
the first turn.

Add ServiceDoesNotManageHistory bool to ProviderConfig. Providers that
never delegate history to the service (e.g. AGUI) set this flag true; the
agent then preserves the HistoryProvider across runs regardless of whether
the session has a ServiceID. This also prevents the provider from being
flagged as a conflict when a user-configured HistoryProvider is present.

Set ServiceDoesNotManageHistory: true in the AGUI provider constructor.

Add TestAGUIAgentRun_WithSession_PreservesHistoryAcrossMultipleTurns to
verify that the second run sends the full conversation history (3 messages)
rather than only the new user message.

Ports behavior fix from microsoft/agent-framework#5904.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
George Adams (gdams) pushed a commit to microsoft/agent-framework-go that referenced this pull request Jun 9, 2026
#258)

The AG-UI provider assigns a thread ID to the session on the first run by
calling session.SetServiceID(threadID). The agent's history machinery
interpreted any non-empty ServiceID as a signal that the service manages
history server-side, and therefore disabled the local HistoryProvider for
every subsequent run. This caused conversation history to be dropped after
the first turn.

Add ServiceDoesNotManageHistory bool to ProviderConfig. Providers that
never delegate history to the service (e.g. AGUI) set this flag true; the
agent then preserves the HistoryProvider across runs regardless of whether
the session has a ServiceID. This also prevents the provider from being
flagged as a conflict when a user-configured HistoryProvider is present.

Set ServiceDoesNotManageHistory: true in the AGUI provider constructor.

Add TestAGUIAgentRun_WithSession_PreservesHistoryAcrossMultipleTurns to
verify that the second run sends the full conversation history (3 messages)
rather than only the new user message.

Ports behavior fix from microsoft/agent-framework#5904.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: AG UI session stops updating after first turn

4 participants