Skip to content

Pipelines executor

Pipelines drawn in an editor and executed by a server of your own. This example is that server: an HTTP service - the Worker agent-pipelines - that stores pipeline definitions with their versions, runs a version on request, shows every run’s node states and events live, retries the node a run failed at and cancels a run. Pipeline Studio (apps/studio) is its front end: the canvas editor, the versions, the runs. The Studio also works without one, in the browser (its default mode: pipelines and runs on the device, your own provider key); connect an executor for runs that go on with the tab closed, a failed node retried where it failed and secrets kept on the server.

It is an example, not a package: private in the workspace, never published. Each person who wants it deploys it to their own Cloudflare account, with their own model key. Nothing here deploys or logs in to anything.

Stage 1. Runs start by API request (or from the Studio). Triggers (a schedule, a file, a webhook), the secrets store and the “human” step come later. A definition may already reference secrets by name: a run is refused while any reference does not resolve - and with no secrets store yet, a secret reference never does.

Studio / curl ──HTTPS + operator token──▶ Worker (the HTTP API, src/api.ts)
│ │
CatalogDO (one) RunDO (one per run) ◀──────┐
pipelines, versions, record, node visits, │
the run index events, snapshots, journal │
│ │
RunWorkflow (one per attempt) ───┘
the core's graph engine = scheduler,
each node visit a step: the node's agent
  • The definition is the pipeline definition format - versioned JSON that the editor writes and the executor only reads. A save is a new version; a version never changes. A run names the version it runs and keeps a copy of its graph.
  • A run is a Durable Object of its own (RunDO): its single writer. It holds the run’s record, every node visit, the event log the stream serves, and each visit agent’s snapshots and call journal.
  • An attempt of a run is a Workflow instance (run-<runId>-<attempt>). It runs runPipelineGraph - the core’s deterministic graph engine (@dudko.dev/agent/pipeline-engine, the scheduler the swarm’s pipelines use) - and every node visit is a named step that runs the node’s agent (the Node core, nodejs_compat). A wave’s visits run side by side; their answers reach the engine in the order the visits started, so a Workflow replay after an eviction feeds the engine the same sequence and nothing is run or written twice.
  • A failed node fails the run at it. Retry starts the next attempt: it runs the engine from the top again - it asks for the same visits in the same order - and every visit already done is answered from its record (not run again), the failed one resumes its agent from the call journal (a model call that was made is not made again, a tool call that succeeded is not run twice), the rest run.
  • Cancel stops the running visits (each polls its run) and ends the run cancelled.

The swarm exists on four platforms. This example builds on the Cloudflare one because it is the simplest to run locally: wrangler dev is the whole stack - workerd with Durable Objects and Workflows, SQLite on disk - with nothing else to install (no Postgres and Temporal, no Java for the Firestore emulator or DynamoDB Local) and no account. What it reuses:

  • swarm-shared: the HTTP plumbing (bounded JSON bodies, the constant-time bearer check, CORS for exact origins) and the JSON logger;
  • swarm-cloudflare (its ./worker entry): the agent’s setup from the environment (the same AGENT_* and MCP_SERVERS variables, the providers built in code), a pipeline node’s agent config (pipelineNodeConfig: its instructions under the system prompt, only the tools and MCP servers it names), and the log filter that redacts secrets (safeLogger);
  • the core’s public engine (preparePipeline, runPipelineGraph, pickPipelineRoute) and its persistence with the call journal - the same pieces the swarm’s PipelineWorkflow runs on.

A run is not a swarm session: a session is a conversation with an agent that decides to call a pipeline; a run here starts the graph directly, with no session agent in front of it. So the run has an object and a Workflow of its own, built the way the swarm’s are (a single writer per run, fenced writes, steps named by what they do).

The format lives in @dudko.dev/agent-web-ui/pipeline-format (it imports nothing, so the editor in a browser and this Worker share it): the types, the validator, the JSON Schema and the converters. In short:

