Skip to content

Deploy the Node agent

@dudko.dev/agent is a library: one createAgent, one agent.run per request. How it is deployed depends on how many processes run it and on where a conversation lives between two requests. This repository has five answers that exist today: the package inside one process of your own, and four reference deployments of it as a swarm - many workers behind one HTTP API - each on a different platform.

The four swarms are examples, not packages: private in the workspace, never published to npm. Read them, run them, copy what you need. A fifth example is built on one of them: a public support chat - an agent of its own on the Cloudflare swarm, without forking it.

One process is the package in your own Node service or job (Node 22.6 or newer), or the dd-agent CLI. Pick it when a single service is enough and the conversation already lives in your application: there is nothing to deploy but your own code. A conversation is the history you pass to agent.run, kept wherever you keep it; a turn is one agent.run call; the HTTP API, if you want one, is yours to write. The package needs no database and no broker: persistence (and the call journal) is an interface you implement when a run must outlive its process - with it, a run whose process died can be resumed from its last snapshot. The scale-out hooks are there when one process stops being enough; the four swarms are what they look like filled in.

A swarm is that filling in, done four times. At a glance:

Swarm on You run A session is
Temporal + Postgres Temporal, Postgres and one container image A Temporal workflow
Cloudflare One Worker A Durable Object
Google Cloud Two Cloud Run services A Firestore document
AWS Three Lambda functions, or two ECS services Items of one DynamoDB table

Pick the swarm on Temporal + Postgres when you run your own infrastructure (Docker, Kubernetes) and want workers you can add and remove while conversations go on. It is the one the other three are ports of, and the only one whose image is published.

  • What you run: a Temporal cluster, a Postgres database and one container image (examples/swarm) in its three roles - gateway, worker, migrate.
  • A conversation is a Temporal workflow per session; its state, events and journal are in Postgres. A turn is one agent.run in a Temporal activity.
  • When a worker dies mid-run, Temporal retries the turn on another worker, which resumes the run from its last checkpoint and replays the call journal.
  • More capacity: more replicas of the gateway and of the worker; no session affinity.
  • Shipped as a Dockerfile, compose.yaml and a Helm chart. MCP servers over stdio and HTTP. Its integration tests run on a Postgres and a Temporal dev server.

Pick the swarm on Cloudflare when you would rather run no servers: one Worker, with no Temporal and no Postgres.

  • What you run: nothing but the Worker (examples/swarm-cloudflare): Durable Objects and Workflows are the platform’s.
  • A conversation is a Durable Object per session, with its own SQLite storage. A turn is one agent.run in a step of a Workflow instance.
  • When a step dies mid-run, the Workflow engine runs it again, and it resumes the run the same way: from its last checkpoint, replaying the call journal.
  • More capacity is the platform’s; every write of one session goes through that session’s object.
  • Shipped as wrangler.jsonc. Its tests run in wrangler dev: workerd, on your machine.
  • It gives up what workerd does not offer - stdio MCP servers, the run_js sandbox, worker-thread subagents and the web_fetch tool: see its limits.

Pick the swarm on Google Cloud when your project is already there and you want the platform to keep the state and drive the work, with no cluster of your own.

  • What you run: a gateway service and a worker service from one image on Cloud Run (examples/swarm-gcp), or the same two handlers as Firebase Functions. Firestore, Cloud Tasks and Cloud Scheduler are the platform’s.
  • A conversation is a Firestore document per session, with everything of it under that document; no process owns it - every change is one transaction. A turn is one agent.run in the request of a Cloud Task.
  • When a worker dies mid-run, Cloud Tasks delivers the task again, and that attempt resumes the run the same way.
  • More capacity: Cloud Run’s instances, within max_instances and the turns queue’s rate and concurrency caps.
  • Shipped as a Dockerfile, Terraform, Cloud Run manifests and firebase.json. The Node core runs in a container, so stdio MCP servers, the run_js sandbox, worker-thread subagents and web_fetch work as in the Temporal swarm.
  • Its limits: one attempt of a turn is one request of at most 29 minutes - a longer turn goes on in the next attempt, from the journal, and a single model or tool call longer than that can never finish. An agent is made per attempt, so MCP servers are connected to (a stdio one started) at every attempt.

Status: a reference implementation, tested end to end locally and in CI on every change that touches it - against the Firestore emulator and a stand-in for Cloud Tasks. It has not yet run on a live Google Cloud project: what that leaves unproven is the checklist before a first terraform apply.

