Runs CrestApps.Core 2.0 AI chat as an AG-UI agent over SignalR or Server-Sent Events. Covers tool approvals, interrupts, resume, page context, shared state, and frontend tools.
Ships in crestapps-core. 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.
AG-UI is an event protocol between an agent and the app a person uses it in. A client starts a run with a RunAgentInput (thread, newest message, the tools it runs itself, shared state, page context) and the agent streams events back: RUN_STARTED, text, reasoning, tool calls and results, state changes, then RUN_FINISHED or RUN_ERROR. CrestApps runs the whole AI chat pipeline (profiles, orchestration, retrieval, tools, guardrails, session history) behind it.
| Transport | Used by |
|---|---|
The chat hub's RunAgent(JsonElement input, CancellationToken) method (SignalR, returns a ChannelReader<JsonElement> of events) | The CrestApps chat UI and widget (ai-chat.js), by default |
MapAGUIChat<THub>() (HTTP POST, Server-Sent Events) | Any AG-UI client: CopilotKit, the AG-UI client SDKs, your own app |
Both go through the same hub, so the hub's profile and session authorization, rate limits and guardrails apply to both.
AIChatHubCore<TClient> has RunAgent, and AddCoreAIOrchestration() (called by AddAISuite()) registers the shared state tool, the frontend tool provider and the page context handler.MapAGUIChat only when other AG-UI clients should reach your profiles over HTTP, and add authorization and rate limiting to the builder it returns..AsDestructive(), .AsExternal() or .AsSecurity() (or call .RequireApproval()). They only run after a person approves the call; where nobody can answer, the model gets a "was not run" result instead.ChatInteractionHubBase) and realtime voice conversations do not speak AG-UI yet; they keep the text-only stream.| Package | What it has |
|---|---|
CrestApps.Core.AI.AGUI | AGUIRunEventWriter (chat updates to AG-UI events), AGUIRunRequest (what a run input asks for: prompt, Resume, ClientToolResults, IsResume, TryGetApproval) and AGUIJson (SerializerOptions, SerializeEvent, DeserializeInput), on the MIT-licensed AG-UI .NET SDK (AGUI.Abstractions, AGUI.Formatting 1.0.1) |
CrestApps.Core.AI.Chat | AIChatHubCore.RunAgent, resumable runs, AGUIChatOptions and MapAGUIChat (namespace CrestApps.Core.AI.Chat.AGUI) |
CrestApps.AI.Resources (@crestapps/ai-chat-ui) | The chat UI's AG-UI client: tool cards, reasoning, approvals, page context, shared state (agui-activity.css styles) |
using CrestApps.Core.AI.Chat.AGUI;
builder.Services.AddCrestAppsCore(crestApps => crestApps
.AddAISuite(ai => ai
.AddOpenAI()
)
);
// Optional: how long a run keeps going after its connection drops (two minutes by default; TimeSpan.Zero ends it with the connection).
builder.Services.Configure<AGUIChatOptions>(options => options.DisconnectedRunTimeout = TimeSpan.FromMinutes(1));
var app = builder.Build();
app.MapHub<AIChatHub>("/hubs/ai-chat");
// Optional: POST api/ai/agui (AGUIEndpointRouteBuilderExtensions.DefaultPattern) with a RunAgentInput.
app.MapAGUIChat<AIChatHub>()
.RequireAuthorization();
services.AddCoreServices().AddCoreAIServices().AddCoreAIOrchestration();.IAIChatHubClient uses MapAGUIChat<THub, TClient>(pattern).Content-Type: application/json (a cross-site page cannot send that without a CORS preflight), so it calls DisableAntiforgery() and needs no token.RunAgent by default (protocol: 'agui'). Set protocol: 'legacy' in the chat configuration to keep the text-only SendMessage stream; a hub without RunAgent makes the UI fall back by itself.| Want | Add |
|---|---|
| Tool calls, reasoning, citations and shared state in the chat | Nothing: the chat UI and widget use AG-UI by default |
| Other AG-UI clients over HTTP | app.MapAGUIChat<AIChatHub>() |
| A person approves a tool before it runs | .AsDestructive(), .AsExternal(), .AsSecurity() or .RequireApproval() on the tool |
| The agent works on the page and keeps going on pages it opens | WebMCP page tools (crestapps-core-webmcp) |
| No page context sent to the model | sendPageContext: false in the chat configuration |
RunAgentInput member | What the chat does |
|---|---|
threadId | The chat session id. Empty starts a new session; its id comes back in RUN_STARTED |
runId | Echoed in RUN_STARTED and RUN_FINISHED |
messages | Only the newest user message is read (the server keeps the history), plus role: "tool" results of calls that waited for the client |
forwardedProps.profileId | The AI profile (required for a new message). forwardedProps.sessionProfileId names a session-level prompt profile |
context | Page context entries |
state | The shared state |
tools | Frontend tools the client runs itself |
resume | Answers to the previous run's interrupts |
| Event | When |
|---|---|
RUN_STARTED / RUN_FINISHED / RUN_ERROR | Every run. RUN_FINISHED has a success outcome (with pendingToolCallIds when frontend tools wait) or an interrupt outcome. Hub errors (unknown profile, refused session, rate limit) end with RUN_ERROR; a refused session start has the code session_start_rejected |
TEXT_MESSAGE_START / CONTENT / END | The answer. Its message id is the stored assistant message id; text written again after a tool call is a new message whose id ends with -1, -2, ... |
REASONING_START ... REASONING_END | Visible reasoning, when the model streams it |
TOOL_CALL_START / ARGS / END / RESULT | Every tool call and result (profile, MCP, agent, page and shared state tools). Results are cut to 4,000 characters |
STATE_SNAPSHOT / STATE_DELTA | The shared state and each change, as JSON Patch |
CUSTOM | crestapps.assistant_message, crestapps.references, crestapps.message_replaced (output checks replaced what streamed), crestapps.tool_calls_resolved, crestapps.tool_call_display (a call's title, such as the agent's title, right after its TOOL_CALL_END), crestapps.continues_on_next_page |
Tool calls are stored with the assistant message as a ChatTurnToolActivity (ToolCalls of ChatTurnToolCall: CallId, Name, DisplayText, Arguments, Result, Status, ApprovalRequestId, NeedsNoApproval, AgentName, AgentDisplayText, AgentCallId; AgentRuns, kept on the server only; ContinuesOnNextPage; HasPendingCalls). ChatTurnToolCallStatus is Requested, Completed, AwaitingApproval, Approved, Rejected or AwaitingClient. The session payload returns them (AIChatResponseMessageDetailed.ToolCalls) and the history replays calls and results to the model in later turns.
using CrestApps.Core.AI.Tooling;
builder.Services
.AddCoreAITool<DeleteArticleTool>(DeleteArticleTool.TheName)
.WithDescription("Deletes an article.")
.AsDestructive()
.Selectable();
AIChatResponseHandler sets AICompletionContextKeys.ToolApprovalSupported, ToolMaterializationOptions.SupportsToolApproval is true, and the tool is wrapped in ApprovalRequiredAIFunction.interrupt outcome naming each call and asking for { "approved": true | false }, and the paused message is stored with the calls AwaitingApproval.
When the model calls several tools at once and one needs approval, nothing in the batch runs before the person answers, but only the calls that need an approval get an interrupt. The others are marked where the request is made (ToolApprovalRequests.MarkCallsThatNeedNoApproval, NeedsNoApprovalProperty), stored as Requested with NeedsNoApproval, and run on resume whatever the person answered. If such a call's tool requires an approval by the time the run resumes, it is rejected with ToolApprovalRequests.NowRequiresApprovalReason. The client never decides this.<button> it rendered in that call's .ai-chat-agui-approval row while the call is waiting; the answer sanitizer strips every data-agui-* attribute from model output, so an answer cannot forge an approval.resume. Approved calls run, rejected ones never run and the model is told, and an interrupt the client did not answer counts as rejected.{
"threadId": "<session id>",
"runId": "<new run id>",
"messages": [],
"resume": [{ "interruptId": "<interrupt id>", "status": "resolved", "payload": { "approved": true } }],
"forwardedProps": { "profileId": "<profile id>" }
}
GetResumeInProgressMessage() and runs nothing. A host with several instances needs sticky routing for a session.SendMessage stream, chat interactions, realtime sessions, the Claude and Copilot orchestrators, workflows, channels, background work) still offer the tool, but a call returns a "was not run" result the model relays; each counts on crestapps.core.ai.tool.denied with reason=approval. A profile's AIToolApprovalSettings can run approval kinds without asking (see crestapps-core-custom-tools).IToolRegistryProvider sets ToolRegistryEntry.RequiresApproval on its own entries. WebMCP tools marked consequentialHint require approval in an AG-UI run unless the profile has AllowConsequentialPageTools. Resuming a run counts against the per-message rate limit (EvaluateMessageRateLimitAsync), once per resume.On the default orchestrator, a tool of an agent that requires an approval asks the same person through the assistant's run:
ChatTurnToolActivity.AgentRuns (ChatTurnAgentRun, tool results up to 16,000 characters).interrupt. Its message names the agent (by DisplayText when it has one) and the tool; its metadata has agentName, agentDisplayText, agentToolCallId, toolName and arguments. The agent's tool call streams too, and the call to the agent has no result yet.resume calls the agent again. It continues where it stopped: earlier calls are not repeated, an approved call runs, a rejected one is reported to the agent. A further approval pauses again.The chat UI shows the agent's call with Allow and Deny and the question aguiAgentApprovalPrompt (default Allow {0} to do this?). The orchestrator adds a ToolApprovalRequestContent per waiting call with AgentToolApprovalProperties; AGUIRunEventWriter turns it into the interrupt and exposes AgentRuns. AGUIRunEventWriter.ToolDisplayTextResolver supplies call titles (AIChatHubCore reads the agents' DisplayText); a label in aguiToolLabels still wins. The Claude and Copilot orchestrators cannot pause, so their agents get the "was not run" result.
The chat sends the page title, address and the user's last text selection with each message. Scripts add their own entries:
window.crestAppsAGUI.registerContextProvider(() => ({
description: 'Record being edited',
value: `Article #${articleId}: ${document.querySelector('#Title').value}`,
}));
At most 20 entries of 2,000 characters reach the model (and at most 32,000 characters of shared state), in the system message as data (ClientContextOrchestrationHandler). On the server they are ChatResponseHandlerContext.ClientContext (ChatClientContextEntry: Description, Value) and AICompletionContextKeys.ClientContext. A script that runs before ai-chat.js can preset window.crestAppsAGUI = { _contextProviders: [...], _stateProvider: {...} }.
window.crestAppsAGUI.registerStateProvider({
get: () => ({ orderDetails: { giftMessage: gift.value, deliveryDate: date.value } }),
apply: (state, delta) => {
gift.value = state.orderDetails?.giftMessage ?? '';
date.value = state.orderDetails?.deliveryDate ?? '';
},
});
When a run carries state, the model sees it and gets the update_shared_state tool (UpdateSharedStateFunction.FunctionName), which applies JSON Patch add, replace and remove operations through JsonPatchApplier to a ChatSharedState (Value, OnChangedAsync). Each change streams as STATE_DELTA; the chat calls apply and fires a crestapps:agui-state event on document. The server does not store the state; it uses what each run sends (ChatResponseHandlerContext.SharedState, AICompletionContextKeys.SharedState).
Tools in RunAgentInput.tools are offered to the model as declarations (ClientToolRegistryProvider, ChatResponseHandlerContext.ClientTools, AICompletionContextKeys.ClientTools). A call ends the run with RUN_FINISHED whose pendingToolCallIds name the calls; the client runs them and sends role: "tool" messages with the toolCallId in its next run:
{
"threadId": "<session id>",
"runId": "<new run id>",
"messages": [{ "id": "t1", "role": "tool", "toolCallId": "call_123", "content": "Sunny, 21 °C" }],
"tools": [{ "name": "get_weather", "description": "Gets the weather in a city.", "parameters": { "type": "object", "properties": { "city": { "type": "string" } } } }],
"forwardedProps": { "profileId": "<profile id>" }
}
The CrestApps chat UI does not use frontend tools; page tools reach it through WebMCP instead.
With WebMCP page tools (AddWebMcp(webMcp => webMcp.AddPageTools<AIChatHub>()), Allow page tools on the profile, WebMCP scripts before the chat scripts), page_navigate answers first and opens the page 400 ms later. In a run on the chat hub that ends the turn:
ChatTurnToolActivity.ContinuesOnNextPage and the run sends crestapps.continues_on_next_page.forwardedProps.continueRun = true and forwardedProps.continuePage (title and address).ContinueAGUIRunAsync clears the mark and tells the model which page loaded (GetContinueOnNextPagePrompt, overridable). At most five pages chain in a row; the user's next message starts a new chain. HTTP runs have no page to continue on.A tool that ends the turn this way sets AICompletionContextKeys.EndTurnAfterToolCalls in AIInvocationScope.Current.Items when the completion context carries AICompletionContextKeys.ContinuesOnNextPage. A run whose connection dropped keeps going for AGUIChatOptions.DisconnectedRunTimeout so its answer is saved; a user Stop ends it at once, and the hub then sends the session to its group.
AIChatHubCore<TClient> virtuals for AG-UI: RunAgent, HandleRunAgentAsync(AGUIChatTurn, IServiceProvider, CancellationToken), ResumeAGUIRunAsync, ContinueAGUIRunAsync, GetContinueOnNextPagePrompt(string loadedPage), GetInvalidRunInputMessage(), GetNothingToResumeMessage(), GetNothingToContinueMessage(), GetResumeInProgressMessage(). ProcessGeneratedPromptAsync (template prompts) and ProcessUtilityAsync (Utility profiles) stream an AG-UI run chunk by chunk too, so the whole reply shows.
Clients from IAIClientFactory stream tool calls through FunctionInvokingChatClient; the Azure OpenAI client streams FunctionCallContent and FunctionResultContent on Chat Completions and Responses, pauses for approval-required tools (also in CompleteAsync without streaming) and replays stored calls; a resumed Responses API run sends the paused turn's calls and results. A completion client with its own tool loop calls AIToolLoop.ShouldEndTurn(invocation) after each round and reads a call's id with AIToolInvocation.GetCallId(arguments). NamedAICompletionClient passes tool result messages to the provider and drops results whose calls a past-message limit cut off.
Both sample hosts map MapAGUIChat<AIChatHub>() and register sendEmail with .AsExternal(), so the chat asks before it sends, also inside an agent. On the WebMCP Playground with a profile that allows page tools, "Place the order" waits for Allow or Deny (store.place_order is consequential), and "Write a gift message for my sister" fills the shared Order details card.
curl -N -X POST https://localhost:5100/api/ai/agui -H "Content-Type: application/json" \
-d '{"threadId":"","runId":"r1","messages":[{"id":"m1","role":"user","content":"Hello"}],"tools":[],"context":[],"forwardedProps":{"profileId":"<profile id>"}}'
protocol: 'legacy', or the page loads an older ai-chat.js that has no AG-UI client.SendMessage, a chat interaction, realtime, an agent called over MCP, background, the Claude or Copilot orchestrator); check crestapps.core.ai.tool.denied with reason=approval.RUN_ERROR with session_start_rejected: the session-start rate limit refused a new session.415/400 from MapAGUIChat: send Content-Type: application/json with a valid RunAgentInput.See crestapps-core-chat-interactions for the hubs and chat UI, crestapps-core-custom-tools for tool registration, and crestapps-core-webmcp for page tools.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/crestapps-core:crestapps-core-ag-uifrom crestapps-core
npx claudepluginhub crestapps/crestapps.agentskills --plugin crestapps-core51 skills in this plugin
/crestapps-core-a2aSkill for Agent-to-Agent (A2A) protocol support in CrestApps.Core on the A2A 1.0 SDK. Covers AddA2AClient and AddCoreAIA2AClient with Entity Framework Core or YesSql connection stores, A2AConnection and A2AConnectionMetadata authentication, AIProfileA2AMetadata, the agent card cache and A2AToolRegistryProvider, the listAvailableAgents, findAgentForTask and findToolsForTask tools, building an A2A host with IAgentHandler, A2AServer, ITaskStore and MapA2A, A2A 1.0 agent cards with supportedInterfaces published at /.well-known/agent-card.json, A2AHostOptions authentication and ExposeAgentsAsSkill, system agents exposed through the host, and upgrading from the 0.3 SDK./crestapps-core-ai-agentsSkill for AI agents in CrestApps.Core 2.0, specialized AIProfile records of type Agent that the primary model invokes as tools. Covers creating agent profiles with AgentMetadata availability (OnDemand or AlwaysAvailable), linking them with AgentInvocationMetadata, how AgentProxyTool runs an agent with tools disabled or through the orchestrator when AllowToolInvocation is set, the AgentInvocationDepth recursion guard, never offering an agent to itself (RunningAgentName), tools of an agent that require an approval and pause the agent, deployment inheritance and the chat slot, code-defined and system agents through IAIProfileProvider including the Tabular Data, PDF, Presentation and Word agents, chat-specific agents that read AIInvocationScope, exposing agents to MCP clients with McpServerOptions Agents and ExposeAllAgents, and SubAgent usage labels. Use it when delegating work to sub-agents, adding a framework-managed agent, publishing an agent over MCP, or troubleshooting an agent the model does not call.Other plugins' skills for the same job