Skip to content

Commit ac12442

Browse files
javiercnCopilot
andcommitted
.NET: Replace internal AG-UI implementation with external ag-ui packages
Remove the in-tree Microsoft.Agents.AI.AGUI sources and consume the external AG-UI .NET SDK packages (AGUI.Abstractions, AGUI.Formatting, AGUI.Protobuf, AGUI.Client, AGUI.Server) at 0.1.0-preview instead. - Microsoft.Agents.AI.Hosting.AGUI.AspNetCore keeps its own ASP.NET glue (MapAGUI / AddAGUI / SSE result) layered over the framework-agnostic AGUI.Server primitives (ToChatRequestContext / AsAGUIEventStreamAsync). - Migrate call sites to the options-based AGUIChatClient constructor and recover the originating AG-UI input via ChatOptions.TryGetRunAgentInput. - Multi-turn continuation flows through parentRunId + threadId on RawRepresentationFactory; shared state flows through RunAgentInput.State and is surfaced as StateSnapshotEvent raw representations. - Update samples, hosting/unit/integration tests, and central package versions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 098e521 commit ac12442

102 files changed

Lines changed: 515 additions & 10333 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.

dotnet/Directory.Packages.props

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project>
1+
<Project>
22
<PropertyGroup>
33
<!-- Enable central package management -->
44
<!-- https://learn.microsoft.com/en-us/nuget/consume-packages/Central-Package-Management -->
@@ -52,7 +52,13 @@
5252
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="10.0.8" />
5353
<PackageVersion Include="System.Linq.AsyncEnumerable" Version="10.0.5" />
5454
<PackageVersion Include="System.Net.Http.Json" Version="10.0.0" />
55-
<PackageVersion Include="System.Net.ServerSentEvents" Version="10.0.5" />
55+
<PackageVersion Include="System.Net.ServerSentEvents" Version="10.0.8" />
56+
<!-- AG-UI .NET SDK packages (published by the AG-UI team). -->
57+
<PackageVersion Include="AGUI.Abstractions" Version="0.1.0-preview" />
58+
<PackageVersion Include="AGUI.Formatting" Version="0.1.0-preview" />
59+
<PackageVersion Include="AGUI.Protobuf" Version="0.1.0-preview" />
60+
<PackageVersion Include="AGUI.Client" Version="0.1.0-preview" />
61+
<PackageVersion Include="AGUI.Server" Version="0.1.0-preview" />
5662
<PackageVersion Include="System.Text.Json" Version="10.0.8" />
5763
<PackageVersion Include="System.Threading.Channels" Version="10.0.8" />
5864
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.3" />
@@ -88,7 +94,7 @@
8894
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.1" />
8995
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.1" />
9096
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.8" />
91-
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="10.0.6" />
97+
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="10.0.8" />
9298
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.1" />
9399
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="10.0.0" />
94100
<PackageVersion Include="Microsoft.Extensions.Logging" Version="10.0.1" />

