Repository navigation
.NET: Add sessionId overloads to AgentSessionStore - #9799
Marco Minerva (marcominerva) wants to merge 1 commit into
Conversation
Add non-virtual overloads to AgentSessionStore that accept a string sessionId instead of an AgentSessionStoreKey: - GetSessionAsync(AIAgent, string, CancellationToken) - SaveSessionAsync(AIAgent, string, AgentSession, CancellationToken) - GetOrCreateSessionAsync(AIAgent, string, CancellationToken) - DeleteSessionAsync(AIAgent, string, CancellationToken) Each overload creates an AgentSessionStoreKey without partitions and forwards to the corresponding key-based method, so the key-based methods remain the only ones implementations need to provide. This keeps the common case concise and reduces the migration effort from the previous string-based API, while preserving partition and isolation support.
There was a problem hiding this comment.
🔵 Needs a closer look
Maintainer judgment is needed on the source-compatibility tradeoff: the new public overloads make existing target-typed new(...), null, and default key arguments ambiguous despite the API being experimental.
No open issues 🎉
What changed in this PR
Adds sessionId convenience overloads to the .NET AgentSessionStore, addressing #8571 while preserving key-based methods as the implementation path for partitioned sessions.
Changes:
- Adds non-virtual overloads for get, save, get-or-create, and delete operations that forward using unpartitioned keys.
- Adds tests for argument forwarding and invalid session identifiers.
- Updates all five target-framework API baselines and clarifies XML documentation references.
| File | Description |
|---|---|
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentSessionStoreTests.cs |
Tests forwarding and session identifier validation. |
dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt |
Records the four overloads for .NET Standard 2.0. |
dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/net9.0/PublicAPI.Unshipped.txt |
Records the four overloads for .NET 9. |
dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/net8.0/PublicAPI.Unshipped.txt |
Records the four overloads for .NET 8. |
dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/net472/PublicAPI.Unshipped.txt |
Records the four overloads for .NET Framework 4.7.2. |
dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/net10.0/PublicAPI.Unshipped.txt |
Records the four overloads for .NET 10. |
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentSessionStore.cs |
Implements and documents forwarding overloads with local analyzer suppressions. |
Review effort: Balanced
|
I would keep Main concern: existing Migration benefit also needs care. Previous conventional Hosting lookup created missing sessions; new string overload returns
Given limited benefit and these costs, I would prefer keeping one explicit key-based contract rather than adding these overloads. |
|
OK, this makes sense. |
Motivation & Context
AgentSessionStorenow identifies sessions throughAgentSessionStoreKey, which enables partitioning and session isolation. However, applications that only need a session identifier must wrap every call innew AgentSessionStoreKey(sessionId), which adds noise and increases the migration effort from the previous string-based API.This PR adds
string sessionIdconvenience overloads that create an unpartitionedAgentSessionStoreKeyand forward to the key-based methods. The common case stays concise, whileAgentSessionStoreKeyremains the canonical, extensible API for partitioned scenarios.Description & Review Guide
AgentSessionStore:GetSessionAsync(AIAgent, string, CancellationToken)SaveSessionAsync(AIAgent, string, AgentSession, CancellationToken)GetOrCreateSessionAsync(AIAgent, string, CancellationToken)DeleteSessionAsync(AIAgent, string, CancellationToken)new AgentSessionStoreKey(sessionId)and forwards to the corresponding key-based method, sosessionIdvalidation (null/empty/whitespace) is the same as forAgentSessionStoreKey.GetSessionAsyncandSaveSessionAsync; equivalent overloads were also added forGetOrCreateSessionAsyncandDeleteSessionAsyncto keep the API surface consistent.RS0026(multiple overloads with optional parameters) is suppressed locally around each overload pair, following the existing pattern used forGetServicein the same class.crefs toGetSessionAsyncwere made explicit to avoid ambiguity between the overloads.PublicAPI.Unshipped.txtfor all target frameworks and added unit tests that verify forwarding (key without partitions, same agent/session/cancellation token) andsessionIdvalidation.AgentSessionStoreare unaffected: they still override only theAgentSessionStoreKey-based methods, and the new overloads apply automatically to every store.new(...)or anull/defaultliteral as the key argument now get an ambiguous call error (CS0121) and must usenew AgentSessionStoreKey(...)explicitly. No such call sites exist in the repository, and the affected APIs are[Experimental]and not yet shipped (they are only listed inPublicAPI.Unshipped.txt).new(...)is acceptable.[OverloadResolutionPriority]was considered, but it would require a polyfill fornetstandard2.0/net472/net8.0and is only honored by callers using C# 13 or later, so it was not added.Related Issue
Fixes #8571
AI Assistance
AI assistance details: GitHub Copilot assisted with the unit tests and the comments in the code
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.