Skip to content

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

Merged
westey (westey-m) merged 11 commits into
microsoft:mainfrom
danroth27:daroth/simplify-agui-hitl-sample
Aug 19, 2026
Merged

.NET: Update AG-UI samples for latest MAF + AG-UI SDK and align with docs#7295
westey (westey-m) merged 11 commits into
microsoft:mainfrom
danroth27:daroth/simplify-agui-hitl-sample

Conversation

@danroth27

@danroth27 Daniel Roth (danroth27) commented Jul 23, 2026

Copy link
Copy Markdown
Member

Motivation & Context

The .NET AG-UI samples had diverged from the current MAF integration, AG-UI C# SDK, and Learn documentation. The human-in-the-loop sample maintained custom approval middleware despite native approval and resume support, while the state-management sample emitted DataContent that the released AG-UI server did not map to state events. Several clients also replayed messages already retained by AgentSession, and one frontend tool exposed a compiler-generated name.

This update makes the samples accurate references for streaming chat, backend and frontend tools, human approval, multi-turn sessions, and shared state.

Description & Review Guide

  • What are the major changes?
    • Update all AGUI.* packages from 0.0.3 to 0.0.4.
    • Simplify Steps 01-03 and give the frontend location tool the stable get_user_location name.
    • Replace Step04's custom client/server approval middleware with ApprovalRequiredAIFunction, ToolApprovalRequestContent.CreateResponse, and the native AG-UI resume flow.
    • Replace Step05's custom state middleware and DataContent output with RunAgentInput.State, a thin state-context agent, and AGUIStreamOptions.MapResultAsStateSnapshot.
    • Let AgentSession exclusively own prior conversation history so clients send only each new turn.
    • Refresh the AG-UI sample README for the shipped APIs, ports, security guidance, and behavior.
  • What is the impact of these changes?
    • The samples now demonstrate supported first-class APIs instead of protocol workarounds.
    • Approval/resume, frontend and backend tools, multi-turn memory, and shared-state snapshots work end to end.
    • All ten sample projects build cleanly, and the targeted AG-UI unit and integration suites pass.
  • What do you want reviewers to focus on?
    • The native approval/resume loop in Step04.
    • The state input and declarative snapshot mapping in Step05.
    • The ownership boundary between each client's current-turn messages and AgentSession history.

Related Issue

Fixes #7623

Related documentation update: MicrosoftDocs/semantic-kernel-docs#430

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

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
@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
Daniel Roth (danroth27) marked this pull request as ready for review July 23, 2026 19:58
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
Roger Barreto (rogerbarreto) marked this pull request as ready for review July 24, 2026 11:12
Resolve the Directory.Packages.props conflict by retaining the AG-UI SDK 0.0.4
versions required by this PR while accepting main's updated System.Text.Json,
System.Threading.Channels, and Microsoft.Extensions.AI package versions.

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.

.NET: Update AG-UI samples to current SDK patterns

5 participants