AGUI.Client separates the chat client from the wire protocol with
IAGUITransport. AGUIChatClient builds a RunAgentInput, passes it to the
transport, and consumes the resulting AG-UI BaseEvent stream.
public interface IAGUITransport{ IAsyncEnumerable<BaseEvent> SendAsync( RunAgentInput input, CancellationToken cancellationToken);}
The input contains the AG-UI thread id, run id, message history, tools, state,
context, forwarded properties, and any resume entries for interrupted runs. The
output is the ordered AG-UI event stream described in the
event reference.
The AGUIChatClientOptions(HttpClient, endpoint) constructor creates the
built-in HTTP transport internally:
using AGUI.Client;using Microsoft.Extensions.AI;using HttpClient httpClient = new();IChatClient client = new AGUIChatClient(new(httpClient, "https://api.example.com/agent"));
The built-in transport sends the request as an HTTP POST whose body is the
serialized RunAgentInput. The response is read as Server-Sent Events, and each
SSE item is deserialized as a BaseEvent.
AGUIHttpTransport is the built-in HTTP+SSE implementation used by the
AGUIChatClientOptions(HttpClient, endpoint) constructor. Most applications do
not need to instantiate a transport directly.
The transport returns AG-UI protocol events. AGUIChatClient then converts them
to ChatResponseUpdate values:
RUN_STARTED establishes the AG-UI thread id and run id.
Text message events become streamed text updates.
Tool call events become MEAI function call content.
Interrupt outcomes become ToolApprovalRequestContent or
InterruptRequestContent.
RUN_ERROR becomes an ErrorContent update. Its message maps to
ErrorContent.Message, and its optional code maps to
ErrorContent.ErrorCode. When the event carries partial usage, the client
also emits UsageContent updates so ChatResponse.Usage includes the tokens
consumed before the failure.
ResponseId on each update corresponds to the AG-UI run id. The client clears
ConversationId before yielding updates so callers continue sending full
message history to stateless AG-UI servers.