Extensibility
AGUIStreamOptions customizes how ChatResponseUpdate streams are converted
to AG-UI events. It is fluent and method-only: create an instance, register
Map* hooks, and pass it to ToChatRequestContext.
Built-in conversion
You do not need stream options for the common path. The hosting layer already maps:TextContenttoTEXT_MESSAGE_*TextReasoningContenttoREASONING_*FunctionCallContenttoTOOL_CALL_*FunctionResultContenttoTOOL_CALL_RESULTToolApprovalRequestContentandInterruptRequestContentto interrupt outcomesChatResponseUpdate.RawRepresentationcontaining aBaseEventdirectly to that event
If a
ChatResponseUpdate.RawRepresentation is a BaseEvent, the hosting
layer emits it verbatim. This is often the simplest way for a custom
IChatClient wrapper to inject StateSnapshotEvent, CustomEvent, or
RawEvent values.MapContent
MapContent(Func<AIContent, IEnumerable<BaseEvent>?> mapper) receives an
otherwise-unmapped AIContent and returns AG-UI events to emit. Return null
to let the next mapper try the content.
MapInterrupt
MapInterrupt(Func<AIContent, AGUIInterrupt?> mapper) receives an
otherwise-unmapped AIContent and returns an AGUIInterrupt when the run needs
user input. The hosting layer emits RunFinishedEvent with an interrupt
outcome and stops the run. Return null to continue to the next mapper or to
MapContent.
InterruptRequestContent or tool approval content.
MapCall
MapCall(string toolName, Func<FunctionCallContent, IEnumerable<BaseEvent>> mapper) receives a matching FunctionCallContent and emits extra events after
the normal tool call start, args, and end events.
write_document, the UI can update a live document
preview before the server-side tool finishes.
MapResult
MapResult(string toolName, Func<FunctionResultContent, IEnumerable<BaseEvent>> mapper) receives a matching tool result and emits
extra events after the normal ToolCallResultEvent.
State mapping helpers
Two convenience methods cover the common state-management cases:MapResultAsStateSnapshot(toolName)emits aStateSnapshotEventMapResultAsStateDelta(toolName)emits aStateDeltaEvent
FunctionResultContent.Result to be a JsonElement. If
your tool returns another type, use MapResult and serialize the value
yourself.
RawRepresentation pass-through
For customIChatClient wrappers, setting RawRepresentation to an AG-UI
event is often simpler than defining a new AIContent type.
StateSnapshotEvent directly. If the raw event appears
before a run has started, the hosting layer emits RUN_STARTED first.
Chaining
You can register multipleMapContent or MapInterrupt callbacks. They are
tried in registration order, and the first non-null result wins.