/ag-ui-dotnet:agui-dotnet-shared-statefrom ag-ui-dotnet
Keeps structured state in sync between an AG-UI agent and its .NET client, with client seeding state and server streaming snapshots/deltas.
Ships in ag-ui-dotnet. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Goal: keep a structured object (a form, a document, a plan, a recipe) in sync between the client and the agent — the client provides the current state, the agent updates it, and the new state streams back next to the assistant's text.
State travels on the wire inside RunAgentInput.State (inbound) and as StateSnapshotEvent / StateDeltaEvent (outbound). In Microsoft.Extensions.AI terms, inbound state rides on the request's raw representation and outbound state rides on a ChatResponseUpdate's raw representation.
Send the starting state with the request, and watch for snapshots in the response:
using System.Text.Json;
using AGUI.Abstractions;
using Microsoft.Extensions.AI;
var initialState = JsonSerializer.SerializeToElement(new
{
recipe = new { title = "", ingredients = Array.Empty<string>(), steps = Array.Empty<string>() }
});
var options = new ChatOptions
{
RawRepresentationFactory = _ => new RunAgentInput { State = initialState },
};
var messages = new List<ChatMessage> { new(ChatRole.User, "Suggest an Italian pasta recipe") };
JsonElement? latestState = null;
await foreach (var update in client.GetStreamingResponseAsync(messages, options))
{
if (update.RawRepresentation is StateSnapshotEvent snapshot)
{
latestState = snapshot.Snapshot; // the full updated state object
}
Console.Write(update.Text); // the assistant's summary streams as usual
}
State updates are content-less — they arrive on update.RawRepresentation, not as update.Text.
Add a DelegatingChatClient to the pipeline that reads RunAgentInput.State, produces the new state, and yields it as a StateSnapshotEvent:
using System.Runtime.CompilerServices;
using System.Text.Json;
using AGUI.Abstractions;
using AGUI.Server;
using Microsoft.Extensions.AI;
internal sealed class RecipeStateChatClient(IChatClient inner, JsonSerializerOptions jso)
: DelegatingChatClient(inner)
{
public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
IEnumerable<ChatMessage> messages,
ChatOptions? options = null,
[EnumeratorCancellation] CancellationToken ct = default)
{
if (options?.TryGetRunAgentInput(out var input) is true
&& input!.State is { ValueKind: JsonValueKind.Object } incoming)
{
var newState = await BuildStateAsync(messages, incoming, ct); // your logic / an LLM call
yield return new ChatResponseUpdate
{
RawRepresentation = new StateSnapshotEvent
{
Snapshot = JsonSerializer.SerializeToElement(newState, jso.GetTypeInfo(typeof(AgentState))),
},
};
}
await foreach (var update in base.GetStreamingResponseAsync(messages, options, ct))
{
yield return update; // the assistant's text summary
}
}
}
Register it after function invocation:
builder.Services.AddChatClient(/* provider IChatClient */)
.UseFunctionInvocation()
.Use((inner, sp) => new RecipeStateChatClient(
inner, sp.GetRequiredService<IOptions<JsonOptions>>().Value.SerializerOptions));
TryGetRunAgentInput recovers the originating RunAgentInput from the ChatOptions the endpoint built — that is how the server-side chat client reaches State (and thread id, tools, …) without endpoint plumbing.
StateSnapshotEvent carries the entire state object. Simple and self-correcting; send it when the whole state changed or you want to resync.StateDeltaEvent carries a JSON Patch (RFC 6902) array of changes against the last known state. Use it for small, frequent edits to a large object to avoid resending everything. The client applies the patch to its copy.State objects are serialized through the source-generated context. Put each state type in a JsonSerializerContext, register it on the host (ConfigureHttpJsonOptions(o => o.SerializerOptions.TypeInfoResolverChain.Add(...))), and serialize through jso.GetTypeInfo(typeof(T)) rather than reflection.
StateSnapshotEvent / StateDeltaEvent arrive on content-less updates, which the non-streaming aggregation drops. Read state inside the await foreach over the streaming response.StateDeltaEvent patches the client's last known state; if the client missed the prior snapshot the patch fails to apply. Start a session (or resync) with a full StateSnapshotEvent, then send deltas.State and the run streams back at least one StateSnapshotEvent whose Snapshot reflects the agent's changes.update.RawRepresentation yields the StateSnapshotEvent while update.Text yields the summary.What SKILL.md sets; muted values are Claude Code's defaults
Claude Code refuses to install this plugin
.claude-plugin/plugin.json: skills: Invalid string: must start with "./"
Checked against Claude Code 2.1.332's install rules. The listing below is what the repository ships; Claude Code cannot install it as published.
9 skills in this plugin
/agui-dotnet-client-toolsExpose client-side (frontend) tools to an AG-UI agent with the AG-UI .NET SDK — C# functions that run in the CLIENT app (read local state, GPS, UI, device APIs), where the client executes the call and returns the result so the run continues. USE FOR: declaring an AIFunction in the client and passing it via ChatOptions.Tools to AGUIChatClient; having the client execute a tool the model requested and feed the result back automatically; understanding why no UseFunctionInvocation is needed on the client (AGUIChatClient already invokes functions); what the server must do (UseFunctionInvocation + TerminateOnUnknownCalls) so it forwards an unknown/client tool instead of erroring. DO NOT USE FOR: tools that run on the server/backend (use agui-dotnet-server-tools); pausing for human approval/input before acting (interrupts / human-in-the-loop); plain chat (use agui-dotnet-streaming-chat); shared state, generative UI, multimodal, or protobuf.
/agui-dotnet-human-in-the-loopPause an AG-UI agent run for a human, then resume it, with the AG-UI .NET SDK — gate a sensitive tool behind explicit approval, or interrupt a run to collect free-form input from the user before continuing. USE FOR: requiring human approval before a tool executes (ApprovalRequiredAIFunction + ToolApprovalRequestContent/ToolApprovalResponseContent, resume by appending the request + CreateResponse(approved)); pausing a run to ask the user a question and resuming with their answer (InterruptRequestContent / InterruptResponseContent, RunAgentInput.Resume); how a paused run surfaces as RUN_FINISHED outcome=interrupt and how the client detects and answers it. DO NOT USE FOR: tools that run without approval on the server (use agui-dotnet-server-tools) or in the client (use agui-dotnet-client-tools); plain chat (use agui-dotnet-streaming-chat); shared state, generative UI, multimodal, or protobuf.
Other plugins' skills for the same job