/ceh-ag-ui:add-human-approvalfrom ceh-ag-ui
Load this skill when an AG-UI agent must stop for the user's decision before an irreversible or costly step (a delete, a payment, a send), using AG-UI 1.0 interrupts and resume. Trigger on "ask the user before", "human in the loop", "approval step".
Ships in ceh-ag-ui. 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.
An approval is a pause the protocol knows about, not a chat message asking "are you sure?". The
agent ends the run with an interrupt. The canvas shows a card whose look it controls. The user's
decision comes back as a resume entry on the next run, and the agent acts only on that.
The work is done when the five checks in step 3 pass.
Keep a server-side record of what each pending interrupt guards. Act only on a resume entry whose id is in that record, then remove it, so each approval can be used once. Never act on an id the server did not issue, and never on an expired one.
Mock-agent handlers (agent/main.py; import Interrupt and RunFinishedInterruptOutcome from
ag_ui.core). respond checks run.resume first, and triggers ask_approval when the text
mentions "delete":
PENDING: dict[str, str] = {} # interrupt id -> the action it guards
def ask_approval(run: RunAgentInput, action: str) -> list[BaseEvent]:
interrupt = Interrupt(
id=str(uuid.uuid4()),
reason="confirmation",
message=f"Allow the agent to {action}?",
response_schema={
"type": "object",
"properties": {"approved": {"type": "boolean"}},
"required": ["approved"],
},
)
PENDING[interrupt.id] = action
outcome = RunFinishedInterruptOutcome(interrupts=[interrupt])
return [
RunFinishedEvent(thread_id=run.thread_id, run_id=run.run_id, outcome=outcome)
]
def resumed(run: RunAgentInput) -> list[BaseEvent]:
events: list[BaseEvent] = []
for entry in run.resume or []:
action = PENDING.pop(entry.interrupt_id, None)
if action is None:
events += say("That request is no longer waiting for approval.")
elif (
entry.status == "resolved" and (entry.payload or {}).get("approved") is True
):
events += say(f"Done: {action}.")
else:
events += say(f"Not done: {action}.")
return events
The template mock sends RUN_FINISHED itself unless a handler's last event is already one. That
lets ask_approval end the run with the interrupt outcome.
With a real model (the ceh-ag-ui:build-ag-ui-agent server), mark the sensitive backend tools
as needing approval. When the model calls one, do not execute it. Store the call under a new
interrupt id and end the run with the interrupt outcome, leaving the tool_use unanswered. On
resume, execute it (approved) or return an is_error tool result saying the user declined
(rejected or cancelled). That result goes in the same user turn as any other results for that
model turn, and the loop then continues as usual.
In useAgent.ts, add the interrupt handling to the existing drive loop and send:
import { isInterruptExpired, type Interrupt } from "@ag-ui/client";
const [interrupts, setInterrupts] = useState<Interrupt[]>([]);
const [decisions, setDecisions] = useState<Record<string, boolean>>({});
// in drive(), right after `params = {};`:
if (agent.pendingInterrupts.length > 0) break; // waiting on the user: don't re-run
// in drive()'s finally:
setInterrupts([...agent.pendingInterrupts]);
// Every open interrupt must be answered in one resume, so decisions are collected first.
async function decide(id: string, approved: boolean) {
const next = { ...decisions, [id]: approved };
if (agent.pendingInterrupts.some((i) => !(i.id in next)))
return setDecisions(next);
setDecisions({});
await drive({
resume: agent.pendingInterrupts.map((i) =>
isInterruptExpired(i)
? { interruptId: i.id, status: "cancelled" as const }
: {
interruptId: i.id,
status: "resolved" as const,
payload: { approved: next[i.id] },
},
),
});
}
// at the top of send(): typing instead of answering cancels what was pending,
// then the new message goes out as its own run.
if (agent.pendingInterrupts.length > 0) {
setDecisions({});
await drive({
resume: agent.pendingInterrupts.map((i) => ({
interruptId: i.id,
status: "cancelled" as const,
})),
});
}
// return interrupts, decisions and decide from the hook
The approval card is a fixed component, not a catalogue entry. The agent supplies only the question, and the card renders it as text:
// src/ApprovalCard.tsx
import type { Interrupt } from "@ag-ui/client";
import { Button } from "@ui-sdk/react/button";
import { buttonOutlineSm, buttonPrimary, card, eyebrow } from "./ui";
const buttonPrimarySm = buttonPrimary.replace(
"h-8 px-2.5",
"h-7 px-2.5 text-[0.8rem]",
);
export function ApprovalCard({
interrupt,
decided,
onDecide,
}: {
interrupt: Interrupt;
decided?: boolean;
onDecide: (approved: boolean) => void;
}) {
const labelId = `approval-${interrupt.id}`;
return (
<section
className={`${card} mx-4 mb-2 border-l-2 border-primary`}
role="group"
aria-labelledby={labelId}
aria-current={decided === undefined ? "true" : undefined}
>
<p className={eyebrow}>Approval needed</p>
<p id={labelId}>{interrupt.message ?? interrupt.reason}</p>
{decided === undefined ? (
<div className="flex gap-2">
<Button className={buttonPrimarySm} onClick={() => onDecide(true)}>
Approve
</Button>
<Button className={buttonOutlineSm} onClick={() => onDecide(false)}>
Reject
</Button>
</div>
) : (
<p className="text-muted-foreground">
{decided ? "Approved" : "Rejected"}, waiting for the others.
</p>
)}
</section>
);
}
Render the cards in the chat panel between the messages and the input, where the user is already
looking:
{interrupts.map((i) => <ApprovalCard key={i.id} interrupt={i} decided={decisions[i.id]} onDecide={(ok) => void decide(i.id, ok)} />)}.
The card's spacing in the chat panel is in its own utilities, so app.css needs no new rule.
run 1 → … RUN_FINISHED { outcome: { type: "interrupt", interrupts: [ { id, reason, message, responseSchema?, expiresAt? } ] } }
client: agent.pendingInterrupts = [...] (the canvas shows one card per interrupt)
run 2 ← RunAgentInput.resume = [ { interruptId, status: "resolved", payload: { approved } } | { interruptId, status: "cancelled" } ]
resume. @ag-ui/client throws
"Thread has N pending interrupt(s) not addressed by resume" otherwise. Collect a decision for
every card, then resume once.resolved + { approved: false } for an explicit Reject, and cancelled when the user
never answered: they typed something else, or the interrupt expired. Send cancelled, never
resolved, for an interrupt past its expiresAt (check with isInterruptExpired).border-l-2 border-primary with aria-current is the "this needs you"
signal. Its colour comes from the theme's --primary, never from the interrupt. If the agent
needs a severity, make it a semantic field that the card maps to token utilities, as tone does
in the catalogue.message ("delete 3 archived records"), because a vague "Proceed?" gets approved without being
read.role="group" with aria-labelledby, so a screen reader announces the question with the
buttons. Use role="alert" only when the run truly cannot continue without it.ceh-ag-ui:add-live-state-panel.ceh-ag-ui:add-canvas-component.ceh-ag-ui:build-ag-ui.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub cheneeheng/ceh-claude-code-library --plugin ceh-ag-ui5 skills in this plugin
/add-canvas-componentLoad this skill when adding or changing a component in an AG-UI canvas catalogue: a card, chart, or form the agent can place on screen. Trigger on "add a component the agent can show", "let the agent render a <thing>", or an edit under `catalogue/`./add-live-state-panelLoad this skill when adding a live panel to an AG-UI canvas: one fixed area the agent keeps updating while it works, wired from STATE_SNAPSHOT and STATE_DELTA. Trigger on "show the agent's progress live", "shared state", "sync state with the agent"./build-ag-uiLoad this skill when starting a generative-UI frontend for an AG-UI agent: a canvas where the agent answers by placing components from a catalogue. Trigger on "build a UI with AG-UI", "generative UI for my agent", or @ag-ui/client with no canvas yet.Other plugins' skills for the same job