Pick the swarm on AWS when your account is already there and you want the platform to keep the state and drive the work: DynamoDB and SQS, with the compute on Lambda or on ECS Fargate.

  • What you run: three Lambda functions (examples/swarm-aws) - a gateway behind a streaming Function URL, and a worker for each of the two queues - or, from the same code, a gateway and a worker service on ECS Fargate. DynamoDB, SQS and EventBridge are the platform’s.
  • A conversation is a partition of one DynamoDB table: every change of a session is one transaction locked on its own item, with the effects it causes in an outbox. A turn is one agent.run in the delivery of an SQS message.
  • When a worker dies mid-run, its message comes back after the queue’s visibility timeout (or a watchdog sends it again), and that attempt resumes the run the same way.
  • More capacity: Lambda’s own, within the concurrency the deployment reserves for each function; on ECS, more tasks.
  • Shipped as a Dockerfile, Terraform (functions or containers, chosen per role) and a zip of the functions pinned by the workspace lockfile. On ECS the Node core runs in a container, as on Google Cloud; on Lambda, stdio MCP servers are only what the package brings.
  • Its limits: one attempt of a turn is one delivery - 14 minutes at most on Lambda, 29 by default on ECS - and a longer turn goes on in the next attempt, from the journal. An agent is made per attempt, so MCP servers are connected to at every attempt. An open event stream on Lambda is one invocation, billed while it is open: see Lambda or containers.

Status: a reference implementation, tested end to end locally and in CI on every change that touches it - against DynamoDB Local and a stand-in for SQS. It has not yet run on a live AWS account: what that leaves unproven is the checklist before a first terraform apply.

None of the four is deployed by this repository: each README’s deploying section is the owner’s commands.

Pipelines drawn in an editor, run by a server

Section titled “Pipelines drawn in an editor, run by a server”

The pipelines executor (examples/pipelines) is not a swarm of conversations but a server for pipelines - graphs of agents drawn in Pipeline Studio (apps/studio) and stored as versions of the pipeline definition format. It starts a version on request, streams every node’s state, retries the node a run failed at (the nodes done before it are not run again; its agent resumes from the call journal) and cancels a run. It runs on the Cloudflare port’s platform - a Durable Object per run, a Workflow instance per attempt, the core’s graph engine as the scheduler - and reuses its agent setup; wrangler dev runs it locally with no account. Each person deploys it with their own keys.

All four run the same code for everything that does not depend on the platform: swarm-shared holds the session’s logic, the ids, the answer checks, the event cursor and the HTTP API itself, as a fetch-style handler ((request: Request) => Promise<Response>). A client written against one swarm talks to the other three without a change.

  • Sessions. A session is one conversation. POST /sessions starts one (with an optional first message), POST /sessions/:id/messages adds a message, GET /sessions/:id reads its state, POST /sessions/:id/stop stops the running turn (and, with { "end": true }, ends the session).
  • Turns. A turn is one agent.run on the messages that arrived. Messages sent while a turn runs wait and become the next turn, together. A turn whose worker dies is resumed elsewhere from its last checkpoint, under the next attempt.
  • Events over SSE. GET /sessions/:id/events streams every event of the agent, in order, with turn.started and turn.ended around each turn. Each frame has a cursor (<turn>:<attempt>:<seq>): a client that reconnects with Last-Event-ID (or ?after=) gets what it missed, then the live stream. Delivery is at-least-once.
  • Parking on a person’s answer. A tool call that asks for approval (AGENT_TOOL_APPROVAL, AGENT_TOOL_RULES), or a tool whose result comes from outside, parks the turn: it holds no worker while it waits and goes on, as the same run, when POST /sessions/:id/answers/:requestId has brought every answer - minutes or days later.
  • Subagents and pipelines. SUBAGENTS and PIPELINES name static subagents and graphs of agents as tools of the session’s agent. A call parks the turn and runs as a child of its own (a child workflow on Temporal, a Workflow instance on Cloudflare, tasks of its own on Google Cloud, messages of its own on AWS) with its own event stream; its outcome answers the call.
  • Auth. Every route but /healthz and /readyz needs Authorization: Bearer <token>, one of GATEWAY_TOKENS. It is one shared secret for the whole API: put your own authentication and tenancy in front before serving several users. The shared gateway also has a visitor mode (GATEWAY_AUTH=visitor) for a chat on a public site - per-user tokens signed by your backend or an anonymous cookie, every session its visitor’s, credentialed CORS for exact origins, and per-visitor, per-address, per-network and all-visitors limits; it is wired in on Cloudflare (visitors).
  • Browser clients. The packages’ remote chat talks to this API: createRemoteAgentController (@dudko.dev/agent-web-ui), useRemoteAgent (React) and <dd-agent-chat backend="..."> (the web component) - the chat in the page, the model and its key on the server.

