From ag-ui-dotnet
Configures AG-UI .NET client or server to use protobuf binary transport instead of SSE, with automatic fallback. Useful for reducing bandwidth in AG-UI event streams.
How this skill is triggered — by the user, by Claude, or both
Slash command
/ag-ui-dotnet:agui-dotnet-protobufThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Goal: carry the AG-UI event stream as compact protobuf binary instead of Server-Sent Events, with automatic fallback to SSE when one side doesn't support it.
Goal: carry the AG-UI event stream as compact protobuf binary instead of Server-Sent Events, with automatic fallback to SSE when one side doesn't support it.
Transport is negotiated by content type: the client advertises the formats it accepts (in preference order) on the Accept header, and the server replies in the first format it also supports. Nothing above the transport changes — AGUIChatClient, messages, and your endpoint logic are identical to SSE.
dotnet add package AGUI.Protobuf # ProtobufEventStreamFormatter
Client apps also need AGUI.Client (for AGUIEventStreamHandler); server apps also need AGUI.Formatting (for SseEventStreamFormatter) and AGUI.Server.
Wrap your HttpClient in an AGUIEventStreamHandler configured with the formatters in preference order. The handler advertises them on Accept and decodes whatever the server returns:
using AGUI.Client;
using AGUI.Formatting;
using AGUI.Protobuf;
using Microsoft.Extensions.AI;
var handler = new AGUIEventStreamHandler(
[new ProtobufEventStreamFormatter(), new SseEventStreamFormatter()])
{
InnerHandler = new HttpClientHandler(),
};
using var httpClient = new HttpClient(handler);
IChatClient client = new AGUIChatClient(new(httpClient, "http://localhost:5013"));
Protobuf is listed first, so the client prefers it; if the server only speaks SSE, the handler transparently decodes SSE instead. Switching transports is purely a matter of reordering (or trimming) this formatter list.
Register both formatters and pick one per request from the Accept header, defaulting to SSE:
using System.Linq;
using AGUI.Abstractions;
using AGUI.Formatting;
using AGUI.Protobuf;
using AGUI.Server;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Options;
using JsonOptions = Microsoft.AspNetCore.Http.Json.JsonOptions;
builder.Services.AddSingleton<IAGUIEventStreamFormatter, SseEventStreamFormatter>();
builder.Services.AddSingleton<IAGUIEventStreamFormatter, ProtobufEventStreamFormatter>();
var app = builder.Build();
app.MapPost("/", async (
[FromBody] RunAgentInput input,
IChatClient chatClient,
IEnumerable<IAGUIEventStreamFormatter> formatters,
IOptions<JsonOptions> jsonOptions,
HttpContext http,
CancellationToken ct) =>
{
var accept = http.Request.Headers.Accept.ToString();
var formatter =
formatters.FirstOrDefault(f => f is ProtobufEventStreamFormatter
&& accept.Contains(f.MediaType, StringComparison.OrdinalIgnoreCase))
?? formatters.First(f => f is SseEventStreamFormatter);
var ctx = input.ToChatRequestContext(jsonOptions.Value.SerializerOptions);
var updates = chatClient.GetStreamingResponseAsync(ctx.Messages, ctx.ChatOptions, ct);
var events = updates.AsAGUIEventStreamAsync(ctx, ct);
http.Response.ContentType = formatter.MediaType;
http.Response.Headers.CacheControl = "no-cache";
await formatter.WriteAsync(events, http.Response.Body, ct);
});
Protobuf is selected only when the client explicitly accepts its media type, so a default SSE client keeps working unchanged.
Content-Type, don't assume.@ag-ui/proto byte-for-byte. Always read and write through ProtobufEventStreamFormatter; don't decode the stream yourself.Content-Type is the protobuf media type (ProtobufEventStreamFormatter.MediaType), and the body is binary, not data: text frames.npx claudepluginhub ag-ui-protocol/ag-ui --plugin ag-ui-dotnetBootstraps an AG-UI .NET streaming-chat client and server. Installs NuGet packages, configures AGUIChatClient or a hosted endpoint, and runs multi-turn conversations with stateless or session-persisted agents.
Implements the AG-UI protocol for agent-to-frontend communication via SSE events. Covers event types, state sync, tool calls, and human-in-the-loop flows for custom agent backends.
Choosing inter-service protocols. REST vs gRPC vs SignalR vs SSE decision matrix, tradeoffs.