dotnet/agent-framework-dotnet.slnx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,6 @@
600600
<Project Path="src/Aspire.Hosting.AgentFramework.DevUI/Aspire.Hosting.AgentFramework.DevUI.csproj" />
601601
<Project Path="src/Microsoft.Agents.AI.A2A/Microsoft.Agents.AI.A2A.csproj" />
602602
<Project Path="src/Microsoft.Agents.AI.Abstractions/Microsoft.Agents.AI.Abstractions.csproj" />
603-
<Project Path="src/Microsoft.Agents.AI.AGUI/Microsoft.Agents.AI.AGUI.csproj" />
604603
<Project Path="src/Microsoft.Agents.AI.Anthropic/Microsoft.Agents.AI.Anthropic.csproj" />
605604
<Project Path="src/Microsoft.Agents.AI.AzureAI.Persistent/Microsoft.Agents.AI.AzureAI.Persistent.csproj" />
606605
<Project Path="src/Microsoft.Agents.AI.CopilotStudio/Microsoft.Agents.AI.CopilotStudio.csproj" />
@@ -659,7 +658,6 @@
659658
<Project Path="tests/Aspire.Hosting.AgentFramework.DevUI.UnitTests/Aspire.Hosting.AgentFramework.DevUI.UnitTests.csproj" />
660659
<Project Path="tests/Microsoft.Agents.AI.A2A.UnitTests/Microsoft.Agents.AI.A2A.UnitTests.csproj" />
661660
<Project Path="tests/Microsoft.Agents.AI.Abstractions.UnitTests/Microsoft.Agents.AI.Abstractions.UnitTests.csproj" />
662-
<Project Path="tests/Microsoft.Agents.AI.AGUI.UnitTests/Microsoft.Agents.AI.AGUI.UnitTests.csproj" />
663661
<Project Path="tests/Microsoft.Agents.AI.Anthropic.UnitTests/Microsoft.Agents.AI.Anthropic.UnitTests.csproj" />
664662
<Project Path="tests/Microsoft.Agents.AI.AzureAI.Persistent.UnitTests/Microsoft.Agents.AI.AzureAI.Persistent.UnitTests.csproj" />
665663
<Project Path="tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/Microsoft.Agents.AI.CosmosNoSql.UnitTests.csproj" />