{
"format": "agent-pipeline",
"schemaVersion": 1,
"name": "review",
"title": "Review",
"entry": "writer",
"nodes": [
{ "id": "writer", "instructions": "Write a draft.", "tools": ["word_count"] },
{
"id": "judge",
"instructions": "Approve the draft or ask for changes.",
"routes": [{ "label": "approve" }, { "label": "revise" }],
"secrets": ["GITHUB_TOKEN"]
},
{ "id": "publish", "mcpServers": ["docs"], "settings": { "auth": { "$secret": "DOCS_KEY" } } }
],
"edges": [
{ "id": "e1", "from": "writer", "to": "judge" },
{ "id": "e2", "from": "judge", "to": "publish", "when": { "kind": "route", "label": "approve" } },
{ "id": "e3", "from": "judge", "to": "writer", "when": { "kind": "route", "label": "revise" } }
]
}
  • Conditions are data: always, contains, matches (a linear-time regular expression subset), route (a label the node picked after it answered), otherwise.
  • References by name: tools (a native tool of the executor, or <server>__<tool>), MCP servers, skills, models, and secrets - a node’s secrets, or { "$secret": "NAME" } anywhere in its settings. Never a value: a string that looks like a key or a token (provider key shapes, private keys, JWTs, bearer credentials, password=..., long random runs), or any value under a key such as apiKey / token / password, is refused with the path where it is - and the value is not echoed.
  • A save is checked three ways: this executor’s zod schema (src/format-zod.ts, held to the format’s validator and JSON Schema by tests/format.test.ts), the format’s validator (references between nodes and edges, routes, secret values), and the core’s validatePipeline (the engine’s own rules: the otherwise rule, a pattern’s size, …). Every problem comes back at once, each with a JSON Pointer.

Every route takes Authorization: Bearer <operator token> (one of OPERATOR_TOKENS); a preflight (OPTIONS) carries no data and needs none. Bodies are JSON (at most MAX_BODY_BYTES).

Route What it does
GET /v1/health { "ok": true }
GET /v1/schema the format as a JSON Schema
GET /v1/capabilities what a definition may name here: tools, mcpServers, secretsStore: false
GET /v1/pipelines the pipelines, newest change first
POST /v1/pipelines a document; saved as the next version of its name. 201 { name, version, warnings } - warnings are the references this executor cannot resolve (a run of it would be refused). 422 invalid_definition with issues
GET /v1/pipelines/:name the pipeline and its versions
GET /v1/pipelines/:name/versions/:v a version’s document (:v a number, or latest)
POST /v1/pipelines/:name/versions/:v/runs { "input": "<the request>" }: start a run. 201 { run }; 422 unresolved_reference with issues; 503 start_failed when its Workflow could not be started (the run is then failed, never left queued)
GET /v1/runs?pipeline=&limit= the runs, newest first
GET /v1/runs/:id { run, visits, lastSeq }: the record and every node visit
GET /v1/runs/:id/events the run’s events (Server-Sent Events)
POST /v1/runs/:id/cancel 202; a run that is over: 409
POST /v1/runs/:id/nodes/:node/retry 202: the next attempt (the run is queued until its Workflow loads it). Only a failed run, only at the node it failed at; else 409. 503 start_failed when the attempt’s Workflow could not be started: the run is failed at the same node again, to be retried later

A run’s status: queued (no worker has taken it yet: a cancel ends it at once), running, cancelling, done, failed (with failedNode), cancelled. The run index of the listings is best effort (the run’s object tells it again on its next change); a run’s own record is the truth. A visit’s: running, done, failed, stopped, pending (a retry will run it).

Events. Each frame is id: <seq>, event: <type>, data: <JSON with seq and at>. A client that reconnects with Last-Event-ID (or ?after=<seq>) gets what it missed, then the live stream; the stream ends when the run is over. The types: run.created, run.started, the engine’s (pipeline.started, pipeline.node.started / .finished / .failed / .skipped, pipeline.edge, pipeline.finished), every node agent’s own events with nodeId and visit (the plan, steps, tool calls; streamed deltas are left out - a node’s answer arrives whole), run.retried, run.cancelling, run.finished. A retry does not repeat the engine’s events up to the retried node: the log reads as one run.

Terminal window
TOKEN=... # one of OPERATOR_TOKENS
curl -sX POST localhost:8787/v1/pipelines -H "authorization: Bearer $TOKEN" \
-H 'content-type: application/json' -d @review.json
curl -sX POST localhost:8787/v1/pipelines/review/versions/latest/runs \
-H "authorization: Bearer $TOKEN" -H 'content-type: application/json' \
-d '{"input":"Write about the release"}'
curl -N localhost:8787/v1/runs/<runId>/events -H "authorization: Bearer $TOKEN"

No account, nothing deployed - wrangler dev on localhost:8787:

Terminal window
pnpm install && pnpm nx run-many -t build -p @dudko.dev/agent,@dudko.dev/agent-web-ui,swarm-shared
cd examples/pipelines
cp .dev.vars.example .dev.vars # set OPERATOR_TOKENS and AGENT_API_KEY; never commit it
npx wrangler dev

