Skip to content

Commit 10f7f98

Browse files
marcominervarogerbarretowestey-mCopilotSergeyMenshykh
authored
.NET: Add AgentSessionStore.DeleteSessionAsync to the Abstraction (#8801)
* .NET: Re-add AgentSessionStore.DeleteSessionAsync Bring session deletion back to the shared AgentSessionStore contract, so the store handles a session's whole lifecycle again. It was removed when the abstraction moved to Agents.AI.Abstractions (#7991). [PREVIEW BREAKING] DeleteSessionAsync is abstract: custom stores must implement it. - In-box stores implement it; deleting a missing session is a no-op - Decorators forward it, adding the isolation partition when needed - Update PublicAPI.Unshipped.txt, unit tests, ADR-0039 and spec 003 Fixes #8586 * .NET: Address session store delete review - FileSystemAgentSessionStore: delete without a File.Exists precheck so access and I/O failures surface; a missing agent directory stays a no-op. - Add unit tests for the Foundry InMemoryAgentSessionStore delete path. * Address review feedback on session store deletion * Normalize RecordingLoggerFactory header Normalized the file header in `RecordingLoggerFactory.cs` by removing an extra leading character/encoding artifact from the copyright line. No functional code was changed. * Implement DeleteSessionAsync in OAuthConsentPolicyHandlerTests session store * Move CapturingLoggerFactory to shared unit test code Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Roger Barreto <[email protected]> Co-authored-by: westey <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: SergeyMenshykh <[email protected]>
1 parent c739447 commit 10f7f98

43 files changed

Lines changed: 681 additions & 39 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/decisions/0039-shared-agent-session-store.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Chosen option: **Promote the Foundry Hosting contract to `Microsoft.Agents.AI.Ab
4141
- The abstraction and every public implementation start as experimental under diagnostic `MAAI001`.
4242
- `GetSessionAsync` returns `AgentSession?` and returns `null` when no session is stored.
4343
- `GetOrCreateSessionAsync` performs the explicit lookup or creation operation.
44-
- `SaveSessionAsync` and both lookup methods receive an `AgentSessionStoreKey`.
44+
- `SaveSessionAsync`, `DeleteSessionAsync`, and both lookup methods receive an `AgentSessionStoreKey`.
4545
- `AgentSessionStoreKey.SessionId` identifies the logical session.
4646
- `AgentSessionStoreKey.Partitions` holds zero or more named isolation dimensions. Every partition is
4747
part of identity and implementations cannot ignore unknown partitions.
@@ -50,7 +50,9 @@ Chosen option: **Promote the Foundry Hosting contract to `Microsoft.Agents.AI.Ab
5050
- Partition order does not affect identity. Physical encoding remains the responsibility of each store.
5151
- `GetService(Type, object?)` and `GetService<TService>(object?)` retain service discovery from conventional
5252
Hosting. Stores can expose themselves, underlying implementations, or additional capabilities.
53-
- `DeleteSessionAsync` is not part of the shared contract.
53+
- `DeleteSessionAsync` is abstract, like `GetSessionAsync` and `SaveSessionAsync`, so the store remains the
54+
single owner of the whole session lifecycle. It removes the stored session and treats a missing session as
55+
a no-op. Decorators forward it, applying the same key transformation used for lookup and save.
5456

5557
The duplicate types in `Microsoft.Agents.AI.Hosting` and `Microsoft.Agents.AI.Foundry.Hosting` are removed.
5658
Both packages reference the shared type directly.
@@ -86,7 +88,7 @@ Negative:
8688

8789
- This is a source-breaking change for implementations of the preview Hosting contract.
8890
- Callers must construct an `AgentSessionStoreKey`; unpartitioned sessions use only `SessionId`.
89-
- Consumers that need deletion must use a storage-specific API until a separate shared deletion capability is defined.
91+
- Every store implementation must provide `DeleteSessionAsync`.
9092

9193
## More Information
9294

‎docs/specs/003-dotnet-hosting-protocol-helpers.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ public abstract class AgentSessionStore
109109
AgentSessionStoreKey key,
110110
AgentSession session,
111111
CancellationToken cancellationToken = default);
112+
113+
public abstract ValueTask DeleteSessionAsync(
114+
AIAgent agent,
115+
AgentSessionStoreKey key,
116+
CancellationToken cancellationToken = default);
112117
}
113118
```
114119

@@ -139,7 +144,8 @@ state without observing another branch's changes. The store performs no cross-ca
139144
application that needs concurrent runs against the same id to be serialized owns that coordination.
140145
`SaveSessionAsync(agent, key, session)` persists the post-run state, including under a newly
141146
minted `resp_*` id when the protocol creates a continuation id. No agent-side holder is needed because
142-
the convenience method already performs lookup or creation.
147+
the convenience method already performs lookup or creation. `DeleteSessionAsync(agent, key)` removes the
148+
stored session and is a no-op when nothing is stored.
143149

144150
`AgentSessionStoreKey` contains a session id plus arbitrary named partitions. Every partition contributes
145151
to identity, independent of dictionary order. Stores must not ignore unknown partitions. Physical key

‎dotnet/agent-framework-dotnet.slnx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,10 @@
588588
<Folder Name="/Solution Items/src/Shared/StructuredOutput/">
589589
<File Path="src/Shared/StructuredOutput/StructuredOutputSchemaUtilities.cs" />
590590
</Folder>
591+
<Folder Name="/Solution Items/src/Shared/UnitTests/">
592+
<File Path="src/Shared/UnitTests/CapturingLoggerFactory.cs" />
593+
<File Path="src/Shared/UnitTests/README.md" />
594+
</Folder>
591595
<Folder Name="/Solution Items/src/Shared/Workflows/" />
592596
<Folder Name="/Solution Items/src/Shared/Workflows/Execution/">
593597
<File Path="src/Shared/Workflows/Execution/README.md" />

‎dotnet/eng/MSBuild/Shared.props‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<ItemGroup Condition="'$(InjectSharedIntegrationTestCode)' == 'true'">
99
<Compile Include="$(MSBuildThisFileDirectory)\..\..\src\Shared\IntegrationTests\*.cs" LinkBase="Shared\IntegrationTests" />
1010
</ItemGroup>
11+
<ItemGroup Condition="'$(InjectSharedUnitTestCode)' == 'true'">
12+
<Compile Include="$(MSBuildThisFileDirectory)\..\..\src\Shared\UnitTests\*.cs" LinkBase="Shared\UnitTests" />
13+
</ItemGroup>
1114
<ItemGroup Condition="'$(InjectSharedIntegrationTestAzureCredentialsCode)' == 'true'">
1215
<Compile Include="$(MSBuildThisFileDirectory)\..\..\src\Shared\IntegrationTestsAzureCredentials\*.cs" LinkBase="Shared\IntegrationTestsAzureCredentials" />
1316
</ItemGroup>

‎dotnet/src/Microsoft.Agents.AI.Abstractions/AgentSessionStore.cs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ public virtual async ValueTask<AgentSession> GetOrCreateSessionAsync(
7878
?? await agent.CreateSessionAsync(cancellationToken).ConfigureAwait(false);
7979
}
8080

81+
/// <summary>
82+
/// Deletes a stored agent session, if present.
83+
/// </summary>
84+
/// <param name="agent">The agent that owns this session.</param>
85+
/// <param name="key">The key that identifies and partitions the session.</param>
86+
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests.</param>
87+
/// <returns>A task that represents the asynchronous delete operation.</returns>
88+
/// <remarks>
89+
/// Implementations delete the session and treat a missing session as a no-op.
90+
/// </remarks>
91+
public abstract ValueTask DeleteSessionAsync(
92+
AIAgent agent,
93+
AgentSessionStoreKey key,
94+
CancellationToken cancellationToken = default);
95+
8196
/// <summary>Asks the store for an object of the specified type.</summary>
8297
/// <param name="serviceType">The type of object being requested.</param>
8398
/// <param name="serviceKey">An optional key that identifies the requested service.</param>

‎dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/net10.0/PublicAPI.Unshipped.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[MAAI001]virtual Microsoft.Agents.AI.AgentSessionStore.GetService(System.Type! serviceType, object? serviceKey = null) -> object?
66
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.GetSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<Microsoft.Agents.AI.AgentSession?>
77
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.SaveSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, Microsoft.Agents.AI.AgentSession! session, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
8+
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.DeleteSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
89
[MAAI001]virtual Microsoft.Agents.AI.AgentSessionStore.GetOrCreateSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<Microsoft.Agents.AI.AgentSession!>
910
[MAAI001]Microsoft.Agents.AI.AgentSessionStoreKey
1011
[MAAI001]Microsoft.Agents.AI.AgentSessionStoreKey.AgentSessionStoreKey(string! sessionId, System.Collections.Generic.IReadOnlyDictionary<string!, string!>? partitions = null) -> void

‎dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/net472/PublicAPI.Unshipped.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[MAAI001]virtual Microsoft.Agents.AI.AgentSessionStore.GetService(System.Type! serviceType, object? serviceKey = null) -> object?
66
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.GetSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<Microsoft.Agents.AI.AgentSession?>
77
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.SaveSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, Microsoft.Agents.AI.AgentSession! session, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
8+
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.DeleteSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
89
[MAAI001]virtual Microsoft.Agents.AI.AgentSessionStore.GetOrCreateSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<Microsoft.Agents.AI.AgentSession!>
910
[MAAI001]Microsoft.Agents.AI.AgentSessionStoreKey
1011
[MAAI001]Microsoft.Agents.AI.AgentSessionStoreKey.AgentSessionStoreKey(string! sessionId, System.Collections.Generic.IReadOnlyDictionary<string!, string!>? partitions = null) -> void

‎dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/net8.0/PublicAPI.Unshipped.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[MAAI001]virtual Microsoft.Agents.AI.AgentSessionStore.GetService(System.Type! serviceType, object? serviceKey = null) -> object?
66
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.GetSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<Microsoft.Agents.AI.AgentSession?>
77
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.SaveSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, Microsoft.Agents.AI.AgentSession! session, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
8+
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.DeleteSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
89
[MAAI001]virtual Microsoft.Agents.AI.AgentSessionStore.GetOrCreateSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<Microsoft.Agents.AI.AgentSession!>
910
[MAAI001]Microsoft.Agents.AI.AgentSessionStoreKey
1011
[MAAI001]Microsoft.Agents.AI.AgentSessionStoreKey.AgentSessionStoreKey(string! sessionId, System.Collections.Generic.IReadOnlyDictionary<string!, string!>? partitions = null) -> void

‎dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/net9.0/PublicAPI.Unshipped.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[MAAI001]virtual Microsoft.Agents.AI.AgentSessionStore.GetService(System.Type! serviceType, object? serviceKey = null) -> object?
66
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.GetSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<Microsoft.Agents.AI.AgentSession?>
77
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.SaveSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, Microsoft.Agents.AI.AgentSession! session, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
8+
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.DeleteSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
89
[MAAI001]virtual Microsoft.Agents.AI.AgentSessionStore.GetOrCreateSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<Microsoft.Agents.AI.AgentSession!>
910
[MAAI001]Microsoft.Agents.AI.AgentSessionStoreKey
1011
[MAAI001]Microsoft.Agents.AI.AgentSessionStoreKey.AgentSessionStoreKey(string! sessionId, System.Collections.Generic.IReadOnlyDictionary<string!, string!>? partitions = null) -> void

‎dotnet/src/Microsoft.Agents.AI.Abstractions/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[MAAI001]virtual Microsoft.Agents.AI.AgentSessionStore.GetService(System.Type! serviceType, object? serviceKey = null) -> object?
66
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.GetSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<Microsoft.Agents.AI.AgentSession?>
77
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.SaveSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, Microsoft.Agents.AI.AgentSession! session, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
8+
[MAAI001]abstract Microsoft.Agents.AI.AgentSessionStore.DeleteSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
89
[MAAI001]virtual Microsoft.Agents.AI.AgentSessionStore.GetOrCreateSessionAsync(Microsoft.Agents.AI.AIAgent! agent, Microsoft.Agents.AI.AgentSessionStoreKey! key, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<Microsoft.Agents.AI.AgentSession!>
910
[MAAI001]Microsoft.Agents.AI.AgentSessionStoreKey
1011
[MAAI001]Microsoft.Agents.AI.AgentSessionStoreKey.AgentSessionStoreKey(string! sessionId, System.Collections.Generic.IReadOnlyDictionary<string!, string!>? partitions = null) -> void

0 commit comments

Comments
 (0)