dotnet/agent-framework-release.slnf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"projects": [
55
"src\\Microsoft.Agents.AI.A2A\\Microsoft.Agents.AI.A2A.csproj",
66
"src\\Microsoft.Agents.AI.Abstractions\\Microsoft.Agents.AI.Abstractions.csproj",
7-
"src\\Microsoft.Agents.AI.AGUI\\Microsoft.Agents.AI.AGUI.csproj",
87
"src\\Microsoft.Agents.AI.Anthropic\\Microsoft.Agents.AI.Anthropic.csproj",
98
"src\\Microsoft.Agents.AI.GitHub.Copilot\\Microsoft.Agents.AI.GitHub.Copilot.csproj",
109
"src\\Microsoft.Agents.AI.Harness\\Microsoft.Agents.AI.Harness.csproj",

dotnet/samples/02-agents/AGUI/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ A basic AG-UI server and client that demonstrate the foundational concepts.
3535
A basic AG-UI server that hosts an AI agent accessible via HTTP. Demonstrates:
3636

3737
- Creating an ASP.NET Core web application
38-
- Setting up an AG-UI server endpoint with `MapAGUI`
38+
- Setting up an AG-UI server endpoint with `MapAGUIServer`
3939
- Creating an AI agent from an Azure OpenAI chat client
4040
- Streaming responses via Server-Sent Events (SSE)
4141

@@ -204,7 +204,7 @@ dotnet run
204204
### Server-Side
205205

206206
1. Client sends HTTP POST request with messages
207-
2. ASP.NET Core endpoint receives the request via `MapAGUI`
207+
2. ASP.NET Core endpoint receives the request via `MapAGUIServer`
208208
3. Agent processes messages using Agent Framework
209209
4. Responses are streamed back as Server-Sent Events (SSE)
210210

@@ -214,14 +214,14 @@ dotnet run
214214
2. Server responds with SSE stream
215215
3. Client parses events into `AgentResponseUpdate` objects
216216
4. Updates are displayed based on content type
217-
5. `ConversationId` maintains conversation context
217+
5. The client sends the full message history each turn (the stateless AG-UI client does not rely on a server-assigned `ConversationId`)
218218

219219
### Protocol Features
220220

221221
- **HTTP POST** for requests
222222
- **Server-Sent Events (SSE)** for streaming responses
223223
- **JSON** for event serialization
224-
- **Thread IDs** (as `ConversationId`) for conversation context
224+
- **Thread IDs** (read from the `RUN_STARTED` event's raw representation) for conversation context. `AGUIChatClient` is stateless and intentionally does not surface a `ConversationId`.
225225
- **Run IDs** (as `ResponseId`) for tracking individual executions
226226

227227
## Troubleshooting

dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Client/Client.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -9,7 +9,7 @@
99

1010
<ItemGroup>
1111
<ProjectReference Include="..\..\..\..\..\src\Microsoft.Agents.AI\Microsoft.Agents.AI.csproj" />
12-
<ProjectReference Include="..\..\..\..\..\src\Microsoft.Agents.AI.AGUI\Microsoft.Agents.AI.AGUI.csproj" />
12+
<PackageReference Include="AGUI.Client" />
1313
</ItemGroup>
1414

1515
</Project>

dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Client/Program.cs

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

3+
using AGUI.Abstractions;
4+
using AGUI.Client;
35
using Microsoft.Agents.AI;
4-
using Microsoft.Agents.AI.AGUI;
56
using Microsoft.Extensions.AI;
67

78
string serverUrl = Environment.GetEnvironmentVariable("AGUI_SERVER_URL") ?? "http://localhost:8888";
@@ -14,7 +15,7 @@
1415
Timeout = TimeSpan.FromSeconds(60)
1516
};
1617

17-
AGUIChatClient chatClient = new(httpClient, serverUrl);
18+
AGUIChatClient chatClient = new(new(httpClient, serverUrl));
1819

1920
AIAgent agent = chatClient.AsAIAgent(
2021
name: "agui-client",
@@ -49,7 +50,7 @@
4950

5051
// Stream the response
5152
bool isFirstUpdate = true;
52-
string? sessionId = null;
53+
string? threadId = null;
5354

5455
await foreach (AgentResponseUpdate update in agent.RunStreamingAsync(messages, session))
5556
{
@@ -58,9 +59,11 @@
5859
// First update indicates run started
5960
if (isFirstUpdate)
6061
{
61-
sessionId = chatUpdate.ConversationId;
62+
// AGUIChatClient is stateless and never surfaces a ConversationId; the thread
63+
// id is carried on the AG-UI RUN_STARTED event's raw representation.
64+
threadId = (chatUpdate.RawRepresentation as RunStartedEvent)?.ThreadId;
6265
Console.ForegroundColor = ConsoleColor.Yellow;
63-
Console.WriteLine($"\n[Run Started - Session: {chatUpdate.ConversationId}, Run: {chatUpdate.ResponseId}]");
66+
Console.WriteLine($"\n[Run Started - Thread: {threadId}, Run: {chatUpdate.ResponseId}]");
6467
Console.ResetColor();
6568
isFirstUpdate = false;
6669
}
@@ -84,7 +87,7 @@
8487
}
8588

8689
Console.ForegroundColor = ConsoleColor.Green;
87-
Console.WriteLine($"\n[Run Finished - Session: {sessionId}]");
90+
Console.WriteLine($"\n[Run Finished - Thread: {threadId}]");
8891
Console.ResetColor();
8992
}
9093
}

dotnet/samples/02-agents/AGUI/Step01_GettingStarted/Server/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft. All rights reserved.
1+
// Copyright (c) Microsoft. All rights reserved.
22

33
using Azure.AI.OpenAI;
44
using Azure.Identity;
@@ -8,7 +8,7 @@
88

99
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
1010
builder.Services.AddHttpClient().AddLogging();
11-
builder.Services.AddAGUI();
11+
builder.Services.AddAGUIServer();
1212

1313
// WARNING: When adding session persistence (e.g., WithInMemorySessionStore), or running in production,
1414
// make sure to also register a SessionIsolationKeyProvider to scope sessions by principal in multi-user
@@ -36,6 +36,6 @@
3636
instructions: "You are a helpful assistant.");
3737

3838
// Map the AG-UI agent endpoint
39-
app.MapAGUI("/", agent);
39+
app.MapAGUIServer("/", agent);
4040

4141
await app.RunAsync();

dotnet/samples/02-agents/AGUI/Step02_BackendTools/Client/Client.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -9,7 +9,7 @@
99