Then Pipeline Studio: pnpm nx build @dudko.dev/agent-web-react && pnpm --filter studio dev (localhost:5175/studio/, which .dev.vars.example’s CORS_ORIGINS allows), or https://agent.dudko.dev/studio/ with CORS_ORIGINS=https://agent.dudko.dev.

The agent’s variables are the swarm’s on Cloudflare - AGENT_PROVIDER_TYPE (openai, anthropic, google, openai-compatible), AGENT_MODEL, AGENT_API_KEY, AGENT_BASE_URL, MCP_SERVERS (HTTP only), the AGENT_* limits: see its configuration. A node’s model is a model id on that provider. This executor’s own:

Variable Default What it is
OPERATOR_TOKENS (required, secret) Comma-separated tokens, at least 16 characters each, not a placeholder. Every route takes one.
CORS_ORIGINS empty The exact origins a browser may call from (https://host[:port], or http on loopback). * is refused; a request from another origin answers 403.
MAX_BODY_BYTES 524288 The largest request body.
NODE_MAX_ATTEMPTS 2 Attempts of one node visit (a step’s retries, each resuming its agent from the journal) before the run fails at it.
NODE_TIMEOUT_MS 600000 How long one attempt of a visit may take.
SSE_KEEPALIVE_MS 15000 A comment on an open event stream this often.
MAX_RUNS_LISTED 100 The most runs one listing returns.
LOG_LEVEL info debug, info, warn, error.

Tools. The native tools a node may name are in src/tools.ts (word_count, utc_now - an example’s); add yours there. MCP tools are <server>__<tool> of MCP_SERVERS.

  • The operator token guards every route (constant-time comparison over SHA-256 digests; more than one for rotation). It is one shared secret: put your own authentication in front before giving the executor to several people.
  • CORS answers exact origins only, never *, never with credentials; a request carrying an Origin that is not listed is refused outright.
  • Definitions never contain secret values (see the format); the executor never logs one: no request body is logged, and every log line goes through swarm-cloudflare’s safeLogger (keys, bearer tokens, key=value pairs and long random runs redacted, outside text clipped).
  • Fences. Everything an older attempt sends is refused; a visit’s agent writes its snapshots, journal and events under the visit’s token, so a step the engine retried after a timeout cannot write next to its successor.
  • A run’s id is a UUID made by the executor; no storage is made for an id nobody created.
  • A node’s agent runs inside a Workflow step: one attempt of a visit is bounded by NODE_TIMEOUT_MS and by the Workers limits of the plan (CPU time, subrequests: see the swarm’s long turns). A long graph needs more Workflow steps (about three per visit): raise limits.steps in wrangler.jsonc.
  • What workerd does not offer is not here either: stdio MCP servers, run_js, worker-thread subagents.
  • A node that mounts whole MCP servers AND names single tools of other servers is refused at run start (the swarm probes for the servers’ catalog; this example does not).
  • The catalog is one Durable Object: fine for an operator’s pipelines, not for a multi-tenant product.

The owner’s step, by hand, to their own account (nothing in this repository deploys):

Terminal window
cd examples/pipelines
npx wrangler login
npx wrangler secret put OPERATOR_TOKENS # openssl rand -hex 24
npx wrangler secret put AGENT_API_KEY
# CORS_ORIGINS: the Studio's origin, e.g. https://agent.dudko.dev - in wrangler.jsonc or the dashboard
npx wrangler deploy

wrangler.jsonc publishes no workers.dev route and no previews: add a route or a Custom Domain of your own.

Terminal window
pnpm nx run-many -t typecheck format:check build test -p pipelines # build = wrangler deploy --dry-run (offline)
pnpm nx run pipelines:test:e2e # wrangler dev, a scripted model
  • tests/ (node --test, nothing external): the run’s object and an attempt over node:sqlite and a replaying fake step (the order of visits, a replay after an eviction, a failure and the retry, cancel, the fences), a node visit with the real core on the agent package’s scripted OpenAI-compatible model (the route call, a retry that resumes from the journal, a cancel), the HTTP API (the token on every route, CORS, the three checks of a save, unresolved references, runs, events), the zod schema against the format, the configuration.
  • e2e/ (test:e2e): the Worker under wrangler dev with the scripted model - a wave, a join and a route, the event stream, a failed node retried, a cancel. apps/studio’s browser tests start the same harness.