Endpoints
An AG-UI endpoint is a normal ASP.NET Core POST endpoint. It receives aRunAgentInput, calls an IChatClient, converts the streamed response to AG-UI
events, and returns Server-Sent Events.
Register AG-UI services
CallAddAGUI() during startup. It configures ASP.NET Core JSON options with
the AG-UI source-generated serializer context and registers interrupt content
types used by the IChatClient pipeline.
Endpoint pattern
Every AG-UI endpoint follows the same five steps.Create ChatRequestContext
Call
input.ToChatRequestContext(jsonSerializerOptions, streamOptions?).
The returned context exposes ctx.Messages and ctx.ChatOptions.Call the IChatClient
Pass
ctx.Messages and ctx.ChatOptions to
chatClient.GetStreamingResponseAsync(...).Convert to AG-UI events
Pipe the
ChatResponseUpdate stream through
.AsAGUIEventStreamAsync(ctx, cancellationToken).Minimal endpoint
This is the canonical endpoint shape used by the .NET samples.Key APIs
ToChatRequestContext
ToChatRequestContext adapts the AG-UI request to the
Microsoft.Extensions.AI request shape.
ChatRequestContext contains:
ctx.Input- the originalRunAgentInputctx.Messages- convertedList<ChatMessage>ctx.ChatOptions- configuredChatOptions
ctx.ChatOptions.AdditionalProperties[AGUIConstants.RunAgentInputKey].
AsAGUIEventStreamAsync
AsAGUIEventStreamAsync converts streamed ChatResponseUpdate values into
AG-UI BaseEvent values.
TEXT_MESSAGE_* events,
maps FunctionCallContent and FunctionResultContent to tool events, maps
TextReasoningContent to reasoning events, and passes through any BaseEvent
stored in ChatResponseUpdate.RawRepresentation.
WrapAsSseItems
ASP.NET Core’sTypedResults.ServerSentEvents writes SseItem<T> values. The
small helper wraps each AG-UI event in SseItem<BaseEvent>.
Adding stream options
PassAGUIStreamOptions when the endpoint needs custom stream conversion.