Skip to content

Host and agent packages ​

clanker-host is the always-on composition root. It wires the runtime, durable agent registry, event bus, rules engine, task pad, executors, MCP tools, and HTTP surface into one process, and runs whatever agent package it is given. No agent's prompt, tools or rules live in the host's code: the package describes the whole agent.

Start locally ​

Build the package, choose a writable data directory, point the host at an agent package directory, and explicitly enable local development mode:

bash
pnpm build
CLANKER_DATA_DIR=.clanker-data \
CLANKER_DEV=1 \
CLANKER_PROVIDER=claude \
CLANKER_AGENT_PACKAGE_DIR=./my-agent \
node packages/clanker/dist/host/main.js

Production mode refuses to start without a bearer token: CLANKER_TOKEN, or DOUGH_DELIVERY_TOKEN on dough (see below). CLANKER_DEV=1 is the only unauthenticated escape hatch and should remain local.

Important settings include:

  • CLANKER_AGENT_PACKAGE_DIR (a package directory) or CLANKER_AGENT_SOURCE=platform (the app's published package) — see Agent packages;
  • CLANKER_AGENT_ID for the entry agent's id (default DOUGH_APP_NAME, else agent);
  • CLANKER_PROVIDER=claude|codex;
  • CLANKER_MODEL for the agents' model when the package names none;
  • CLANKER_ASSISTANT_NAME for the entry agent's display name when the package names none;
  • CLANKER_PORT (falls back to PORT), CLANKER_HOST (default 127.0.0.1), and CLANKER_MCP_PORT;
  • CLANKER_EMIT_NAMESPACES (default <agent id>.): the operator's event namespaces, which bus_emit may emit and POST /v1/events accepts. Namespaces a package capability needs are not configured here: github.pad. (approvals) is accepted exactly while the live package has approvals on, and is ignored in this list once a package is applied;
  • CLANKER_INBOUND_ONLY_NAMESPACES (default github.pad.): namespaces bus_emit may never emit. github.pad. is always among them;
  • CLANKER_ACTOR_ID (default the agent id);
  • CLANKER_MULTI_USER=1 for a host serving many users;
  • CLANKER_PAD_STORE_URL and CLANKER_PAD_STORE_TOKEN to use a remote pad;
  • CLANKER_AUTHORING_URL and CLANKER_AUTHORING_TOKEN (or CLANKER_AUTHORING_URL=off) for the platform that creates agents for users — see Agent authoring;
  • CLANKER_MESSAGING_URL and CLANKER_MESSAGING_TOKEN (or CLANKER_MESSAGING_URL=off) for the platform that delivers messages to teammates — see Messaging teammates;
  • CLANKER_WEB_TOOLS_URL and CLANKER_WEB_TOOLS_TOKEN (or CLANKER_WEB_TOOLS_URL=off) for the platform that serves web_search/web_fetch — see Web tools;
  • CLANKER_REMINDERS_URL and CLANKER_REMINDERS_TOKEN (or CLANKER_REMINDERS_URL=off) for the platform that serves the reminder tools — see Reminders;
  • CLANKER_DAG_SUMMARY_MAX_CHARS (default 24000) for the budget of a finished DAG's results in its feedback turn — see What the feedback turn sees.

Deploying on dough ​

The repository's railpack.json builds the host as a dough app: dough builds it from source and runs packages/clanker/dist/host/main.js. Mount a volume and point CLANKER_DATA_DIR at it (the railpack default is /data). The platform reaches the app on 127.0.0.1:$PORT inside its VM, so the default CLANKER_HOST and the PORT fallback need no changes.

At boot, dough injects:

VariableMeaning
DOUGH_DELIVERY_TOKENPer-instance bearer the platform delivers channel messages with. The host's inbound token when CLANKER_TOKEN is unset.
DOUGH_PLATFORM_URLThe platform's base URL, e.g. https://api.try-dough.com.
DOUGH_PLATFORM_TOKENApp-scoped token for the connections RPC, the agent-package endpoint, the authoring endpoints and the web tools.
DOUGH_APP_IDThe app's id. Not read by the host.
DOUGH_APP_NAMEThe app's name: the entry agent's id unless CLANKER_AGENT_ID is set, and the app the "unpublished" reply points at.

How the host resolves each setting, first match wins:

  • Inbound token: CLANKER_TOKEN, then DOUGH_DELIVERY_TOKEN. A blank value counts as unset. With neither, the host refuses to boot unless CLANKER_DEV=1.
  • Entry agent id: CLANKER_AGENT_ID, then DOUGH_APP_NAME, then agent. It must match ^[a-z0-9][a-z0-9-]{0,63}$. The pad actor id (CLANKER_ACTOR_ID) and the default emit namespace (<id>.) derive from it.
  • Connections: CLANKER_CONNECTIONS_URL (off disables them; a URL needs CLANKER_CONNECTIONS_TOKEN), then the pad store, then DOUGH_PLATFORM_URL with DOUGH_PLATFORM_TOKEN (both must be set), then none.
  • Authoring: CLANKER_AUTHORING_URL (off disables it; a URL needs CLANKER_AUTHORING_TOKEN), then DOUGH_PLATFORM_URL with DOUGH_PLATFORM_TOKEN (both must be set), then none. It never follows the pad store.
  • Messaging: CLANKER_MESSAGING_URL (off disables it; a URL needs CLANKER_MESSAGING_TOKEN), then DOUGH_PLATFORM_URL with DOUGH_PLATFORM_TOKEN (both must be set), then none. It never follows the pad store.
  • Web tools: CLANKER_WEB_TOOLS_URL (off disables them; a URL needs CLANKER_WEB_TOOLS_TOKEN), then the pad store (the concierge's operator credential), then DOUGH_PLATFORM_URL with DOUGH_PLATFORM_TOKEN, then none. At boot the host asks that platform once whether it serves them (an empty POST /v1/web-tools/search, which the dough gateway refuses with a 400 without running anything). A 404/405 (e.g. a pad server that is not the gateway) or 401/403 drops the web tools platform, with a log line; packages then compile as on a host without one. No answer at boot keeps it.
  • Reminders: CLANKER_REMINDERS_URL (off disables them; a URL needs CLANKER_REMINDERS_TOKEN), then the pad store, then none — never DOUGH_PLATFORM_* alone: the gateway's personal-triggers RPC takes the operator pad service token, not an app token. At boot the host probes it the same way (an empty POST /v1/personal-triggers/list, a 400 from the gateway); 404/405 or 401/403 drops it, with a log line. The reminder tools, and the notes that describe them, are offered to a coordinator turn with a signed-in user whenever the package turns tools.reminders on and a platform is configured; a call from a turn that isn't a chat message of that user's says so instead of setting anything.
  • Pad and memory: CLANKER_PAD_STORE_* / CLANKER_MEMORY_STORE_* only, else local JSONL under CLANKER_DATA_DIR. They never use DOUGH_PLATFORM_*.
  • Agent package: CLANKER_AGENT_PACKAGE_DIR, or CLANKER_AGENT_SOURCE=platform (setting both stops the host at boot), else none — the host then answers every message with the unpublished reply below.

Agent packages ​

A package is three kinds of file:

FileWhat it is
agent.jsonMetadata, capabilities and sub-agents. Strict: an unknown key is an error.
persona.mdThe entry agent's system prompt, UTF-8, 1 B to 64 KiB.
<name>.mdUp to 16 more markdown files (each 1 B to 64 KiB, 256 KiB in total), each referenced from agent.json.

agent.json (every key optional; every package from before capabilities existed stays valid, with everything but authoring, messaging, web and reminders on):

json
{
  "description": "What the agent is for",
  "assistantName": "Pip",
  "model": "gpt-5.5",
  "tools": {
    "memory": true,
    "tasks": true,
    "agents": true,
    "events": true,
    "connections": true,
    "webSearch": true,
    "web": false,
    "authoring": false,
    "messaging": false,
    "reminders": false
  },
  "approvals": true,
  "connectApps": ["google-calendar", "gmail"],
  "notes": "notes.md",
  "subAgents": [
    {
      "id": "researcher",
      "name": "Researcher",
      "description": "Looks one question up and reports what it found.",
      "instructions": "researcher.md",
      "tools": { "memory": true, "connections": false, "webSearch": false, "web": true },
      "default": true
    }
  ]
}
  • tools switches the entry agent's capabilities; each defaults to true, except authoring, messaging, web and reminders, which default to false. memory is memory_recall/memory_remember/memory_forget; tasks is pad_create_task/pad_list_tasks/pad_get_task, the task DAG rules, the default worker and taskIds in the reply; agents is list_agents/ register_agent (requires tasks); events is bus_emit; connections is connections_list and the user's connected-service tools; webSearch is the provider's hosted web search (Codex's web.run, Claude's WebSearch) — false switches it off, which for Codex means web_search="disabled"; web is the platform's web tools (only on a host with a web tools platform); authoring is the agent-authoring tools and notes (independent of tasks, and only on a host with an authoring platform); messaging is the teammate messaging tools and notes (independent of tasks, and only on a host with a messaging platform); reminders is the reminder tools and notes (only on a host with a reminders platform). Sub-agents never get authoring, messaging or reminders.
  • approvals turns on the needs-approval gate. It defaults to tasks and requires it. While it is on, the host accepts the approval event (github.pad.approved) on POST /v1/events; no CLANKER_* variable is needed, and turning it off closes that ingress on the next swap.
  • connectApps (up to 20 app slugs, requires connections) are the apps the /connect notes name.
  • notes names a file of agent-specific operating notes, appended after the host's own.
  • subAgents (up to 16, requires tasks) are agents that run tasks. Ids are unique and never the entry agent's id; worker is reserved for the default sub-agent (a non-default worker is rejected). Their instructions file is used verbatim. Their tools (memory, connections, webSearch, web) default to true, except web (false). At most one is the default: it runs every task that names no agent.

Every file must be referenced from notes or a subAgents[].instructions, and every reference must exist.

Web tools ​

With web on, an agent gets two tools the platform serves (in dough, the gateway's POST /v1/web-tools/{search,fetch}, backed by Exa):

  • web_search(query, numResults?, includeDomains?, excludeDomains?, startPublishedDate?, endPublishedDate?, category?) — titles, urls, published dates and highlights;
  • web_fetch(url, maxCharacters?) — one public page's readable text, capped.

The host calls them with its platform credential (the pad service token for the concierge, the app's DOUGH_PLATFORM_TOKEN otherwise) and names the run's user, never one from the arguments. The platform meters them per team or app and per user, and its errors are written for the model ("Exa rate limit, retry in 12s", "page returned 403 …", "fetch blocked: private address …"); the host passes them on verbatim.

Every agent has exactly one search path. With web on (and a web tools platform) the provider's own search is switched off, whatever webSearch says. With web asked for on a host without a web tools platform, the provider's own search is kept on — whatever webSearch says — and the host warns, so an agent is never left with no search at all. Agents minted with register_agent follow the package's generic worker: its tools (web included) and its search path.

Timeouts nest so the model always gets the most specific error: the dough gateway ends a web call by its own deadline (45s), RemoteWebTools waits 60s for it, and every run's clanker-tools handle sets the provider's per-tool limit to 150s (Codex: tool_timeout_sec; its default, 60s, would also cut a connected service's 120s calls short).

The run's clanker-tools session is also required, with a 60s startup timeout (Codex: required = true, startup_timeout_sec). Codex starts a turn without waiting for a server that isn't required, so a session that hadn't listed its tools within a second or two was missing for the whole run: no host tool at all. A cold listing of the user's connected services, on the first turn after a restart, was slow enough for that. A required server is waited for; one that misses its startup timeout fails the run instead of running toolless. tools/list itself never waits more than 5s on the connected services (CONNECTION_TOOLS_LIST_BUDGET_MS). The host's own tools, every package-gated family included, are listed at once. A slow connected service is served from that server's last listing of it, or left out. Its listing finishes in the background for the next turn, and concurrent sessions of one user share one platform call. When the platform fails, the last listing is served too. Listings are kept per user and never shared, and the cache is bounded (least recently used evicted: 1,000 users, 5,000 tool lists). Because a service's tools can be missing for a turn, the notes and connections_list tell the model to check connections_list before saying a service isn't connected. A run whose required tool server fails to start answers the user with that cause ("my tools didn't load in time — clanker-tools: timed out awaiting tools/list after 60s"), and the host logs it.

Reminders ​

With reminders on, the entry agent gets three tools the platform serves. In dough each reminder is a personal time trigger (POST /v1/personal-triggers/{create,list,cancel}), fired by the gateway's trigger scheduler and delivered through the pad — docs/design/personal-triggers.md in dough-gateway:

  • reminder_create(when, mode, text) — when is exactly one of at (ISO 8601 with an offset, or a local time read in timezone), in_minutes, in (an ISO 8601 duration) or cron (five fields, at least 5 minutes apart, needs timezone), plus timezone (IANA). mode: "notify" sends the text itself as ⏰ Reminder: … at that time; mode: "run" runs the agent again then, as the same user in the same conversation, with text as their instruction, and posts its reply there. Returns the id, the fire time in UTC and in the user's zone, and where it goes;
  • reminder_list() — the user's reminders still to fire, and those that failed in the last week with why;
  • reminder_cancel(id).

They are listed to a coordinator run with a user — exactly when the notes describe them — and a call acts only for a job of that user's: the chat message the run answers, recorded by the front door (Job tasks), because that job is where a reminder is delivered. A call from a run with no such job is refused with a message the model can relay to the user. The host calls the platform with its platform credential and names the run's user and job task — never ones from the tool arguments; only each tool's own arguments are forwarded. The platform resolves the conversation from its own record of the job, checks the job is that user's and the caller's, and its errors are written for the model; the host passes them on verbatim. A run reminder's firing reaches the host as an ordinary message with a job task of its own (metadata.source: "trigger").

Ending a task as failed ​

Every worker run executing a pad task gets fail_task(reason). A worker that cannot do its task calls it, then ends its turn: the host fails the attempt with that reason (whatever the run returned), so the job ends failed and the user is told the reason — instead of a "completed" task whose result is an apology. The run's closing note is kept as the failed attempt's output. A report is final: nothing a run returns afterwards withdraws it (an ordinary ending can't tell "recovered" from "apologized" — the reason the tool exists).

Host notes for workers ​

The generic worker's instructions are the host's own. A sub-agent's instructions file is used verbatim and followed by the host's ## How this host works notes for workers: how to end a task with fail_task and — only when the agent has web — to search with web_search, read with web_fetch and cite urls. Agents minted with register_agent get the same notes after their instructions. A package's own files therefore never need to name host tools (and never claim tools a host has stripped).

What the feedback turn sees ​

When a DAG finishes, its report (host.dag.completed/failed, the feedback turn's input) carries every task's result WHOLE while all of them fit CLANKER_DAG_SUMMARY_MAX_CHARS (default 24000, 2000-200000). Past it the shortest stay whole and the longest share what is left; each trimmed result ends with […truncated: N of M characters left out — the full result is in task <id>; read it with pad_get_task("<id>")], and pad_get_task returns the task's full output (and each attempt's error/output). The feedback turn is told to relay each result faithfully — its facts, figures and source links — not a vaguer summary.

When a feedback turn fails ​

A failed entry-agent run that answered a message replies "Sorry — I hit an error…". A failed DAG feedback turn sends nothing: its job ends un-notified, so the platform delivers the one message that matters — why the work failed, or the work's own result.

How the host compiles a package ​

  • Entry agent (id from the entry-agent rule above): its instructions are persona.md (trimmed), a blank line, the host's ## How this host works notes, then the notes file. The notes describe only what is on: per-user scope and history always; then memory, /connect (naming connectApps), acting through tools, tasks and the default worker, and the output contract; with authoring on, a ## Creating agents for the user section follows them. Its output is {reply, taskIds} with tasks on, else {reply}. It never gets a shell; its tool session offers exactly its capabilities, and a call to anything else is refused.
  • Sub-agents run tasks with their own instructions and tools; they may run commands only on a single-user host.
  • Default worker: the default sub-agent, else (with tasks on) the host's generic worker, which acts for the task's owner through the entry agent's memory/connections capabilities and signs nothing in anyone's name.
  • Rules (engine-owned ids): agent-dispatch, agent-reply, agent-failed-reply always; auto-ready-roots, auto-attempt, agent-dag-completed, agent-dag-failed with tasks; gate-needs-approval, resolve-on-approval with approvals.
  • Applying a package (at boot and on every hot reload) registers its agents, removes agents a previous package seeded that it no longer has, upserts its rules, and removes every engine-owned rule it no longer generates — from the rule store too, so a restart does not bring them back. The pre-package concierge-* rule ids are always removed. Agents minted at run time and rules you added yourself are left alone.

From a directory ​

CLANKER_AGENT_PACKAGE_DIR names a directory holding agent.json, persona.md and the package's other *.md files. It is validated exactly like a publish; an invalid package stops the host at boot with every problem listed. A relative path resolves against the working directory.

From the platform ​

On the platform-managed agent host image, dough sets CLANKER_AGENT_SOURCE=platform. The agent is then the app's active package, published from the dashboard or with a deploy token (PUT /v1/apps/<name>/agent with {agent, persona, files}). Publishing never rebuilds or redeploys; the running host picks it up.

  • At boot the host fetches GET <DOUGH_PLATFORM_URL>/v1/agent-runtime/package with DOUGH_PLATFORM_TOKEN and applies it.
  • When nothing is published yet (404) the host answers every message with "This agent has no published agent package yet. Publish one from the dough dashboard (Apps → <name> → Agent)." — there is no hidden persona — and keeps polling.
  • Every applied package is cached under CLANKER_DATA_DIR/agent-package/. When the platform cannot be reached at boot, the host runs the cached package (or, with none cached, the unpublished reply) and keeps polling.
  • It polls every CLANKER_AGENT_POLL_SECONDS (default 10, 1-3600) with If-None-Match. A new version is applied as above: the next turn runs it — with its persona, model, capabilities, sub-agents and rules — while a turn already running finishes on the old one. The host logs agent package v<n> (<digest>) active.
  • The package's model and assistantName override CLANKER_MODEL and CLANKER_ASSISTANT_NAME, which remain the defaults when the package omits them.
  • Network errors, bad responses and packages that fail to apply never take the host down: the live version stays, and polling backs off (the interval doubled per failure, up to 5 minutes).
  • CLANKER_AGENT_SOURCE=platform without DOUGH_PLATFORM_URL and DOUGH_PLATFORM_TOKEN stops the host at boot.

GET /health reports the live package, e.g. "agent": {"id": "concierge", "source": "platform", "published": true, "version": 3, "digest": "sha256:…"} (source is dir, platform or none; published is false while the host gives the unpublished reply).

Removed settings ​

These stop the host at boot with a pointer to their replacement: CLANKER_PERSONA_FILE (use a package directory), CLANKER_AGENT_REGISTRY_URL, CLANKER_AGENT_REGISTRY_TOKEN, CLANKER_AGENT_REGISTRY_VERSION, CLANKER_AGENT_REGISTRY_DIGEST, CLANKER_AGENT_VERSION and CLANKER_AGENT_DIGEST (publish an agent package and use CLANKER_AGENT_SOURCE=platform).

Agent authoring ​

An entry agent with tools.authoring creates agents for the user it is talking to: a one-off agent (a dough task in its own VM, owned by and billed to that user, on their own linked credentials, optionally in one of their repos; its result comes back into the same conversation) or a permanent one (a dough app with its agent package, triggers and channel binding). The agent only ever proposes. The platform validates and stores each proposal and returns a short code; nothing is created until the user sends confirm <code> in the same conversation, which the platform intercepts before it reaches the agent.

The capability needs both the package switch and a host that reaches the authoring platform (see the resolution order under Deploying on dough). A package that asks for it on a host without one runs without it, and the host logs a warning. With both, the entry agent's tool session offers:

ToolWhat it does
agent_authoring_optionsThe user's teams and roles, the templates they can use, their channel connections, billing/credential status, repos.
propose_agent_run{agent: {name, description, systemPrompt, runtime?, model?, maxTurns?, needsWorkspace?, workspaceMode?, openPullRequest?}, task, repo?}: a one-off agent.
propose_agent_deploy{name, team?, package: {agent, persona, files?}, triggers?, channel?, requiredSecrets?}: a permanent agent app.
agent_proposal_status{proposalId}: a proposal's status and, once executed, its result.
agent_run_status{taskId}: a one-off run's status and result summary.

A proposing tool's arguments are exactly the platform's proposal payload (the dough gateway's docs/design/agent-authoring.md is the normative contract), so the host only checks their top-level shape and drops anything else; the platform validates the rest with the same rules as the dashboard. They return {id, code, summary, expiresAt}; the summary already ends with the line the user sends. The tools are coordinator-only (a worker session never gets them) and need a session with a user and a conversation. Every call carries that session's userId and conversationId, never values from the tool's arguments, and the platform checks that the app really is talking to that user in that conversation. The host calls, with the platform token as a bearer:

  • POST <url>/v1/agent-runtime/authoring/options with {userId, conversationId};
  • POST <url>/v1/agent-runtime/authoring/proposals with {userId, conversationId, kind: "run" | "deploy", payload};
  • GET <url>/v1/agent-runtime/authoring/proposals/<id>?userId=…&conversationId=…;
  • GET <url>/v1/agent-runtime/authoring/runs/<taskId>?userId=…&conversationId=….

A refusal ({error: {code, message, fields?}}) reaches the model as the tool's error. A validation refusal (400) lists every invalid field by its tool argument (propose_agent_deploy: rejected — triggers.0.config.cron: …), so the model can fix the proposal; any other refusal's message says what to tell the user, with the platform's reason appended when it sends one (for example, "sign in to dough to create agents (reason: anonymous)"; 403 reasons are authoring_disabled, anonymous, no_recent_delivery and user_inactive).

The notes tell the agent to start from the options, prefer a template, always propose and then relay the summary verbatim (it ends with the exact confirm <code> line), never claim anything was created before the platform says so, and never collect secrets in chat (it names them in requiredSecrets; the user sets them in the dashboard). register_agent remains the way to add internal helpers for the agent's own pad tasks.

Messaging teammates ​

An entry agent with tools.messaging sends a message, on behalf of the user it is talking to, to another member of its app's team — on a channel that member has linked to dough (Discord, WhatsApp, Telegram or Slack). The agent only ever proposes. The platform resolves the teammate (by dough user id, name, email or linked handle), checks that both are members of the app's team, honours the recipient's opt-out, preferred channel and rate limits, and stores the message under a short code. The platform itself posts the message (recipient, channel, exact text) and that code into the conversation — the agent never sees the code, so it can't hand the user a code for a message they didn't see. Nothing is sent until the user sends confirm <code> in the same conversation, which the platform intercepts before it reaches the agent and answers itself with the outcome ("Sent to Priya on WhatsApp", or why not). The platform prefixes every delivered message with From <assistant>, on behalf of <user>:.

Like authoring, it needs both the package switch and a host that reaches the messaging platform; a package that asks for it on a host without one runs without it, and the host logs a warning. With both, the entry agent's tool session offers:

ToolWhat it does
message_member{to, text, channel?}: propose a message; channel is one of discord, whatsapp, telegram, slack (omitted: the recipient's preferred linked channel).
message_member_status{messageId}: whether it is awaiting confirmation, expired or cancelled, and once confirmed its delivery.

The tools are coordinator-only and need a session with a user and a conversation. Only to, text and channel are forwarded (shape-checked); the call carries the session's userId and conversationId, never values from the tool's arguments. The host calls, with the platform token as a bearer:

  • POST <url>/v1/agent-runtime/member-messages with {userId, conversationId, to, text, channel?} → {id, summary, expiresAt, recipient: {userId, name}, channel}. The response has no confirm code. Any code the platform did send would be dropped. The model gets the response plus shownToUser: true.
  • GET <url>/v1/agent-runtime/member-messages/<id>?userId=…&conversationId=….

A refusal ({error: {code, message, fields?}}) reaches the model as the tool's error, written to be relayed (an ambiguous teammate lists the candidates and their channels; an unlinked channel lists the ones they have), with the platform's reason appended when it sends one (ambiguous_recipient, unknown_recipient, opted_out, channel_not_linked, channel_not_enabled, …). A validation refusal without a reason lists each invalid argument.

The notes tell the agent to message a teammate only when the user explicitly asks, never on its own initiative; that the platform shows the user the message and its code, so the agent only says it awaits their confirmation and never writes a confirm code or line itself; never to claim the message was sent; and to relay a refusal as written. On an app with tools.messaging, /messages … (a person's own settings for messages from teammates) is answered by the platform and never reaches the agent; elsewhere it is an ordinary message.

Interfaces ​

The host exposes:

  • an authenticated HTTP API for messages, events, agents, tasks, and pulls;
  • asynchronous message submission with correlation IDs;
  • an SSE stream for catch-up, live progress, heartbeats, and terminal state;
  • a loopback MCP tool server for pad, bus, registry, memory, connection and authoring operations, scoped per run to one user and filtered per agent capability.

State is JSONL-backed by default. Durable remote registries and pad servers can replace the local reference stores without changing the runtime or rule model.

Sending a message ​

POST /v1/messages takes a JSON body:

fieldtypemeaning
textstringRequired. The message.
principalobject{userId, platform?, externalId?, displayName?}: the verified sender, asserted by the authenticated caller. Required when CLANKER_MULTI_USER=1.
conversationIdstringWhich conversation the message belongs to; with a principal, the last turns of it are passed as history.
metadataobjectOptional caller context, at most 8 KiB of JSON. Its keys are copied onto the host.message.received event's data, so rules and the event feed can see them.
asyncbooleantrue (or Prefer: respond-async): answer 202 {correlationId, streamUrl} at once and stream progress from GET /v1/messages/:correlationId/stream.

metadata is how a caller tags where a message came from. The dough gateway, for example, sends {"source": "trigger", "triggerId": …, "runId": …, "kind": "schedule"} for messages fired by an app trigger. It must be a JSON object (null counts as absent); an array, string, number or boolean, or more than 8192 bytes of serialized UTF-8 JSON, is rejected with 400 and the message is not accepted. It never sets the keys the host owns on the event (text, user, principal, conversationId, sender, history), even when the message itself leaves them unset: a principal inside metadata is dropped, never treated as verified.

Following a message to its end ​

Every accepted message is a job that ends with exactly one terminal event, correlated by its correlationId:

  • host.job.completed — {result?, resultRelayed, replies, tasks, durationMs}. result is the final user-facing text (the last reply, or the spawned work's own summary when no reply carried it); resultRelayed says whether it already went out as a host.message.reply.
  • host.job.failed — {stage, reason, notified, replies, tasks, durationMs}. stage is intake (the message never reached the agent), coordinator, tasks (work it spawned failed or was cancelled), timeout or interrupted (the host restarted under it). reason is one presentable line — no stack traces or credentials. notified says whether a reply already told the user.

A job that hands work to pad tasks replies at once (the acknowledgement); the tasks run detached on workers, and when they finish the entry agent is invoked again and its reply — the result — is a second host.message.reply on the same stream. The stream (GET /v1/messages/:correlationId/stream) forwards the job's events, including its tasks' progress, and ends with done:

done.reasonmeaning
completehost.job.completed was sent.
failedhost.job.failed was sent.
unknown-jobthis host never accepted the id (e.g. a new instance after a redeploy): it cannot finish here.
max-durationthe live window (CLANKER_STREAM_WINDOW_SECONDS, default 1800) passed; the job keeps running — reconnect (the backlog is replayed).
client-gonethe client disconnected.

Each conversation's messages run in order; different conversations run concurrently, at most CLANKER_MAX_CONCURRENT_JOBS (default 4) agent turns and CLANKER_MAX_CONCURRENT_TASK_RUNS (default 4) task runs at a time. A job still open after CLANKER_JOB_TIMEOUT_MINUTES (default 360) fails with timeout. The host logs one clanker-host job {…} JSON line per step (accepted, started, replied, task-spawned, tasks-finished, completed, failed) with ids, counts and timings — never message text.

Job tasks: the job's record in a shared pad ​

The terminal events above live on this host's bus, which a redeploy empties. A front door that must tell the user about work finishing long after the chat's live window (the dough gateway) records the job in the pad instead: before submitting, it creates a job task there and passes its id — POST /v1/messages { …, "job": { "taskId": "<id>" } }. The task is labels: ["job"], status created, owned by the principal's userId, with metadata.conversationId and the front door's own record in metadata.job. The 202 says whether the host took it: "job": { "taskId", "adopted": true }, or adopted: false with a reason (no such task, not a job task, not created, another owner, held by someone else, the pad unavailable, or a host that keeps no job records) — the front door then drives the record itself.

An adopted job task is written only by this host from then on:

  • accepted — claimed by {kind:"agent", id: "<CLANKER_ACTOR_ID>#<boot id>"} (this process only: two live processes of one host never renew or take each other's jobs), assigned, metadata.job.correlationId, driver: "host" and host: {actor, boot, adoptedAt} recorded; started — in_progress. Adoption runs before the 202 and is bounded (8 s): on a refusal, a pad error or the deadline, whatever part of it committed — even a write whose response was lost — is undone (claim released, assignee and host fields cleared), and the 202 says adopted: false.
  • work — tasks the coordinator (or the job's feedback turn) creates with pad_create_task become children of the job task unless they name a parent of their own, so a request is one tree in the pad; a parent in the tree of a request that already ended files the work under the current request instead (or is refused when there is none). pad_list_tasks never lists job tasks. Each such task gets an attempt timeout (CLANKER_TASK_TIMEOUT_MINUTES, default 30): the dispatcher heartbeats every attempt it holds, queued or running, so the reconciler only times out one nobody carries any more — and a run that breaks while being dispatched (the pad failing a read or write) is failed, with retries, so its job ends instead of hanging.
  • heartbeat — the claim is renewed every CLANKER_JOB_HEARTBEAT_SECONDS (default 60) and holds 15 heartbeats; a host silent that long has visibly lost the job to whoever notices. A job whose end is still being written keeps being renewed.
  • end — completed/failed with the outcome as output, written before host.job.* is emitted: {outcome, stage?, reason?, result?, resultRelayed?, notified?, messages: [{id, text}], tasks, durationMs, finishedAt, by:"host"}, messages being the agent's replies by the id of their host.message.reply. The claim is released; a failed job's still-open work is cancelled, and no feedback turn runs for it. A write that fails is retried in the background.
  • restarts — stopping first answers new messages 503, then fails every open job as interrupted. A job a previous process of the same actor left open is failed as interrupted once its claim EXPIRED (checked at boot and on every heartbeat) — a live process's never does, so a rolling deploy's old process keeps the jobs it is still finishing — and only then is its host.job.failed emitted.

A job task taken over by someone else (its claim expired and was re-taken, or it was ended) is never written again by this host. The reconciler never reaps a job task's expired claim: it is evidence (whose heartbeat stopped, and when) that the job records and the gateway act on.

Registries ​

The durable registry validates and persists agent definitions and emits lifecycle events. The remote registry adds immutable versions, canonical content digests, digest verification, bearer access control, ETags, and provider rebinding when a definition is pulled into a host (POST /v1/agents/:id/pull).