.NET: Update AG-UI samples for latest MAF + AG-UI SDK and align with docs - #7295
.NET: Update AG-UI samples for latest MAF + AG-UI SDK and align with docs#7295danroth27 wants to merge 7 commits into
Conversation
The Step04 sample previously wrapped both the server and client agents in custom ServerFunctionApproval*Agent middleware (~470 lines across two files) to marshal a bespoke approval protocol over AG-UI. This is no longer needed: MapAGUIServer natively emits the tool-approval interrupt when the model calls an ApprovalRequiredAIFunction, and AGUIChatClient natively transports the client's ToolApprovalResponseContent decision back to resume the run. Changes: - Server: map the ChatClientAgent directly with MapAGUIServer; remove the ServerFunctionApprovalAgent wrapper, the JsonOptions plumbing, and the ApprovalJsonContext registration. - Client: use the AGUIChatClient-backed agent directly; the existing loop already handles ToolApprovalRequestContent -> CreateResponse idiomatically. - Delete ServerFunctionApprovalServerAgent.cs and ServerFunctionApprovalClientAgent.cs. Verified end-to-end (approval request -> approve -> tool executes -> final response) against GitHub Models. Both projects build with 0 warnings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: eeb2168d-2ecc-4f8d-9830-c287072eb7e1
There was a problem hiding this comment.
Pull request overview
This PR simplifies the .NET AG-UI Step04 “Human-in-the-loop” sample by removing the bespoke server/client approval-middleware layer and relying on the framework’s native tool-approval interrupt + resume flow when using ApprovalRequiredAIFunction.
Changes:
- Removes the custom server-side
DelegatingAIAgentthat translated approval requests/responses to a bespokerequest_approvaltool-call protocol. - Removes the custom client-side
DelegatingAIAgentand JSON plumbing used to marshal the bespoke approval protocol. - Updates the Step04 server and client to map/use the underlying agents directly (
MapAGUIServer("/", baseAgent)andchatClient.AsAIAgent(...)).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/ServerFunctionApprovalServerAgent.cs | Deletes custom server approval middleware and its custom JSON-serialized approval models. |
| dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Server/Program.cs | Removes custom JSON options + wrapper agent; maps the base agent directly via MapAGUIServer. |
| dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Client/ServerFunctionApprovalClientAgent.cs | Deletes custom client approval middleware and its custom approval models. |
| dotnet/samples/02-agents/AGUI/Step04_HumanInLoop/Client/Program.cs | Uses the AGUI-backed agent directly and removes now-unneeded custom approval-agent wiring. |
The Step04 human-in-the-loop sample no longer uses the custom ServerFunctionApprovalServerAgent / ServerFunctionApprovalClientAgent wrappers. Update the README so it describes the idiomatic native flow: the server maps a plain agent with MapAGUIServer and relies on ApprovalRequiredAIFunction to raise the approval interrupt, and the client handles ToolApprovalRequestContent and replies with ToolApprovalResponseContent.
The Step04 client defaults to http://localhost:5100 (and the server launchSettings also uses 5100), but the README told users to run the server on port 8888, so the client could not reach it. Align the Step04 server run command to 5100. Other steps intentionally keep 8888 because their clients default to that port.
|
@danroth27, thanks for the contribution! I moved from draft to ready for review, let me know if you still adding more changes to this PR in regards to other samples. Thanks! |
|
@rogerbarreto All of the .NET AG-UI samples presumably need an update. This is just one of them. I was going to try to update all of the .NET AG-UI samples once I finished the doc updates: MicrosoftDocs/semantic-kernel-docs#430. But if someone wants to update the samples before I get to the rest of them, that's totally fine by me. |
- Bump AGUI.* packages 0.0.3 to 0.0.4 (Directory.Packages.props) - Step01/02/03: drop AddHttpClient().AddLogging() server noise and simplify the client run-started output to match the getting-started doc (no thread plumbing) - Step04 (HITL): remove HTTP body logging and MEAI001 pragmas, give the approval tool an explicit name, and align the resume decision message with the doc - Step05 (state): replace the custom SharedStateAgent/StatefulAgent DataContent pattern (dropped by released AGUI.Server) with declarative AGUIStreamOptions.MapResultAsStateSnapshot plus a thin RecipeStateAgent that reads RunAgentInput.State, and align the Recipe models with the docs - Refresh README to the shipped API (MapAGUIServer, ApprovalRequiredAIFunction, declarative state) Verified: all 10 sample projects build; Step04 approval/resume and Step05 state snapshot round-trip run end-to-end against GitHub Models. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: eeb2168d-2ecc-4f8d-9830-c287072eb7e1
Give the SearchRestaurants tool an explicit "search_restaurants" name so the client displays an accurate tool name (not a compiler-mangled local-function name) and stays aligned with the backend-tool-rendering doc. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: eeb2168d-2ecc-4f8d-9830-c287072eb7e1
The check-format CI job enforces the repository's utf-8-bom charset rule via dotnet format. The Step05 files added in this PR were saved without a BOM. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: eeb2168d-2ecc-4f8d-9830-c287072eb7e1
Summary
Updates all AG-UI .NET samples under
dotnet/samples/02-agents/AGUIto the latest MAF + AG-UI C# SDK and brings them into alignment with the AG-UI Learn docs.(Supersedes the original Step04-only scope of this PR.)
Changes
0.0.3->0.0.4indotnet/Directory.Packages.props.AddHttpClient().AddLogging()server noise; simplify the client run-started output to match the getting-started doc (no thread-id plumbing).MEAI001pragmas (the referenced Microsoft.Extensions.AI no longer marks these types experimental); give the approval tool an explicit name (approve_expense_report) instead of a compiler-mangled local-function name; align the resume decision message with the doc.SharedStateAgent/StatefulAgentDataContentpattern - which the releasedAGUI.Serversilently drops - with the declarativeAGUIStreamOptions.MapResultAsStateSnapshot("generate_recipe")plus a thinRecipeStateAgentthat reads the client's recipe fromRunAgentInput.State. Recipe models now match the docs (Recipe/Ingredientwithicon/name/amount).MapAGUIServer,ApprovalRequiredAIFunction,ToolApprovalRequestContent/CreateResponse, declarative state); removed references to the removed middleware types.Verification
Related