chain-rdeveloper portal
build

Chat commands

A chat command runs a named workflow from an agent's chat, instead of leaving the turn to the agent's dynamic graph:

/execute skill research-brief Keep it to one page

with the topic field of its form set to "UK AI regulation" runs the built-in Research brief on that topic, with those instructions. The skill's whole graph runs in order, in the agent's persona and on its model. The turn is governed, ledgered and stored like any other.

The grammar

Every command has one shape:

/<action> <kind> <target> [request]
PartMeaningExample
kindthe kind of resource it acts onskill
targetthat resource's slugresearch-brief
requesteverything after: what to work on, line breaks keptKeep it to one page

A target can also take a form: named, typed values that travel beside the text as command_inputs, never inside it. For a skill, the form is the skill's own Run form.

A new workflow is a new (action, kind) pair, never a new syntax. So a future /execute agent … or /search knowledge … would read the way /execute skill … does.

  • Case and spacing don't matter, and the request keeps its line breaks.

  • Text whose first word is not a known action is not a command. For example, /usr/bin holds programs, right? goes to the agent unchanged.

  • The request is required only where the form has no fields. With fields, it is optional additional instructions.

  • A known action that can't run as written is refused, with the reason and the nearest command lines. That covers a missing or unknown kind, an unknown target, a missing request, a required field left out, a value that can't be read, and values sent to a target that takes no form. The WebSocket sends one error frame with code: "command", suggestions and fields (what was wrong with each value); the batch prompt answers 422 with the same detail. Nothing runs, and nothing is stored.

What there is

CommandTargetsWhat runs

/execute skill

  • The skill runs whether or not the agent holds it. Running a skill is using it, and the workspace already allows that.

  • It runs whether or not the chat's skill graph toggle is on. The command is explicit.

  • It answers as the agent. It uses the agent's persona, and its model for every node that doesn't pin one; see skills.md.

  • A rule scoped to the skill governs the turn. The skill joins the turn's scope chain, and so does the skill a turn routes through via the toggle.

  • Its form is the skill's Run form. The fields are the skill's run schema (interface.inputs, plus any node input nothing in the graph supplies; see skills.md), checked by the same validate_inputs. The values reach the graph as its state, as in a standalone run, and are written into the task under "Inputs:" (compose_task), so Input rules read them. A skill with no fields runs on the request alone, which is then required.

How it is built

Commands are a registry (svc-core app/services/chat_commands.py). There is one ChatCommand class per (action, kind), registered with @register. Each class:

  • sets action, kind, label, description, request_hint and request_required;

  • implements targets(ctx): what it can act on in this chat (ctx has the session, the user, the agent and the chat's resolved workspace), each a CommandTarget with a slug that is unique within the command;

  • implements dispatch(ctx, target): how the turn then runs, as a dispatch the chat route knows. Today that is SkillDispatch(skill);

  • may implement form(ctx, target), a CommandForm over a RunSchema, or None (the default) for free text only;

  • may implement task(ctx, target, request, inputs): the text the turn runs on. The default is the request.

Slugs come from the target's name. The first target to claim a slug keeps it (built-ins first, then oldest); a later one with the same name gets its id's first characters. So a slug never moves once it has been given out.

The catalogue is GET /app/agents/{id}/commands?workspace=…, which lists every command with its targets in that workspace. Each target carries its form: fields (the run schema's), request (required or optional) and complete (false when a worker's interface could not be looked up). One worker-interface lookup serves the whole catalogue (runner.shared_definition_lookup). fe-core's palette and form draw from it, so no command, target, slug or field is written into the client.

The server parses every command with chat_commands.parse, on both chat paths: the WebSocket (agents/router.py agent_prompt_ws) and the batch prompt (POST /app/agents/{id}/prompt → prompt_agent). It resolves the target from the same targets the catalogue served, so a command typed by hand is checked exactly like one picked from the palette. A message's attached documents travel beside it, never in the prompt, so they cannot change what is parsed (Attachments). After parsing:

  • the composed task (ParsedCommand.task) becomes the turn's prompt. For /execute skill that is the request, or "Run the “…” workflow: …" when there is none, then the form's values;

  • the form's values (ParsedCommand.inputs, coerced to their types) seed the skill graph's state;

  • input rules see the task. Their redaction applies to the values and to the record as well, so neither carries what the prompt no longer does;

  • the user's message stores the task, with the command on its meta.command (ParsedCommand.meta(): line, action, kind, target_id, target_name, inputs, request). It is kept on refused and failed turns too. Until 24 October 2026 the chat stored the record as the message's whole meta, which the chat and the decision record, reading meta.command, never found on a reloaded message; both now read either shape (svc-core attachments.command_of, fe-core commandOf).

A later turn's history replays the task, not the command syntax.

Adding a command

  1. Add a ChatCommand subclass with @register. Implement targets (in the chat's workspace, with the caller's access) and dispatch, and form and task if its targets take inputs.

  2. If it needs a new way of running a turn, add a dispatch type beside SkillDispatch and teach the two chat paths to run it, once.

  3. Add tests to tests/test_chat_commands.py. They pin the grammar, the registry (each pair registers once, and every command describes itself) and both chat paths.

fe-core needs no change: the palette, the token, the form and the sent record all read the catalogue.

fe-core

  • The palette (components/chat/CommandPalette) opens when the input starts with /, or from the / button beside attach.

    • It lists the catalogue's command lines, grouped by command, with built-ins marked and how many inputs each target's form takes.

    • It filters on every word typed, matched against the line and the target's name, so /brief finds /execute skill research-brief.

    • Keys: ↑ ↓ to move, Enter or Tab to choose, Esc to close.

    • It is drawn in the input area's flow, so the panel's overflow-hidden can't clip it.

  • The token (components/chat/CommandForm). A chosen command becomes a token at the start of the message box: its line in code type, with ✕ to remove it. A command is chosen by picking it, by typing its whole line and a space or line break, or by pasting it (the text after the line stays in the box). While a line is still being typed it reads as code too.

    • Backspace in the empty box turns the token back into text to edit. The form keeps its values for when that command is chosen again; ✕ drops them.

    • The box then holds only the request. With form fields, it reads "Additional instructions (optional)"; without, it asks for the request (request_hint).

  • The form. Above the box, the target's form, drawn with the skill Run form's controls (components/form/RunFields) and laid out by the chat's own width. A long form scrolls. Picking a command focuses its first field; a command typed in the box leaves focus there.

  • The send is held until every required field is filled, every value can be read, and there is a request where one is needed. The form's last line says what is left. Enter with something missing shows every error and moves focus to the first. Ctrl+Enter (⌘+Enter) sends from a field, where Enter is a new line. A whole line sent as text (typed before the catalogue arrived) becomes the token instead of being sent, so its form is seen first.

  • The frame. prompt is the line and the request; command_inputs is the form's typed values, blank optional fields left out (as on the Run form).

  • The record. A sent command shows as its line in code type, the values its form was given and its request, at once and after a reload (meta.command). A record stored before forms has no request; its message text stands in.

  • The logic lives in util/chatCommands.ts (the grammar, tokens, and what holds the send) and util/runForm.ts (form values and their checks, shared with the Run form). The server stays the authority.

Pinned by util/chatCommands.test.ts, CommandPalette.test.tsx, CommandForm.test.tsx, ChatPanel.test.tsx (the chat commands block) and Chat.commands.test.tsx (the frame). svc-core's form handling is pinned by tests/test_chat_commands.py.