On this page
Last week’s article, Building an Agentic UI with Blazor and .NET 11, built an order desk in Blazor on top of an AG-UI endpoint written by hand: about two hundred lines that bind the request, run the agent, stream the events and check every approval against what the server proposed. Microsoft Agent Framework has a method, MapAGUIServer, that maps the same kind of endpoint in one call. The obvious question is whether the two hundred lines were worth writing.
So I built the agent service a second time on Agent Framework hosting and put it behind the same Blazor app. One test class now runs against both services, and the browser steps run twice. For text, tool calls, shared state and Stop, the two servers send the same events in the same order, and all nine browser steps pass on both.
Approvals are where they differ. With the clients used here, the shortest framework setup stopped for approval correctly and then failed on the answer. Getting an honest approval through took a session store and a ten-line wrapper. Once that was in place the framework did something my endpoint does not: when a request tried to swap the approved refund for a different one, it ran the refund the server had proposed and ignored the one in the request. It also did something I like less: it turned every refused approval into an ordinary HTTP 200.
The problem
A hand-built endpoint is code a team owns. Somebody has to register the protocol’s JSON types, turn a run request into chat messages, format Server-Sent Events, and decide what an approval is allowed to do. The first article found that last part matters: the approval and the tool call it approves both travel in the client’s request, so without a server-side check one hand-written POST moved money.
A framework method that does all of this is attractive, and for most of it the attraction is justified. What a one-line mapping cannot tell you is what it decided on your behalf. Does it keep the conversation on the server or trust the copy the client sends? Does it check an approval against anything? What does a caller see when it refuses? Those answers decide whether the endpoint is safe to expose, and none of them is visible in the line of code.
The way to find out is to hold everything else still. Same model stand-in, same three tools, same payment ledger, same Blazor app, same tests. Only the hosting layer changes.
Architecture
%%{init: {'theme':'base','themeVariables':{'primaryColor':'#FFF3E0','primaryTextColor':'#232F3E','primaryBorderColor':'#FF9900','lineColor':'#232F3E','clusterBkg':'#F8FAFC','clusterBorder':'#CBD5E1','edgeLabelBackground':'#FFFFFF','nodeTextColor':'#232F3E'}}}%%
flowchart TD
W["Blazor Web App:
UIAgent over AGUIChatClient"] -- "HTTP POST, whole conversation
and any approval answer" --> M["MapAGUIServer endpoint:
binding, events, interrupts"]
M --> H["Hosted agent:
loads the session for this thread"]
H <--> S["Session store:
history and pending approvals"]
H --> N["NewMessagesOnlyAgent:
keep what follows the last assistant message"]
N --> C["CaseStateAgent:
put the browser's state in front"]
C --> A["ChatClientAgent:
tool loop, approval binding"]
A --> T["Tools: get_order, draft_reply,
refund_order (needs approval)"]
T --> L["Ledger: payment stand-in,
one refund per key"]
style W fill:#EBF8FF,stroke:#0073BB,stroke-width:2px,color:#004C74
style M fill:#F3E8FF,stroke:#7C3AED,stroke-width:2px,color:#4C1D95
style H fill:#F3E8FF,stroke:#7C3AED,stroke-width:2px,color:#4C1D95
style S fill:#F0FFF4,stroke:#1D8102,stroke-width:2px,color:#145202
style L fill:#F0FFF4,stroke:#1D8102,stroke-width:2px,color:#145202The hand-built service from the first article is stateless. Every request carries the whole conversation, and the only thing the server remembers is a small table of approvals it is waiting for. The framework service ends up stateful: the session for a thread lives on the server, holds the history and the pending approval, and is the thing an approval is checked against.
That difference is the whole design. An AG-UI client sends the full conversation on every request, because the protocol lets a server be stateless. A server that also keeps the conversation now has two copies, and has to choose one. The two wrappers in the diagram exist because of that choice.

The framework host
The agent is registered by name, given a session store, and mapped. The model stand-in and the tools are the ones the hand-built service uses. SeenByModel is a test tool that notes what the model was handed; it is how the history numbers later in this article were measured.
IHostedAgentBuilder desk = builder.Services.AddAIAgent("desk", (services, name) =>
{
IConfiguration settings = services.GetRequiredService<IConfiguration>();
OrderBook orders = services.GetRequiredService<OrderBook>();
IChatClient model = new SeenByModel(
new ScriptedModel(orders, TimeSpan.FromMilliseconds(settings.GetValue("DESK_WORD_DELAY_MS", 15))),
services.GetRequiredService<ModelCalls>());
ChatClientAgentOptions options = new()
{
Name = name,
ChatOptions = new ChatOptions { Tools = new DeskTools(orders, services.GetRequiredService<Ledger>()).Create() },
// On by default: an approval is accepted only for a request the session holds. The lab turns
// it off to measure what it changes.
DisableApprovalResponseBinding = !settings.GetValue("DESK_VERIFY_RESUME", true),
};
// Outermost first: keep only what is new from the client, then put the browser's state in front of it.
AIAgent agent = new CaseStateAgent(model.AsAIAgent(options));
return settings.GetValue("DESK_NEW_MESSAGES_ONLY", true) ? new NewMessagesOnlyAgent(agent) : agent;
});
// The approval is checked against the session, so the session has to outlive the request. In memory:
// with more than one instance this is a shared store. Isolation by caller needs an identity, which
// this lab does not have.
desk.WithSessionStore(
(services, _) => services.GetRequiredService<IConfiguration>()["DESK_SESSIONS"] == "none" ? new NoopAgentSessionStore() : new InMemoryAgentSessionStore(),
withIsolation: false);// One call maps the endpoint: request binding, the event stream, interrupts and resume.
app.MapAGUIServer(desk, "/agent")
.WithMetadata(new AGUIStreamOptions().MapResultAsStateSnapshot(DeskTools.DraftReplyName));Compare that with the first article. There is no JSON registration, no RunAgentInput parameter, no event stream result type and no UseFunctionInvocation(): AddAGUIServer() registers the JSON types and the agent type runs the tool loop. AGUIStreamOptions is the same class as before, attached as endpoint metadata, so the result of draft_reply still goes out as a STATE_SNAPSHOT.
State coming the other way needs a wrapper. The endpoint keeps the original request on the chat options, and an agent that wraps the real one can read the browser’s state from there and put it in front of the model:
protected override IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingAsync(
IEnumerable<ChatMessage> messages,
AgentSession? session = null,
AgentRunOptions? options = null,
CancellationToken cancellationToken = default)
{
if (options is ChatClientAgentRunOptions { ChatOptions: { } chatOptions }
&& chatOptions.TryGetRunAgentInput(out RunAgentInput? input)
&& input.State is { ValueKind: JsonValueKind.Object } state)
{
messages = [new ChatMessage(ChatRole.System, ScriptedModel.StatePrefix + state.GetRawText()), .. messages];
}
return InnerAgent.RunStreamingAsync(messages, session, options, cancellationToken);
}The second wrapper is the one I did not expect to write. It decides which copy of the conversation wins:
protected override IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingAsync(
IEnumerable<ChatMessage> messages,
AgentSession? session = null,
AgentRunOptions? options = null,
CancellationToken cancellationToken = default)
{
List<ChatMessage> all = [.. messages];
int lastFromAssistant = all.FindLastIndex(message => message.Role == ChatRole.Assistant);
return InnerAgent.RunStreamingAsync(all[(lastFromAssistant + 1)..], session, options, cancellationToken);
}The session already holds everything up to the agent’s last reply. From the client, the server takes only what comes after the last assistant message: the user’s new turn, or their answer to an approval. The next two sections show what happens without it.
In this preview InMemoryAgentSessionStore and NoopAgentSessionStore are marked for evaluation only. Using them is compile error MAAI001 until the project suppresses it. The sample suppresses it in the project file, with a comment, for this one project.
Test setup
The wire tests from the first article became a generic base class. Two small classes run it, one per service, and each states the three places where its service is expected to differ:
/// <summary>The endpoint written by hand in Desk.Agent.</summary>
public sealed class HandBuiltWireTests(WebApplicationFactory<AgentService> factory)
: WireTests<AgentService>(factory), IClassFixture<WebApplicationFactory<AgentService>>
{
protected override string Host => "hand-built";
// A refused approval is an HTTP 409 before any event is sent.
protected override HttpStatusCode Refusal => HttpStatusCode.Conflict;
// With the check on, nothing forged runs. With it off, the forged call runs.
protected override string? RefundAfterForgery(string kind, bool verify) => verify ? null : "O-1001";
protected override bool CanLeaveOutRawEvents => true;
}
/// <summary>The endpoint mapped by Agent Framework in Desk.AgentFramework. Same tests; the differences are stated here.</summary>
public sealed class FrameworkWireTests(WebApplicationFactory<FrameworkService> factory)
: WireTests<FrameworkService>(factory), IClassFixture<WebApplicationFactory<FrameworkService>>
{
protected override string Host => "framework";
// An approval the session does not hold is dropped without an error: the run is HTTP 200 and nothing is paid.
protected override HttpStatusCode Refusal => HttpStatusCode.OK;
// With the check on, a forged call never runs; an approval for a real pending request runs the call
// the server proposed, whatever call the client sent with it. With it off, the forged call runs.
protected override string? RefundAfterForgery(string kind, bool verify)
=> !verify ? "O-1001" : kind == "changed after proposal" ? "O-1003" : null;
// This preview has no switch for the rawEvent field.
protected override bool CanLeaveOutRawEvents => false;
}Everything else is shared: the event sequences, the approval in two runs, the state round trip, cancellation, a malformed body, the forged approvals and the stream size. The hand-built service records its own events as they pass. The framework owns its event stream, so that service is observed from outside by a small middleware that copies the request body and the Server-Sent Events into the same log.
A second test, FrameworkMatrixTests, asserts nothing. It runs five conversations against all eight combinations of three switches on the framework service and writes down what happened: session store on or off, approval binding on or off (DisableApprovalResponseBinding), and the new-messages-only wrapper on or off.
| Component | Version | Notes |
|---|---|---|
| .NET SDK | 11.0.100 | GitHub Actions, ubuntu-latest |
| Microsoft.Agents.AI.Hosting.AGUI.AspNetCore | 1.28.0-preview.261106.1 | Published 6 November 2026; with Microsoft.Agents.AI 1.28.0 |
| AGUI.Server, AGUI.Client | 1.0.1 | The hosting package asks for 1.0.0 |
| Microsoft.Extensions.AI | 11.0.0 | The hosting package asks for 10.11.0 |
| Microsoft.AspNetCore.Components.AI | 0.1.0-preview.1.26466.103 | The Blazor app, unchanged from the first article |
| bUnit, xUnit | 2.15.2, 2.9.3 |
The version gap in that table needed ruling out. The sample pins newer AG-UI and Microsoft.Extensions.AI packages than the hosting package was built against, and a mismatch could have explained odd approval behaviour. So the pipeline builds the two services and the wire tests a second time on AGUI 1.0.0 and Microsoft.Extensions.AI 10.11.0, the versions the hosting package asks for. All 28 wire tests pass there too, with the same outcomes.
Test results
48 tests pass: 7 on the agent alone, 14 wire tests against each service, the 8 rows of the settings matrix, and 5 bUnit tests. The nine browser steps pass against the Blazor app with either service behind it.
| Scenario | Hand-built endpoint | Framework endpoint |
|---|---|---|
| Text, backend tool, shared state, Stop | Same event sequence | Same event sequence |
| Honest approval | Refund paid once | Refund paid once |
| The same approval sent again | HTTP 409, tool not called again | HTTP 200 and a plain text reply, tool not called again |
| Forged approval, call never proposed | HTTP 409, nothing paid | HTTP 200, nothing paid |
| Forged approval, real request with the call changed | HTTP 409, nothing paid | HTTP 200, the proposed refund is paid, the forged one is not |
| Malformed body | HTTP 400 | HTTP 400 |
| Stream for one order question | 1,430 bytes | 4,901 bytes |
| Browser steps | 9 of 9 | 9 of 9 |
The first row is the reassuring one. For every scenario that both services complete, the list of event types is identical, down to the count of text chunks. A Blazor app, or any other AG-UI client, cannot tell which server it is talking to until an approval is refused.
The forged approvals are the same two attacks as in the first article. One POST approves a refund nobody proposed. The other waits for a real proposal, 37.50 on order O-1003, then answers it with a different call: 42.00 on order O-1001. This time the second attack also names the real thread, which matters now that a server keeps sessions.
framework changed after proposal check off HTTP 200 last event RUN_FINISHED refunds in ledger: [O-1001 42.00]
framework changed after proposal check on HTTP 200 last event RUN_FINISHED refunds in ledger: [O-1003 37.50]
framework never proposed check off HTTP 200 last event RUN_FINISHED refunds in ledger: [O-1001 42.00]
framework never proposed check on HTTP 200 last event RUN_FINISHED refunds in ledger: []
hand-built changed after proposal check off HTTP 200 last event RUN_FINISHED refunds in ledger: [O-1001 42.00]
hand-built changed after proposal check on HTTP 409 last event none refunds in ledger: []
hand-built never proposed check off HTTP 200 last event RUN_FINISHED refunds in ledger: [O-1001 42.00]
hand-built never proposed check on HTTP 409 last event none refunds in ledger: []Look at the second line. With binding on, the framework accepted the approval, because there really was a pending request with that id in that session, and then ran the call it had stored: 37.50 on O-1003. The call in the request was ignored. My endpoint compares the two and refuses with a 409 when they differ. Both keep the forged refund from being paid. They disagree about whether a tampered approval still counts as an approval, and I think refusing is the better answer, because a request that arrives with a different call attached is evidence that something is wrong with the caller.
Now the cost of getting there. This is the settings matrix, reduced to the columns that matter.
| Session store | Binding | New messages only | Honest approval | Never proposed | Call changed | Model saw on turn 2 |
|---|---|---|---|---|---|---|
| Off | On | Off | Run error | Run error | Run error | 3 messages |
| Off | Off | Off | Paid | Forged refund paid | Forged refund paid | 3 messages |
| On | On | Off | Run error | Run error | Run error | 5 messages |
| On | Off | Off | Run error | Forged refund paid | Run error | 5 messages |
| On | On | On | Paid | Nothing paid | Proposed refund paid | 3 messages |
| On | Off | On | Paid | Forged refund paid | Forged refund paid | 3 messages |
| Off | On | On | Nothing paid | Nothing paid | Nothing paid | 1 message |
| Off | Off | On | Paid | Forged refund paid | Forged refund paid | 1 message |
The first row behaves like the shortest setup: an agent, an approval-required tool and MapAGUIServer, with nothing stored between requests. I also ran that shortest form directly, earlier in this work, with the same result. The first run stops for approval as it should. The second run, carrying the answer, ends in RUN_ERROR. The client is told “An error occurred while streaming the agent response.” Underneath, the function-calling client threw because it found an approval request with no matching response.
My reading of that, from behaviour and not from the framework’s source: binding accepts an approval only if the session holds the request it answers. With no stored session there is nothing to match, the answer is discarded, and the request that the AG-UI layer rebuilt from the client’s payload is left without one. The second row supports that reading. Turn binding off and the honest approval works, and so does every forgery, which is exactly the state the hand-built endpoint was in before it got its check.
Adding a session store, rows three and four, fails differently. Now the session holds the real approval request, the AG-UI layer adds its rebuilt copy, and the function-calling client throws on two requests with the same id. The last column shows the wider problem: on the second turn of an ordinary conversation the client sent three messages and the model received five, because the stored history and the client’s copy were both passed in.
Row five is the configuration the sample ships: session store on, binding on, and the wrapper that takes only new messages from the client. It is the only row where an honest approval is paid and neither forgery gets its refund.

%%{init: {'theme':'base','themeVariables':{'primaryColor':'#FFF3E0','primaryTextColor':'#232F3E','primaryBorderColor':'#FF9900','lineColor':'#232F3E','signalColor':'#0073BB','signalTextColor':'#0F172A','actorBkg':'#FFF3E0','actorBorder':'#FF9900','actorTextColor':'#232F3E','noteBkgColor':'#FFF8E7','noteBorderColor':'#FF9900','noteTextColor':'#232F3E'}}}%%
sequenceDiagram
participant W as Blazor web app
participant E as Framework endpoint
participant S as Session store
W->>E: Run 1, "Refund order O-1003"
E->>S: Save history and the pending request
E-->>W: RUN_FINISHED, interrupt
W->>E: Run 2, approved, with a copy of the call
E->>S: Load the session for this thread
Note over E: Bind the answer to the stored request
E-->>W: TOOL_CALL_RESULT, text, RUN_FINISHED
W->>E: Run 2 again
Note over E: No pending request, answer dropped
E-->>W: HTTP 200, a plain text replyOn the framework endpoint a replayed or forged approval is not an error. The answer is dropped, the model is called with what is left, and the caller gets HTTP 200 with a normal run. Nothing is paid, which is right, but nothing in the response or in the status code tells an operator that somebody tried. If you host this way, log dropped approvals yourself, in a wrapper that sees the incoming messages.
The stream size is the last difference. Each event can carry the model update it was made from in a rawEvent field. The hand-built endpoint removes it and sends 1,430 bytes for an order question; with the field left in, it sends 4,978. The framework endpoint sends 4,901 bytes for the same question, and I found no setting in this preview that leaves the field out.
Cost
Cost here is what a team has to own and run.
| Hand-built endpoint | Framework endpoint | |
|---|---|---|
| Service code, with comments and lab endpoints | 196 lines in 3 files | 136 lines in 3 files |
| Protocol code you maintain | JSON registration, request conversion, SSE result | None |
| Approval check | 82 lines of your own | A framework option, on by default |
| State kept on the server | Pending approvals only | The whole session: history and pending approvals |
| Shared store needed with two instances | Small: one entry per open approval | A session store for every conversation |
| Bytes for one order question | 1,430 | 4,901 |
Sixty lines is not much of a saving, and half of what is left on the framework side is two wrappers, one of which exists only to stop the framework and the protocol from disagreeing. The real trade is different. The hand-built service keeps almost nothing and checks approvals itself. The framework service keeps everything and checks approvals for you, and in exchange you operate a session store.
Production considerations
- The session store is now part of the approval path. If a session is lost, the pending approval goes with it and the user’s Approve click does nothing. The seventh row of the matrix shows the other effect: with no stored session and the wrapper on, the model saw one message of a three-message conversation. The in-memory store is marked for evaluation only. Production needs a durable, shared one.
- Keep isolation on.
WithSessionStoreandWithInMemorySessionStoretake awithIsolationargument that defaults to true. I turned it off because neither service has an identity to isolate by. I did not test it. Without it, the thread id in the request is the only key to a session. - Neither endpoint is safe to expose to untrusted callers. In the changed-call test the framework paid the proposed refund on the say-so of a hand-written POST that knew the thread and the interrupt id. That is an approval by someone who was never asked. Binding protects what gets approved. It does not establish who approved it.
- Log what the framework drops. A refused approval is HTTP 200. Count them in a wrapper and alert on them.
- Capture the real exception. The client is told only that streaming failed, which is the right thing to tell a client. Make sure the server log has the rest. During this work I had to hook first-chance exceptions to see the cause.
- Decide who can read the stream.
rawEventcarries the agent name, content types and message ids of every update. With Blazor interactive server the browser never sees it, because the web app is the AG-UI client. A client running in the browser would. - Check what the session stores.
CaseStateAgentadds a system message on every turn. I did not measure whether those accumulate in the stored history. With a real model, measure it before relying on it. - Keep the matrix test. This is a preview package, and every cell in that table is behaviour that can change in the next build. The test runs with the others in the pipeline and tells you which cells moved.
An approval is a decision by a person, and a record of it should name who decided, what was proposed and what ran. Neither service authenticates anyone, so neither can produce that record. The framework service adds a gap of its own: an approval it drops leaves no trace at the endpoint. Where approvals gate money or anything clinical, write the record yourself, at the point the tool runs and at the point an answer is refused.
Decision framework
| If this is true | Prefer | Why |
|---|---|---|
| The agent service should stay stateless and scale without a conversation store | Hand-built | The client carries the conversation; the server keeps one small table |
| A tampered or replayed approval must be refused visibly | Hand-built | HTTP 409 with a reason, before any event is sent |
| The event stream can reach a browser or another party you do not control | Hand-built | It can leave out rawEvent today |
| The server should own the conversation and not trust the client’s copy | Framework | Sessions, with history and pending approvals on the server |
| You already run Agent Framework agents or workflows | Framework | One hosting model, and the endpoint is one call |
| You want the least protocol code to maintain | Framework | With a session store, the new-messages wrapper and the matrix test |
For this order desk, today, I would keep the hand-built endpoint. It has fewer moving parts, it refuses loudly, and it does not depend on a preview hosting package or an evaluation-only store. That changes the day the server needs to own the conversation, for example when the history must survive a browser refresh or be shared between devices. At that point the framework’s session model is the thing you would otherwise have to build, and its approval binding comes with it.
Key takeaways
- For text, tool calls, shared state and cancellation,
MapAGUIServerand a hand-built endpoint onAGUI.Serversend the same events. The same Blazor app passed nine browser steps against both. - With these clients and this preview, an approval did not complete on the shortest framework setup. It needed a session store, and a wrapper that takes only new messages from the client.
- A session store and an AG-UI client both hold the conversation. Passed through unchanged, the model received five messages where the client sent three.
- Framework approval binding blocks a forged call and runs the stored one. It answers a replayed or forged approval with HTTP 200, so add your own logging.
- Turning binding off to make approvals work reopens the hole from the first article: one hand-written POST refunded an order nobody proposed.
- The framework stream was 3.4 times the size of the trimmed hand-built stream, with no switch found to reduce it.
Everything in this article comes from one pipeline run on 18 November 2026: GitHub Actions run 44363641369, commit 93b7416, with the transcripts, wire traces and the settings matrix on the ci-results-agentic-ui-blazor branch. 48 xUnit and bUnit tests passed, the 28 wire tests passed again on AGUI 1.0.0 and Microsoft.Extensions.AI 10.11.0, and nine Chromium steps passed against each service. The model is a scripted stand-in and all orders are invented. Not done: no real model was called; the C# client loop shown in the Agent Framework documentation was not run, the clients here are AGUIChatClient used directly and the Blazor components over it; Agent Framework was studied through its public API and its behaviour, not its source, so the explanation of approval binding is an inference; session isolation was not tested; stores are in memory on one instance; one preview build was tested and later builds may behave differently.
The complete sample for this article is on GitHub: nithinmohantk/blog-samples-working-repo/agentic-ui-blazor. Clone it with git clone https://github.com/nithinmohantk/blog-samples-working-repo.git and open the agentic-ui-blazor folder. Its README says how to run it and what has been verified.
References & Further Reading
- → Building an Agentic UI with Blazor and .NET 11— The first article: the Blazor app, the hand-built endpoint and the forged approval finding
- → Agent Framework: Getting started with AG-UI— MapAGUIServer hosting and the client
- → Agent Framework: Human-in-the-loop with AG-UI— Approval-required tools, interrupts and the resume payload
- → Agent Framework: State management with AG-UI— Reading client state in a delegating agent and mapping tool results to state events
- → Agent Framework: AG-UI security considerations— Untrusted clients, state validation, thread ownership and approval state
- → AG-UI .NET SDK source— Where a resume entry is turned into an approval request and response
- → Sample code for this article— Both agent services, the Blazor app, the shared tests, the settings matrix and the pipeline script
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.