Skip to content

Commit 701174c

Browse files
authored
Merge pull request #5 from duttastunil/main
Sync with the main branch after main rebase
2 parents fce8cc9 + 37b4cfd commit 701174c

209 files changed

Lines changed: 14114 additions & 6685 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.

.github/upgrades/prompts/SemanticKernelToAgentFramework.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ var agentOptions = new ChatClientAgentRunOptions(new ChatOptions
839839
{
840840
MaxOutputTokens = 8000,
841841
// Breaking glass to access provider-specific options
842-
RawRepresentationFactory = (_) => new OpenAI.Responses.ResponseCreationOptions()
842+
RawRepresentationFactory = (_) => new OpenAI.Responses.CreateResponseOptions()
843843
{
844844
ReasoningOptions = new()
845845
{

.github/workflows/dotnet-build-and-test.yml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ jobs:
3535
contents: read
3636
pull-requests: read
3737
outputs:
38-
dotnetChanges: ${{ steps.filter.outputs.dotnet}}
38+
dotnetChanges: ${{ steps.filter.outputs.dotnet }}
39+
cosmosDbChanges: ${{ steps.filter.outputs.cosmosdb }}
3940
steps:
4041
- uses: actions/checkout@v6
4142
- uses: dorny/paths-filter@v3
@@ -44,10 +45,15 @@ jobs:
4445
filters: |
4546
dotnet:
4647
- 'dotnet/**'
48+
cosmosdb:
49+
- 'dotnet/src/Microsoft.Agents.AI.CosmosNoSql/**'
4750
# run only if 'dotnet' files were changed
4851
- name: dotnet tests
4952
if: steps.filter.outputs.dotnet == 'true'
5053
run: echo "Dotnet file"
54+
- name: dotnet CosmosDB tests
55+
if: steps.filter.outputs.cosmosdb == 'true'
56+
run: echo "Dotnet CosmosDB changes"
5157
# run only if not 'dotnet' files were changed
5258
- name: not dotnet tests
5359
if: steps.filter.outputs.dotnet != 'true'
@@ -77,6 +83,16 @@ jobs:
7783
dotnet
7884
python
7985
workflow-samples
86+
87+
# Start Cosmos DB Emulator for all integration tests and only for unit tests when CosmosDB changes happened)
88+
- name: Start Azure Cosmos DB Emulator
89+
if: ${{ runner.os == 'Windows' && (needs.paths-filter.outputs.cosmosDbChanges == 'true' || (github.event_name != 'pull_request' && matrix.integration-tests)) }}
90+
shell: pwsh
91+
run: |
92+
Write-Host "Launching Azure Cosmos DB Emulator"
93+
Import-Module "$env:ProgramFiles\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator"
94+
Start-CosmosDbEmulator -NoUI -Key "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
95+
echo "COSMOS_EMULATOR_AVAILABLE=true" >> $env:GITHUB_ENV
8096
8197
- name: Setup dotnet
8298
uses: actions/[email protected]
@@ -123,17 +139,7 @@ jobs:
123139
popd
124140
popd
125141
rm -rf "$TEMP_DIR"
126-
127-
# Start Cosmos DB Emulator for Cosmos-based unit tests (only on Windows)
128-
- name: Start Azure Cosmos DB Emulator
129-
if: runner.os == 'Windows'
130-
shell: pwsh
131-
run: |
132-
Write-Host "Launching Azure Cosmos DB Emulator"
133-
Import-Module "$env:ProgramFiles\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator"
134-
Start-CosmosDbEmulator -NoUI -Key "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
135-
echo "COSMOS_EMULATOR_AVAILABLE=true" >> $env:GITHUB_ENV
136-
142+
137143
- name: Run Unit Tests
138144
shell: bash
139145
run: |
@@ -225,7 +231,7 @@ jobs:
225231

226232
- name: Upload coverage report artifact
227233
if: matrix.targetFramework == env.COVERAGE_FRAMEWORK
228-
uses: actions/upload-artifact@v5
234+
uses: actions/upload-artifact@v6
229235
with:
230236
name: CoverageReport-${{ matrix.os }}-${{ matrix.targetFramework }}-${{ matrix.configuration }} # Artifact name
231237
path: ./TestResults/Reports # Directory containing files to upload

.github/workflows/python-code-quality.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
env:
4040
# Configure a constant location for the uv cache
4141
UV_CACHE_DIR: /tmp/.uv-cache
42-
- uses: actions/cache@v4
42+
- uses: actions/cache@v5
4343
with:
4444
path: ~/.cache/pre-commit
4545
key: pre-commit|${{ matrix.python-version }}|${{ hashFiles('python/.pre-commit-config.yaml') }}

.github/workflows/python-test-coverage-report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v6
2323
- name: Download coverage report
24-
uses: actions/download-artifact@v6
24+
uses: actions/download-artifact@v7
2525
with:
2626
github-token: ${{ secrets.GH_ACTIONS_PR_WRITE }}
2727
run-id: ${{ github.event.workflow_run.id }}

.github/workflows/python-test-coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Run all tests with coverage report
3939
run: uv run poe all-tests-cov --cov-report=xml:python-coverage.xml -q --junitxml=pytest.xml
4040
- name: Upload coverage report
41-
uses: actions/upload-artifact@v5
41+
uses: actions/upload-artifact@v6
4242
with:
4343
path: |
4444
python/python-coverage.xml
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Time-To-Live (TTL) for durable agent sessions
2+
3+
## Overview
4+
5+
The durable agents automatically maintain conversation history and state for each session. Without automatic cleanup, this state can accumulate indefinitely, consuming storage resources and increasing costs. The Time-To-Live (TTL) feature provides automatic cleanup of idle agent sessions, ensuring that sessions are automatically deleted after a period of inactivity.
6+
7+
## What is TTL?
8+
9+
Time-To-Live (TTL) is a configurable duration that determines how long an agent session state will be retained after its last interaction. When an agent session is idle (no messages sent to it) for longer than the TTL period, the session state is automatically deleted. Each new interaction with an agent resets the TTL timer, extending the session's lifetime.
10+
11+
## Benefits
12+
13+
- **Automatic cleanup**: No manual intervention required to clean up idle agent sessions
14+
- **Cost optimization**: Reduces storage costs by automatically removing unused session state
15+
- **Resource management**: Prevents unbounded growth of agent session state in storage
16+
- **Configurable**: Set TTL globally or per-agent type to match your application's needs
17+
18+
## Configuration
19+
20+
TTL can be configured at two levels:
21+
22+
1. **Global default TTL**: Applies to all agent sessions unless overridden
23+
2. **Per-agent type TTL**: Overrides the global default for specific agent types
24+
25+
Additionally, you can configure a **minimum deletion delay** that controls how frequently deletion operations are scheduled. The default value is 5 minutes, and the maximum allowed value is also 5 minutes.
26+
27+
> [!NOTE]
28+
> Reducing the minimum deletion delay below 5 minutes can be useful for testing or for ensuring rapid cleanup of short-lived agent sessions. However, this can also increase the load on the system and should be used with caution.
29+
30+
### Default values
31+
32+
- **Default TTL**: 14 days
33+
- **Minimum TTL deletion delay**: 5 minutes (maximum allowed value, subject to change in future releases)
34+
35+
### Configuration examples
36+
37+
#### .NET
38+
39+
```csharp
40+
// Configure global default TTL and minimum signal delay
41+
services.ConfigureDurableAgents(
42+
options =>
43+
{
44+
// Set global default TTL to 7 days
45+
options.DefaultTimeToLive = TimeSpan.FromDays(7);
46+
47+
// Add agents (will use global default TTL)
48+
options.AddAIAgent(myAgent);
49+
});
50+
51+
// Configure per-agent TTL
52+
services.ConfigureDurableAgents(
53+
options =>
54+
{
55+
options.DefaultTimeToLive = TimeSpan.FromDays(14); // Global default
56+
57+
// Agent with custom TTL of 1 day
58+
options.AddAIAgent(shortLivedAgent, timeToLive: TimeSpan.FromDays(1));
59+
60+
// Agent with custom TTL of 90 days
61+
options.AddAIAgent(longLivedAgent, timeToLive: TimeSpan.FromDays(90));
62+
63+
// Agent using global default (14 days)
64+
options.AddAIAgent(defaultAgent);
65+
});
66+
67+
// Disable TTL for specific agents by setting TTL to null
68+
services.ConfigureDurableAgents(
69+
options =>
70+
{
71+
options.DefaultTimeToLive = TimeSpan.FromDays(14);
72+
73+
// Agent with no TTL (never expires)
74+
options.AddAIAgent(permanentAgent, timeToLive: null);
75+
});
76+
```
77+
78+
## How TTL works
79+
80+
The following sections describe how TTL works in detail.
81+
82+
### Expiration tracking
83+
84+
Each agent session maintains an expiration timestamp in its internally managed state that is updated whenever the session processes a message:
85+
86+
1. When a message is sent to an agent session, the expiration time is set to `current time + TTL`
87+
2. The runtime schedules a delete operation for the expiration time (subject to minimum delay constraints)
88+
3. When the delete operation runs, if the current time is past the expiration time, the session state is deleted. Otherwise, the delete operation is rescheduled for the next expiration time.
89+
90+
### State deletion
91+
92+
When an agent session expires, its entire state is deleted, including:
93+
94+
- Conversation history
95+
- Any custom state data
96+
- Expiration timestamps
97+
98+
After deletion, if a message is sent to the same agent session, a new session is created with a fresh conversation history.
99+
100+
## Behavior examples
101+
102+
The following examples illustrate how TTL works in different scenarios.
103+
104+
### Example 1: Agent session expires after TTL
105+
106+
1. Agent configured with 30-day TTL
107+
2. User sends message at Day 0 → agent session created, expiration set to Day 30
108+
3. No further messages sent
109+
4. At Day 30 → Agent session is deleted
110+
5. User sends message at Day 31 → New agent session created with fresh conversation history
111+
112+
### Example 2: TTL reset on interaction
113+
114+
1. Agent configured with 30-day TTL
115+
2. User sends message at Day 0 → agent session created, expiration set to Day 30
116+
3. User sends message at Day 15 → Expiration reset to Day 45
117+
4. User sends message at Day 40 → Expiration reset to Day 70
118+
5. Agent session remains active as long as there are regular interactions
119+
120+
## Logging
121+
122+
The TTL feature includes comprehensive logging to track state changes:
123+
124+
- **Expiration time updated**: Logged when TTL expiration time is set or updated
125+
- **Deletion scheduled**: Logged when a deletion check signal is scheduled
126+
- **Deletion check**: Logged when a deletion check operation runs
127+
- **Session expired**: Logged when an agent session is deleted due to expiration
128+
- **TTL rescheduled**: Logged when a deletion signal is rescheduled
129+
130+
These logs help monitor TTL behavior and troubleshoot any issues.
131+
132+
## Best practices
133+
134+
1. **Choose appropriate TTL values**: Balance between storage costs and user experience. Too short TTLs may delete active sessions, while too long TTLs may accumulate unnecessary state.
135+
136+
2. **Use per-agent TTLs**: Different agents may have different usage patterns. Configure TTLs per-agent based on expected session lifetimes.
137+
138+
3. **Monitor expiration logs**: Review logs to understand TTL behavior and adjust configuration as needed.
139+
140+
4. **Test with short TTLs**: During development, use short TTLs (e.g., minutes) to verify TTL behavior without waiting for long periods.
141+
142+
## Limitations
143+
144+
- TTL is based on wall-clock time, not activity time. The expiration timer starts from the last message timestamp.
145+
- Deletion checks are durably scheduled operations and may have slight delays depending on system load.
146+
- Once an agent session is deleted, its conversation history cannot be recovered.
147+
- TTL deletion requires at least one worker to be available to process the deletion operation message.

dotnet/.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ dotnet_diagnostic.CA2000.severity = none # Call System.IDisposable.Dispose on ob
209209
dotnet_diagnostic.CA2225.severity = none # Operator overloads have named alternates
210210
dotnet_diagnostic.CA2227.severity = none # Change to be read-only by removing the property setter
211211
dotnet_diagnostic.CA2249.severity = suggestion # Consider using 'Contains' method instead of 'IndexOf' method
212+
dotnet_diagnostic.CA2252.severity = none # Requires preview
212213
dotnet_diagnostic.CA2253.severity = none # Named placeholders in the logging message template should not be comprised of only numeric characters
213214
dotnet_diagnostic.CA2253.severity = none # Named placeholders in the logging message template should not be comprised of only numeric characters
214215
dotnet_diagnostic.CA2263.severity = suggestion # Use generic overload

dotnet/Directory.Packages.props

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
</PropertyGroup>
1212
<ItemGroup>
1313
<!-- Aspire.* -->
14-
<PackageVersion Include="Anthropic" Version="11.0.0" />
14+
<PackageVersion Include="Anthropic" Version="12.0.0" />
1515
<PackageVersion Include="Anthropic.Foundry" Version="0.1.0" />
1616
<PackageVersion Include="Aspire.Azure.AI.OpenAI" Version="13.0.0-preview.1.25560.3" />
1717
<PackageVersion Include="Aspire.Hosting.AppHost" Version="$(AspireAppHostSdkVersion)" />
1818
<PackageVersion Include="Aspire.Hosting.Azure.CognitiveServices" Version="$(AspireAppHostSdkVersion)" />
1919
<PackageVersion Include="Aspire.Microsoft.Azure.Cosmos" Version="$(AspireAppHostSdkVersion)" />
2020
<PackageVersion Include="CommunityToolkit.Aspire.OllamaSharp" Version="13.0.0-beta.440" />
2121
<!-- Azure.* -->
22-
<PackageVersion Include="Azure.AI.Projects" Version="1.2.0-beta.3" />
23-
<PackageVersion Include="Azure.AI.Projects.OpenAI" Version="1.0.0-beta.4" />
22+
<PackageVersion Include="Azure.AI.Projects" Version="1.2.0-beta.5" />
23+
<PackageVersion Include="Azure.AI.Projects.OpenAI" Version="1.0.0-beta.5" />
2424
<PackageVersion Include="Azure.AI.Agents.Persistent" Version="1.2.0-beta.8" />
25-
<PackageVersion Include="Azure.AI.OpenAI" Version="2.7.0-beta.2" />
25+
<PackageVersion Include="Azure.AI.OpenAI" Version="2.8.0-beta.1" />
2626
<PackageVersion Include="Azure.Identity" Version="1.17.1" />
2727
<PackageVersion Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.4.0" />
2828
<!-- Google Gemini -->
@@ -61,10 +61,9 @@
6161
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
6262
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.0.0" />
6363
<!-- Microsoft.Extensions.* -->
64-
<PackageVersion Include="Microsoft.Extensions.AI" Version="10.1.0" />
65-
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="10.1.0" />
66-
<PackageVersion Include="Microsoft.Extensions.AI.AzureAIInference" Version="10.0.0-preview.1.25559.3" />
67-
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="10.1.0-preview.1.25608.1" />
64+
<PackageVersion Include="Microsoft.Extensions.AI" Version="10.1.1" />
65+
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="10.1.1" />
66+
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="10.1.1-preview.1.25612.2" />
6867
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="10.0.0" />
6968
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="10.0.0" />
7069
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.0" />
@@ -101,11 +100,10 @@
101100
<!-- MCP -->
102101
<PackageVersion Include="ModelContextProtocol" Version="0.4.0-preview.3" />
103102
<!-- Inference SDKs -->
104-
<PackageVersion Include="Anthropic.SDK" Version="5.8.0" />
105103
<PackageVersion Include="AWSSDK.Extensions.Bedrock.MEAI" Version="4.0.4.11" />
106104
<PackageVersion Include="Microsoft.ML.OnnxRuntimeGenAI" Version="0.10.0" />
107105
<PackageVersion Include="OllamaSharp" Version="5.4.8" />
108-
<PackageVersion Include="OpenAI" Version="2.7.0" />
106+
<PackageVersion Include="OpenAI" Version="2.8.0" />
109107
<!-- Identity -->
110108
<PackageVersion Include="Microsoft.Identity.Client.Extensions.Msal" Version="4.78.0" />
111109
<!-- Workflows -->

dotnet/samples/AgentWebChat/AgentWebChat.AgentHost/AgentWebChat.AgentHost.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
<PackageReference Include="CommunityToolkit.Aspire.OllamaSharp" />
2626
<PackageReference Include="Microsoft.Extensions.AI" />
2727
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" />
28-
<PackageReference Include="Microsoft.Extensions.AI.AzureAIInference" />
2928
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
3029
<PackageReference Include="Microsoft.AspNetCore.OpenAPI" />
3130
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" />

dotnet/samples/AgentWebChat/AgentWebChat.AgentHost/Utilities/ChatClientExtensions.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

33
using AgentWebChat.AgentHost.Utilities;
4-
using Azure;
5-
using Azure.AI.Inference;
64
using Microsoft.Extensions.AI;
75
using OllamaSharp;
86

@@ -24,7 +22,6 @@ public static ChatClientBuilder AddChatClient(this IHostApplicationBuilder build
2422
ClientChatProvider.Ollama => builder.AddOllamaClient(connectionName, connectionInfo),
2523
ClientChatProvider.OpenAI => builder.AddOpenAIClient(connectionName, connectionInfo),
2624
ClientChatProvider.AzureOpenAI => builder.AddAzureOpenAIClient(connectionName).AddChatClient(connectionInfo.SelectedModel),
27-
ClientChatProvider.AzureAIInference => builder.AddAzureInferenceClient(connectionName, connectionInfo),
2825
_ => throw new NotSupportedException($"Unsupported provider: {connectionInfo.Provider}")
2926
};
3027

@@ -44,16 +41,6 @@ private static ChatClientBuilder AddOpenAIClient(this IHostApplicationBuilder bu
4441
})
4542
.AddChatClient(connectionInfo.SelectedModel);
4643

47-
private static ChatClientBuilder AddAzureInferenceClient(this IHostApplicationBuilder builder, string connectionName, ChatClientConnectionInfo connectionInfo) =>
48-
builder.Services.AddChatClient(sp =>
49-
{
50-
var credential = new AzureKeyCredential(connectionInfo.AccessKey!);
51-
52-
var client = new ChatCompletionsClient(connectionInfo.Endpoint, credential, new AzureAIInferenceClientOptions());
53-
54-
return client.AsIChatClient(connectionInfo.SelectedModel);
55-
});
56-
5744
private static ChatClientBuilder AddOllamaClient(this IHostApplicationBuilder builder, string connectionName, ChatClientConnectionInfo connectionInfo)
5845
{
5946
var httpKey = $"{connectionName}_http";
@@ -83,7 +70,6 @@ public static ChatClientBuilder AddKeyedChatClient(this IHostApplicationBuilder
8370
ClientChatProvider.Ollama => builder.AddKeyedOllamaClient(connectionName, connectionInfo),
8471
ClientChatProvider.OpenAI => builder.AddKeyedOpenAIClient(connectionName, connectionInfo),
8572
ClientChatProvider.AzureOpenAI => builder.AddKeyedAzureOpenAIClient(connectionName).AddKeyedChatClient(connectionName, connectionInfo.SelectedModel),
86-
ClientChatProvider.AzureAIInference => builder.AddKeyedAzureInferenceClient(connectionName, connectionInfo),
8773
_ => throw new NotSupportedException($"Unsupported provider: {connectionInfo.Provider}")
8874
};
8975

@@ -103,16 +89,6 @@ private static ChatClientBuilder AddKeyedOpenAIClient(this IHostApplicationBuild
10389
})
10490
.AddKeyedChatClient(connectionName, connectionInfo.SelectedModel);
10591

106-
private static ChatClientBuilder AddKeyedAzureInferenceClient(this IHostApplicationBuilder builder, string connectionName, ChatClientConnectionInfo connectionInfo) =>
107-
builder.Services.AddKeyedChatClient(connectionName, sp =>
108-
{
109-
var credential = new AzureKeyCredential(connectionInfo.AccessKey!);
110-
111-
var client = new ChatCompletionsClient(connectionInfo.Endpoint, credential, new AzureAIInferenceClientOptions());
112-
113-
return client.AsIChatClient(connectionInfo.SelectedModel);
114-
});
115-
11692
private static ChatClientBuilder AddKeyedOllamaClient(this IHostApplicationBuilder builder, string connectionName, ChatClientConnectionInfo connectionInfo)
11793
{
11894
var httpKey = $"{connectionName}_http";

0 commit comments

Comments
 (0)