Skip to content

.NET: Update AG-UI samples for latest MAF + AG-UI SDK and align with docs - #7295

Open
danroth27 wants to merge 7 commits into
microsoft:mainfrom
danroth27:daroth/simplify-agui-hitl-sample
Open

.NET: Update AG-UI samples for latest MAF + AG-UI SDK and align with docs#7295
danroth27 wants to merge 7 commits into
microsoft:mainfrom
danroth27:daroth/simplify-agui-hitl-sample

Conversation

@danroth27

@danroth27 danroth27 commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary

Updates all AG-UI .NET samples under dotnet/samples/02-agents/AGUI to 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

  • Package bump: AGUI.* 0.0.3 -> 0.0.4 in dotnet/Directory.Packages.props.
  • Step01 / Step02 / Step03: drop the AddHttpClient().AddLogging() server noise; simplify the client run-started output to match the getting-started doc (no thread-id plumbing).
  • Step04 (human-in-the-loop): remove HTTP request/response body logging and the MEAI001 pragmas (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.
  • Step05 (state management): replace the custom SharedStateAgent/StatefulAgent DataContent pattern - which the released AGUI.Server silently drops - with the declarative AGUIStreamOptions.MapResultAsStateSnapshot("generate_recipe") plus a thin RecipeStateAgent that reads the client's recipe from RunAgentInput.State. Recipe models now match the docs (Recipe/Ingredient with icon/name/amount).
  • README: refreshed to the shipped API (MapAGUIServer, ApprovalRequiredAIFunction, ToolApprovalRequestContent/CreateResponse, declarative state); removed references to the removed middleware types.

Verification

  • All 10 sample projects build clean.
  • Step04 approval + resume and Step05 state-snapshot round-trip were run end-to-end against GitHub Models.

Related

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
Copilot AI review requested due to automatic review settings July 23, 2026 14:34
@danroth27
danroth27 temporarily deployed to github-app-auth July 23, 2026 14:34 — with GitHub Actions Inactive
@danroth27
danroth27 temporarily deployed to github-app-auth July 23, 2026 14:34 — with GitHub Actions Inactive
@danroth27
danroth27 temporarily deployed to github-app-auth July 23, 2026 14:34 — with GitHub Actions Inactive
@danroth27
danroth27 temporarily deployed to github-app-auth July 23, 2026 14:35 — with GitHub Actions Inactive
@agent-framework-automation agent-framework-automation Bot added the .NET Usage: [Issues, PRs], Target: .Net label Jul 23, 2026
@github-actions github-actions Bot changed the title Simplify AG-UI Step04 human-in-the-loop sample to idiomatic native approval flow .NET: Simplify AG-UI Step04 human-in-the-loop sample to idiomatic native approval flow Jul 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DelegatingAIAgent that translated approval requests/responses to a bespoke request_approval tool-call protocol.
  • Removes the custom client-side DelegatingAIAgent and JSON plumbing used to marshal the bespoke approval protocol.
  • Updates the Step04 server and client to map/use the underlying agents directly (MapAGUIServer("/", baseAgent) and chatClient.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.

@danroth27
danroth27 marked this pull request as ready for review July 23, 2026 19:58
@danroth27
danroth27 temporarily deployed to github-app-auth July 23, 2026 19:58 — with GitHub Actions Inactive
@danroth27
danroth27 temporarily deployed to github-app-auth July 23, 2026 19:58 — with GitHub Actions Inactive
@danroth27
danroth27 marked this pull request as draft July 23, 2026 19:59
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.
@agent-framework-automation agent-framework-automation Bot added the documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs label Jul 24, 2026
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.
@rogerbarreto
rogerbarreto marked this pull request as ready for review July 24, 2026 11:12
@rogerbarreto

Copy link
Copy Markdown
Member

@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!

@danroth27

Copy link
Copy Markdown
Member Author

@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
@danroth27
danroth27 temporarily deployed to github-app-auth July 25, 2026 23:36 — with GitHub Actions Inactive
@danroth27 danroth27 changed the title .NET: Simplify AG-UI Step04 human-in-the-loop sample to idiomatic native approval flow .NET: Update AG-UI samples for latest MAF + AG-UI SDK and align with docs Jul 25, 2026
@danroth27
danroth27 temporarily deployed to github-app-auth July 25, 2026 23:38 — with GitHub Actions Inactive
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants