Skip to content

.NET: Add AGUI session persistence#5113

Open
Kazunari001 wants to merge 3 commits intomicrosoft:mainfrom
Kazunari001:feature/add-AGUI-session-persistence
Open

.NET: Add AGUI session persistence#5113
Kazunari001 wants to merge 3 commits intomicrosoft:mainfrom
Kazunari001:feature/add-AGUI-session-persistence

Conversation

@Kazunari001
Copy link
Copy Markdown

Motivation and Context

Fix #4869

Description

  • add an in-memory AGUI session store and register it in DI
  • persist agent sessions by thread id during streaming runs
  • add integration tests for conversation and session restoration
  • add unit tests for cache key isolation and session expiration

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings April 6, 2026 05:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds server-side, in-memory session persistence for the ASP.NET Core AG-UI hosting endpoint to ensure conversation/session continuity across requests using thread IDs (fixing #4869).

Changes:

  • Introduces an in-memory AGUIInMemorySessionStore and registers it in DI via AddAGUI().
  • Updates MapAGUI streaming execution to load/create a session by ThreadId and persist it after streaming completes.
  • Adds unit + integration tests validating cache-key isolation, expiration, and cross-request/session restoration behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/AGUIInMemorySessionStore.cs Adds an in-memory MemoryCache-backed store for AgentSession keyed by agent/thread.
dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/ServiceCollectionExtensions.cs Registers the in-memory session store in DI as a singleton when calling AddAGUI().
dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/AGUIEndpointRouteBuilderExtensions.cs Loads/creates sessions by ThreadId and persists them during streaming runs.
dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests/AGUIInMemorySessionStoreTests.cs Unit tests for reuse, key isolation, and expiration behavior.
dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/BasicStreamingTests.cs Integration tests validating conversation/session restoration across calls.

@Kazunari001
Copy link
Copy Markdown
Author

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: AGUIChatClient sets ConversationId in response despite being stateless

2 participants