The full reference - every route, body and status code, the stream’s frames, the answer checks - is the HTTP API of the Temporal swarm; the Cloudflare, Google Cloud and AWS pages list the differences of their platforms.

The support chat of agent.dudko.dev (examples/support-cloudflare) is a Worker of its own on the Cloudflare swarm’s runtime, taken as it is through its ./worker entry (useAgentSetup, createSwarmFetch with the gateway’s admit hook) - the same Durable Objects and turn Workflow, re-exported, with no fork. Pick it as the model for a chat that anyone on a public site may talk to:

  • What it adds is an agent of its own (three skills over the project’s READMEs and docs, one tool that e-mails the author) and the guards of a public endpoint: text only, Turnstile before a session’s first message, a classifier in front of the agent, exact daily budgets, links only to the project’s hosts, no internal error text to a visitor, a screened and capped e-mail.
  • Visitors are the swarm gateway’s visitor mode: an anonymous __Host- cookie, every session its visitor’s, credentialed CORS for the site’s origin only.
  • In the page it is <dd-agent-chat backend="...">: the site’s round button opens it, and it loads nothing of the in-browser agent’s core.
  • Shipped as wrangler.jsonc, built by Cloudflare’s Workers Builds from this repository. Its tests run in Node and in wrangler dev with a scripted model; nothing here deploys it.

All four need an API key of a provider the example installs (OpenAI, Anthropic, Google, or any OpenAI-compatible server), and all four answer the same requests.

On Temporal + Postgres, with Docker and Compose v2 (the gateway on localhost:8080):

Terminal window
cd examples/swarm
cp .env.example .env # set GATEWAY_TOKENS and AGENT_API_KEY / AGENT_MODEL; never commit .env
docker compose up --build --scale worker=3

compose.yaml runs the Temporal dev server, which keeps everything in memory: it is for trying the swarm out. Production points TEMPORAL_ADDRESS at a real Temporal cluster; on Kubernetes there is the Helm chart.

On Cloudflare, locally in wrangler dev - no account, nothing deployed (the Worker on localhost:8787):

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

Deploying it to your account is a few wrangler commands.

On Google Cloud, locally on emulators - no Google account, no credentials, nothing deployed. The Firestore emulator is a Java program, so this needs Java 21 (the gateway on localhost:8080, the worker on localhost:8081):

Terminal window
pnpm install && pnpm nx run-many -t build -p @dudko.dev/agent,swarm-shared
cd examples/swarm-gcp
pnpm emulator:install # once: the Firestore emulator's jar (137 MB, checksum pinned)
cp .env.example .env # set GATEWAY_TOKENS and AGENT_API_KEY; never commit it
pnpm dev # the emulator, the tasks stand-in, the gateway and the worker

Nothing is kept when it stops: the emulator holds its data in memory. Deploying it to a project is Terraform and a container image, by hand.

On AWS, locally on stand-ins - no AWS account, no credentials, nothing deployed. DynamoDB Local is a Java program, so this needs Java 21 too (the gateway on localhost:8080):

Terminal window
pnpm install && pnpm nx run-many -t build -p @dudko.dev/agent,swarm-shared
cd examples/swarm-aws
pnpm dynamodb:install # once: DynamoDB Local's archive (43 MB, checksum pinned)
cp .env.example .env # set GATEWAY_TOKENS and AGENT_API_KEY; never commit it
pnpm dev # DynamoDB Local, the SQS stand-in, the gateway and the worker

Nothing is kept when it stops: DynamoDB Local runs in memory. Deploying it to an account is Terraform and a zip of the functions (or an image), by hand.

Then talk to any of them (port 8080, or 8787 for wrangler dev):

Terminal window
TOKEN=... # one of GATEWAY_TOKENS
S=$(curl -s -X POST localhost:8080/sessions -H "authorization: Bearer $TOKEN" \
-H 'content-type: application/json' -d '{"message":"What is 2+2?"}' | jq -r .sessionId)
curl -N localhost:8080/sessions/$S/events -H "authorization: Bearer $TOKEN" # the stream
curl -s -X POST localhost:8080/sessions/$S/messages -H "authorization: Bearer $TOKEN" \
-H 'content-type: application/json' -d '{"text":"And times 3?"}'