/ceh-ag-ui:build-ag-ui-agentfrom ceh-ag-ui
Load this skill when building or fixing the agent server behind an AG-UI canvas: an endpoint that calls an LLM with the canvas's frontend tools and streams AG-UI events over SSE. Trigger on "build the AG-UI server", "connect Claude to my canvas", "replace the mock agent".
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.
Read when SKILL.md points to them.
The canvas owns what the user sees, and this server owns what the model sees. Most bugs in an AG-UI backend come from mixing the two up: building the model's history out of the UI's messages, or running a tool that belongs to the canvas. The work is done when every check in Procedure step 3 passes.
Start from ${CLAUDE_SKILL_DIR}/assets/agent-server/ (main.py, pyproject.toml). Copy it to
server/ beside the canvas's web/, keeping agent/ (the mock, still the fastest way to test a
component), and run uv run uvicorn main:app --port 8000 from server/, with the mock stopped.
The canvas's Vite proxy already points at that port, and AGENT_ORIGIN overrides it. It uses
Claude through the official anthropic SDK by default, with AGENT_MODEL defaulting to
claude-opus-5-5. For a different provider, keep the structure in the Rules below and swap only
run_claude.
This is for a tool the server runs itself, such as a database lookup the model needs before choosing a component:
async def lookup_orders(args: dict[str, Any]) -> str:
region = args.get("region")
if not isinstance(region, str): # eager streaming: the API did not validate this
return "error: region must be a string"
return json.dumps(await db.orders_by_region(region))
BACKEND_TOOLS["lookup_orders"] = (
"Order totals for one region. Call before showing order data.",
{
"type": "object",
"properties": {"region": {"type": "string"}},
"required": ["region"],
},
lookup_orders,
)
The loop runs it, streams TOOL_CALL_RESULT, and continues without a new run from the canvas. An
action with side effects the user should confirm first goes through
ceh-ag-ui:add-human-approval, not straight into BACKEND_TOOLS.
uv run python -c "import main" succeeds with no credentials, because the import makes no
network call.show_table and then gets a short
acknowledgement.client.beta.messages.stream
that yields content_block_* events and a final message with stop_reason: "tool_use". Then
confirm that each request's messages starts with the previous request's messages.THREADS. The template keeps them in memory, in one process (marked less-code:). A
restart loses every conversation, and a second replica sees none of them. Store them keyed by
threadId in Redis or Postgres. Store the transcript exactly as it was appended, because a
thinking block changed on the way through storage is invalid.CORSMiddleware, never * alongside credentials.threadId is
client-chosen, so a guessable id lets anyone read or continue someone else's conversation.POST /agent RunAgentInput{threadId, runId, messages, tools, state, resume}
→ RUN_STARTED
→ TEXT_MESSAGE_START / CONTENT… / END (model text, streamed)
→ TOOL_CALL_START / ARGS… / END (model tool call, streamed)
→ TOOL_CALL_RESULT (only for tools the SERVER ran)
→ RUN_FINISHED or RUN_ERROR (exactly one, always last)
RUN_FINISHED or RUN_ERROR. A stream that simply stops
leaves the canvas spinning. The template wraps the whole loop, so any exception becomes
RUN_ERROR, and nothing follows it.content_block_start, then delta, then stop). Take each index's block kind from its
content_block_start event.Thread.transcript keyed by threadId, appends
the final content of each response unchanged, and folds in only unseen AG-UI message ids.
Those are new user text and the canvas's tool results.run.tools holds the catalogue. Send
them to the model as tools. When the model calls one, stream the call and end the run. The
canvas validates the call, renders it, and starts the next run with a role: "tool" message.TOOL_CALL_RESULT, and hold its
tool_result (Thread.held). Send it together with the canvas's results on the next run.
Splitting one turn's results across two user messages is rejected by the API.tool_result for every
call in Thread.awaiting that has no answer. Otherwise the transcript has an unpaired
tool_use and every later request fails.system and developer messages from the
client, and ignore assistant messages too, since the server produced those. The system prompt
lives on the server. Treat run.tools descriptions and schemas as untrusted input. They shape
what the model does, so a deployed server should accept only the catalogue it expects, for
example by comparing tool names against an allowlist.The template follows claude-api defaults. When changing them, check that skill's current guidance
rather than recalling it:
max_tokens=64000, effort: "medium" set explicitly. The default effort
differs by model. Use low for a snappier chat and high for hard analysis.eager_input_streaming: True on every tool, so arguments stream into TOOL_CALL_ARGS while
they are generated. The trade-off is that the API no longer validates the input. The canvas
validates frontend calls with zod, and backend handlers must validate their own input.fallbacks: "default" with the server-side-fallback-2026-07-01 beta, so a policy refusal
is retried on a fallback model. echoable() keeps only the text from before a mid-output
fallback block, as the API requires. A final refusal becomes RUN_ERROR with
code: "refusal".max_tokens with a tool call means the arguments were
truncated, so end with RUN_ERROR and do not hand them to the canvas. pause_turn means loop
again. tool_use means the tool rules above apply.tool_choice. Current Claude models reject any and tool. Steer toward
components in the system prompt instead.ceh-ag-ui:add-human-approval.ceh-ag-ui:add-live-state-panel.ceh-ag-ui:build-ag-ui.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
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-human-approvalLoad 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"./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".