-
Notifications
You must be signed in to change notification settings - Fork 1k
.NET: AG-UI Docs samples #2194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
javiercn
merged 10 commits into
microsoft:main
from
javiercn:javiercn/agent-framework-samples
Dec 8, 2025
Merged
.NET: AG-UI Docs samples #2194
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
077663a
Add AG-UI Blazor sample
javiercn f042009
Add AG-UI getting started samples
javiercn 6f924aa
Cleanups
javiercn beabff3
Update the dojo samples
javiercn 660dee8
cleanups
javiercn 2f620cd
Fix readme
javiercn 05f9392
Address feedback and further cleanups
javiercn f50fd34
Merge remote-tracking branch 'origin/main' into javiercn/agent-framew…
javiercn a909268
Fix build
javiercn 515881b
Missing fixes
javiercn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
dotnet/samples/AGUIClientServer/AGUIDojoServer/AGUIDojoServerSerializerContext.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,23 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
| using AGUIDojoServer.AgenticUI; | ||
| using AGUIDojoServer.BackendToolRendering; | ||
| using AGUIDojoServer.PredictiveStateUpdates; | ||
| using AGUIDojoServer.SharedState; | ||
|
|
||
| namespace AGUIDojoServer; | ||
|
|
||
| [JsonSerializable(typeof(WeatherInfo))] | ||
| [JsonSerializable(typeof(Recipe))] | ||
| [JsonSerializable(typeof(Ingredient))] | ||
| [JsonSerializable(typeof(RecipeResponse))] | ||
| [JsonSerializable(typeof(Plan))] | ||
| [JsonSerializable(typeof(Step))] | ||
| [JsonSerializable(typeof(StepStatus))] | ||
| [JsonSerializable(typeof(StepStatus?))] | ||
| [JsonSerializable(typeof(JsonPatchOperation))] | ||
| [JsonSerializable(typeof(List<JsonPatchOperation>))] | ||
| [JsonSerializable(typeof(List<string>))] | ||
| [JsonSerializable(typeof(DocumentState))] | ||
| internal sealed partial class AGUIDojoServerSerializerContext : JsonSerializerContext; |
52 changes: 52 additions & 0 deletions
52
dotnet/samples/AGUIClientServer/AGUIDojoServer/AgenticUI/AgenticPlanningTools.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.ComponentModel; | ||
|
|
||
| namespace AGUIDojoServer.AgenticUI; | ||
|
|
||
| internal static class AgenticPlanningTools | ||
| { | ||
| [Description("Create a plan with multiple steps.")] | ||
| public static Plan CreatePlan([Description("List of step descriptions to create the plan.")] List<string> steps) | ||
| { | ||
| return new Plan | ||
| { | ||
| Steps = [.. steps.Select(s => new Step { Description = s, Status = StepStatus.Pending })] | ||
| }; | ||
| } | ||
|
|
||
| [Description("Update a step in the plan with new description or status.")] | ||
| public static async Task<List<JsonPatchOperation>> UpdatePlanStepAsync( | ||
| [Description("The index of the step to update.")] int index, | ||
| [Description("The new description for the step (optional).")] string? description = null, | ||
| [Description("The new status for the step (optional).")] StepStatus? status = null) | ||
| { | ||
| var changes = new List<JsonPatchOperation>(); | ||
|
|
||
| if (description is not null) | ||
| { | ||
| changes.Add(new JsonPatchOperation | ||
| { | ||
| Op = "replace", | ||
| Path = $"/steps/{index}/description", | ||
| Value = description | ||
| }); | ||
| } | ||
|
|
||
| if (status.HasValue) | ||
| { | ||
| // Status must be lowercase to match AG-UI frontend expectations: "pending" or "completed" | ||
| string statusValue = status.Value == StepStatus.Pending ? "pending" : "completed"; | ||
| changes.Add(new JsonPatchOperation | ||
| { | ||
| Op = "replace", | ||
| Path = $"/steps/{index}/status", | ||
| Value = statusValue | ||
| }); | ||
| } | ||
|
|
||
| await Task.Delay(1000); | ||
|
|
||
| return changes; | ||
| } | ||
| } |
88 changes: 88 additions & 0 deletions
88
dotnet/samples/AGUIClientServer/AGUIDojoServer/AgenticUI/AgenticUIAgent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Text.Json; | ||
| using Microsoft.Agents.AI; | ||
| using Microsoft.Extensions.AI; | ||
|
|
||
| namespace AGUIDojoServer.AgenticUI; | ||
|
|
||
| [SuppressMessage("Performance", "CA1812:Avoid uninstantiated internal classes", Justification = "Instantiated by ChatClientAgentFactory.CreateAgenticUI")] | ||
| internal sealed class AgenticUIAgent : DelegatingAIAgent | ||
| { | ||
| private readonly JsonSerializerOptions _jsonSerializerOptions; | ||
|
|
||
| public AgenticUIAgent(AIAgent innerAgent, JsonSerializerOptions jsonSerializerOptions) | ||
| : base(innerAgent) | ||
| { | ||
| this._jsonSerializerOptions = jsonSerializerOptions; | ||
| } | ||
|
|
||
| public override Task<AgentRunResponse> RunAsync(IEnumerable<ChatMessage> messages, AgentThread? thread = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default) | ||
| { | ||
| return this.RunStreamingAsync(messages, thread, options, cancellationToken).ToAgentRunResponseAsync(cancellationToken); | ||
| } | ||
|
|
||
| public override async IAsyncEnumerable<AgentRunResponseUpdate> RunStreamingAsync( | ||
| IEnumerable<ChatMessage> messages, | ||
| AgentThread? thread = null, | ||
| AgentRunOptions? options = null, | ||
| [EnumeratorCancellation] CancellationToken cancellationToken = default) | ||
| { | ||
| // Track function calls that should trigger state events | ||
| var trackedFunctionCalls = new Dictionary<string, FunctionCallContent>(); | ||
|
|
||
| await foreach (var update in this.InnerAgent.RunStreamingAsync(messages, thread, options, cancellationToken).ConfigureAwait(false)) | ||
| { | ||
| // Process contents: track function calls and emit state events for results | ||
| List<AIContent> stateEventsToEmit = new(); | ||
| foreach (var content in update.Contents) | ||
| { | ||
| if (content is FunctionCallContent callContent) | ||
| { | ||
| if (callContent.Name == "create_plan" || callContent.Name == "update_plan_step") | ||
| { | ||
| trackedFunctionCalls[callContent.CallId] = callContent; | ||
| break; | ||
| } | ||
| } | ||
| else if (content is FunctionResultContent resultContent) | ||
| { | ||
| // Check if this result matches a tracked function call | ||
| if (trackedFunctionCalls.TryGetValue(resultContent.CallId, out var matchedCall)) | ||
| { | ||
| var bytes = JsonSerializer.SerializeToUtf8Bytes((JsonElement)resultContent.Result!, this._jsonSerializerOptions); | ||
|
|
||
| // Determine event type based on the function name | ||
| if (matchedCall.Name == "create_plan") | ||
| { | ||
| stateEventsToEmit.Add(new DataContent(bytes, "application/json")); | ||
| } | ||
| else if (matchedCall.Name == "update_plan_step") | ||
| { | ||
| stateEventsToEmit.Add(new DataContent(bytes, "application/json-patch+json")); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| yield return update; | ||
|
|
||
| yield return new AgentRunResponseUpdate( | ||
| new ChatResponseUpdate(role: ChatRole.System, stateEventsToEmit) | ||
| { | ||
| MessageId = "delta_" + Guid.NewGuid().ToString("N"), | ||
| CreatedAt = update.CreatedAt, | ||
| ResponseId = update.ResponseId, | ||
| AuthorName = update.AuthorName, | ||
| Role = update.Role, | ||
| ContinuationToken = update.ContinuationToken, | ||
| AdditionalProperties = update.AdditionalProperties, | ||
| }) | ||
| { | ||
| AgentId = update.AgentId | ||
| }; | ||
| } | ||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
dotnet/samples/AGUIClientServer/AGUIDojoServer/AgenticUI/JsonPatchOperation.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace AGUIDojoServer.AgenticUI; | ||
|
|
||
| internal sealed class JsonPatchOperation | ||
| { | ||
| [JsonPropertyName("op")] | ||
| public required string Op { get; set; } | ||
|
|
||
| [JsonPropertyName("path")] | ||
| public required string Path { get; set; } | ||
|
|
||
| [JsonPropertyName("value")] | ||
| public object? Value { get; set; } | ||
|
|
||
| [JsonPropertyName("from")] | ||
| public string? From { get; set; } | ||
| } |
11 changes: 11 additions & 0 deletions
11
dotnet/samples/AGUIClientServer/AGUIDojoServer/AgenticUI/Plan.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace AGUIDojoServer.AgenticUI; | ||
|
|
||
| internal sealed class Plan | ||
| { | ||
| [JsonPropertyName("steps")] | ||
| public List<Step> Steps { get; set; } = []; | ||
| } |
14 changes: 14 additions & 0 deletions
14
dotnet/samples/AGUIClientServer/AGUIDojoServer/AgenticUI/Step.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace AGUIDojoServer.AgenticUI; | ||
|
|
||
| internal sealed class Step | ||
| { | ||
| [JsonPropertyName("description")] | ||
| public required string Description { get; set; } | ||
|
|
||
| [JsonPropertyName("status")] | ||
| public StepStatus Status { get; set; } = StepStatus.Pending; | ||
| } |
12 changes: 12 additions & 0 deletions
12
dotnet/samples/AGUIClientServer/AGUIDojoServer/AgenticUI/StepStatus.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace AGUIDojoServer.AgenticUI; | ||
|
|
||
| [JsonConverter(typeof(JsonStringEnumConverter<StepStatus>))] | ||
| internal enum StepStatus | ||
| { | ||
| Pending, | ||
| Completed | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.