1010
<ItemGroup>
1111
<ProjectReference Include="..\..\..\..\..\src\Microsoft.Agents.AI\Microsoft.Agents.AI.csproj" />
12-
<ProjectReference Include="..\..\..\..\..\src\Microsoft.Agents.AI.AGUI\Microsoft.Agents.AI.AGUI.csproj" />
12+
<PackageReference Include="AGUI.Client" />
1313
</ItemGroup>
1414

1515
</Project>

dotnet/samples/02-agents/AGUI/Step02_BackendTools/Client/Program.cs

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

3+
using AGUI.Abstractions;
4+
using AGUI.Client;
35
using Microsoft.Agents.AI;
4-
using Microsoft.Agents.AI.AGUI;
56
using Microsoft.Extensions.AI;
67

78
string serverUrl = Environment.GetEnvironmentVariable("AGUI_SERVER_URL") ?? "http://localhost:8888";
@@ -14,7 +15,7 @@
1415
Timeout = TimeSpan.FromSeconds(60)
1516
};
1617

17-
AGUIChatClient chatClient = new(httpClient, serverUrl);
18+
AGUIChatClient chatClient = new(new(httpClient, serverUrl));
1819

1920
AIAgent agent = chatClient.AsAIAgent(
2021
name: "agui-client",
@@ -49,7 +50,7 @@
4950

5051
// Stream the response
5152
bool isFirstUpdate = true;
52-
string? sessionId = null;
53+
string? threadId = null;
5354

5455
await foreach (AgentResponseUpdate update in agent.RunStreamingAsync(messages, session))
5556
{
@@ -58,9 +59,11 @@
5859
// First update indicates run started
5960
if (isFirstUpdate)
6061
{
61-
sessionId = chatUpdate.ConversationId;
62+
// AGUIChatClient is stateless and never surfaces a ConversationId; the thread
63+
// id is carried on the AG-UI RUN_STARTED event's raw representation.
64+
threadId = (chatUpdate.RawRepresentation as RunStartedEvent)?.ThreadId;
6265
Console.ForegroundColor = ConsoleColor.Yellow;
63-
Console.WriteLine($"\n[Run Started - Session: {chatUpdate.ConversationId}, Run: {chatUpdate.ResponseId}]");
66+
Console.WriteLine($"\n[Run Started - Thread: {threadId}, Run: {chatUpdate.ResponseId}]");
6467
Console.ResetColor();
6568
isFirstUpdate = false;
6669
}
@@ -116,7 +119,7 @@
116119
}
117120

118121
Console.ForegroundColor = ConsoleColor.Green;
119-
Console.WriteLine($"\n[Run Finished - Session: {sessionId}]");
122+
Console.WriteLine($"\n[Run Finished - Thread: {threadId}]");
120123
Console.ResetColor();
121124
}
122125
}

dotnet/samples/02-agents/AGUI/Step02_BackendTools/Server/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft. All rights reserved.
1+
// Copyright (c) Microsoft. All rights reserved.
22

33
using System.ComponentModel;
44
using System.Text.Json.Serialization;
@@ -14,7 +14,7 @@
1414
builder.Services.AddHttpClient().AddLogging();
1515
builder.Services.ConfigureHttpJsonOptions(options =>
1616
options.SerializerOptions.TypeInfoResolverChain.Add(SampleJsonSerializerContext.Default));
17-
builder.Services.AddAGUI();
17+
builder.Services.AddAGUIServer();
1818

1919
// WARNING: When adding session persistence (e.g., WithInMemorySessionStore), or running in production,
2020
// make sure to also register a SessionIsolationKeyProvider to scope sessions by principal in multi-user
@@ -93,7 +93,7 @@ static RestaurantSearchResponse SearchRestaurants(
9393
tools: tools);
9494

9595
// Map the AG-UI agent endpoint
96-
app.MapAGUI("/", agent);
96+
app.MapAGUIServer("/", agent);
9797

9898
await app.RunAsync();
9999

0 commit comments

Comments
 (0)