ADR-064: Serve mode: one app per deployment, runs before chat, and an HTTP API that is a profile of existing standards
Date: 2026-11-29 Status: proposed Deciders: Milan Pavel
Context
golem runs on your Mac, for you. Phase 21 (#2010) runs the same daemon and gateway in a Linux container behind an application. The app's backend calls an HTTP API to start workflow runs and chats for its own users, and golem returns results. The idea is in the vision.
Three things were open before any gateway code:
- Who a run belongs to. On a Mac the answer is "you". In serve mode there are many people, and golem does not know them.
- What the first API is. newmonday, the reference application, which lives in its own repository (Phase 22), is the first caller. It needs workflow runs with a review. Chat comes second.
- What the API looks like. There is no single standard for an agent gateway (checked 2026-11-29). There is one common shape for chat, several competing protocols for runs, and solid standards for plain HTTP.
The gateway today (ADR-028) serves one browser on 127.0.0.1 and passes protocol lines to the daemon. A workflow run today is a headless session with a workflow_run_id (ADR-050, ADR-062). Both are reused. This record adds no code and no protocol change. The API is written down in docs/api/serve-v1.yaml and shown on the Serve API page. Both say that it is planned.
Decision
One app per deployment
- One deployment serves one app. A second app is a second container.
- The definition of the app (agents, workflows, skills, settings) ships in the image under
/appand is read only. - State lives on a volume under
/data: SQLite, one replica. Postgres comes only when something pays for the port. - Models are endpoints, reached by URL. The image holds the agent, never the model.
- Serve is a row in a table of capabilities (step 21.1), not
if servespread over the code. The command isgolem serve.
The principal
A run and a session belong to a principal: the app's id for a person, such as u_8f2c.
- The app's key proves the app. The
userin the request is trusted, because the app authenticated that person. - The daemon enforces it, not the gateway alone. Every run, session and usage row carries the principal, and every read and write on the daemon side filters by it. A bug in the gateway cannot show one user's run to another.
- A run of another key or another user answers
404, never403. The two cases look the same, so a caller cannot find out which ids exist. DELETE /v1/users/{user}removes everything held about one user.- A key belongs to the app. A person never holds one. The principal of a call without
user(a listing, for example) is "the whole app".
Runs before chat
The first API is workflow runs with a review, because newmonday needs that. Chat completions follow in the same version of the document. They are in the contract now, so nobody builds a second shape later. Their tickets come after the runs tickets (21.9, 21.10, then 21.11).
A run is a resource, not a held-open request. POST answers 202 with Location, and the caller polls GET /v1/runs/{id} or follows the events. A model can take minutes and a review can take days, and neither fits one HTTP request.
Asking: ask = "deny" | "app" | "owner"
On a Mac, golem asks you. In serve mode nobody is at the terminal, so [serve] ask says who answers:
| Value | What happens | Version 1 |
|---|---|---|
deny | Nothing waits. An ask is answered "no" at once. A run.review gets the verdict reject and the run goes on, so no run is ever input-required. | yes |
app | The run waits. The open question is on the run as an interrupt, and the app's own user answers through POST /v1/runs/{id}/resume. | yes |
owner | The call waits in a queue for someone on the app's team, in an admin console. | no. Later. golem serve check refuses it. |
The default is deny. A deployment has to choose app to let a run wait. golem informs and does not refuse in silence: in deny the run's events say that a review was answered reject and why.
The gateway is on a private network first
The gateway does not face the internet in the first versions. The app's backend calls it on a private network, with a key. So:
- No CORS and no cookies. A browser never calls it.
- No TLS in golem. A proxy in front does that if the network needs it. mTLS is left to the proxy too.
- Auth is a bearer key,
gk_plus a random body plus a checksum. A secret scanner can find it. It is stored as a digest, shown once and revocable. A missing or bad key is401. A method list per kind of key says what a key may call (step 21.7). /healthzand/readyzneed no key. SIGTERM drains:/readyzanswers503and running work finishes.
A public listener is a later decision and gets its own record.
The standards profile
The API is a profile of existing standards. Where one exists, golem follows it and names it. The survey is dated 2026-11-29.
| Area | golem follows | Source |
|---|---|---|
| Chat | OpenAI Chat Completions with SSE. An agent is a model. End user in safety_identifier, or in user | OpenAI safety identifiers |
| Runs | 202 and Location, and a status resource to poll | AIP-151, long-running operations; OpenAI background mode for starting_after |
| Run states | The names submitted, working, input-required, completed, failed, canceled | A2A 1.0 |
| Review | The run pauses with a list of open questions, and a resume answers each by id | AG-UI interrupts |
| Streams | SSE, event id is the sequence number, resume with Last-Event-ID or ?starting_after= | WHATWG SSE |
| Retries | Idempotency-Key on every creating POST | IETF draft-ietf-httpapi-idempotency-key-header (draft-09) |
| Errors | application/problem+json, a stable code, and X-Request-Id | RFC 9457 |
| Limits | 429 with Retry-After | RFC 9110 |
| Auth | Bearer keys with a prefix and a checksum | Cloudflare token formats |
| Webhooks | webhook-id, webhook-timestamp, webhook-signature, HMAC-SHA256 (step 21.13) | Standard Webhooks 1.0 |
| Tracing | traceparent accepted and passed on. Prometheus /metrics (step 21.15) | W3C Trace Context; Prometheus exposition format |
| Contract | One OpenAPI 3.1 document, versioned by the /v1 path, changed only by adding | OpenAPI |
| Container | /healthz, /readyz, drain on SIGTERM, non-root, config from the environment, OCI labels | OCI image annotations |
OpenAPI is written at 3.1, not the newest 3.2, because the tools for 3.1 are common.
What was left out, and why
| Left out | Why not now |
|---|---|
| A2A as the API (A2A) | It is the best match for a run's life, so its state names are used. The wire (JSON-RPC, agent cards, push) is bigger than newmonday needs. An adapter can sit on top later, because the states already match. |
| LangChain Agent Protocol (repo) | One vendor, no stability statement, and resume is not specified. Its resource shapes were read, not copied. |
Open Responses (/v1/responses, spec) | A second chat surface later. It has no human review and leaves background undefined. |
| MCP as a server surface (MCP) | golem stays an MCP client. An app wants to call golem, not to give it tools. |
| OAuth 2.1 (draft) | Still a draft, and the caller is a backend that holds a key. |
RateLimit headers (draft) | The draft is not settled. 429 and Retry-After first. |
| CloudEvents (spec) | No signature. Standard Webhooks signs. |
OpenTelemetry gen_ai.* spans (conventions) | Still in development and names change. Maybe behind a flag. |
| WebSocket | SSE is enough for a one-way stream and works through every proxy. |
| Date-header versions | The /v1 path is enough. |
| Kubernetes Gateway API, Envoy AI Gateway | They route to model servers. golem only has to behave behind any proxy. |
| Model text deltas in the run stream | A step's result is the unit in version 1. A client that wants deltas uses chat. |
Tools the client runs (OpenAI tools) | A request with tools is refused with a clear error (tools_not_supported). |
The contract
The full contract is in docs/api/serve-v1.yaml. Here are its main points.
| Call | Meaning |
|---|---|
POST /v1/workflows/{name}/runs | Start a run. Body {input, user, metadata?}. Idempotency-Key. 202, Location: /v1/runs/{id}, and the run. The same key and body returns the same run, another body is 409. |
GET /v1/runs/{id} | The run: id, workflow, user, status, created_at, updated_at, output?, error?, interrupts[], usage, metadata. |
GET /v1/runs?user=&status=&after=&limit= | List, newest first, cursor in after. |
GET /v1/runs/{id}/events | SSE. id: is the sequence number, event: the type, data: JSON. Resume with Last-Event-ID or ?starting_after=. Ends after the terminal event. |
POST /v1/runs/{id}/cancel | Idempotent. |
POST /v1/runs/{id}/resume | Body {answers: [{id, verdict, text?}]}. Must answer every open interrupt, else 422. ?user= as the other calls. No Idempotency-Key: a repeat is 409 run_not_waiting. |
POST /v1/chat/completions | OpenAI shape, streamed and not. model is an agent. A request with tools is refused. |
GET /v1/models | The agents. |
DELETE /v1/users/{user} | Delete everything held about one user. |
GET /healthz, GET /readyz | No key. |
GET /metrics | Prometheus text, off unless [serve] metrics = true. Needs a key. Counted in the gateway process, no id in any label. |
Event types in version 1: run.status, step.started, step.finished, run.interrupt, run.output, run.error.
How the daemon serves these calls (step 21.9):
- Each
workflow.*notification of a run is also written toworkflow_events, with the next number of its run. That number is the SSEid:. A failed run logsworkflow.run.errorbeforeworkflow.run.failed, so each logged event is one API event and the terminalrun.statuscomes last.workflow.eventsreads a run's log after a number and, withsubscribe, sends the run's later events asworkflow.run.eventto that one connection, after the same principal check as every run call. It stops after the run's end or when the connection ends. App connections still get no broadcast. - The key of
Idempotency-Key, a digest of the request and the run are written in one transaction with the run, in the daemon (tableidempotency_keys, 24 hours, per app key). The gateway would need its own store to do the same, and two gateways would race. A second request with the key waits on the first one's write and gets the first run, soidempotency_in_progressis not answered today. GET /v1/runs/{id},/eventsand/canceltake the user as a requireduserquery parameter, since the daemon looks a run up for one principal.
From golem's run states to the API's
golem's states are in WorkflowRunStatus (packages/protocol/golem_protocol/commands.py) and are set by packages/daemon/golem/workflows/engine.py. The API never shows golem's names. The map is one function in the gateway, and it is total.
golem (workflow_runs.status) | API status | Notes |
|---|---|---|
pending | submitted | Saved, not yet started. |
running | working | |
waiting, with an open review | input-required | The run holds no task, slot or model while it waits. interrupts[] lists the open reviews. |
waiting, with no open review | working | This is on_restart = "ask" after a restart. Serve mode sets on_restart = "resume", so it should not happen. If it does, the caller has nothing to answer, so it sees working. |
done | completed | output is the workflow's result and what it marked with run.output. |
failed | failed | error has the reason. |
cancelled | canceled | One l in the API, as in A2A. golem keeps its own spelling. |
Reading it the other way: submitted, working and input-required are not final. completed, failed and canceled are final, and the events stream ends after the one that gets there.
Steps have their own states in the events (done, failed, skipped, in_doubt, from WorkflowStepStatus). They are not mapped. step.finished carries golem's name as it is, and a step that is in_doubt (a keyed step that may have had its effect before a restart) stays visible to the app.
golem event (workflow.*) | API event |
|---|---|
workflow.run.started, .waiting, .resumed, .done, .failed, .cancelled | run.status with the mapped status. workflow.run.failed also sends run.error. |
workflow.step.started | step.started |
workflow.step.done, .failed, .in_doubt (and a skipped step) | step.finished |
workflow.step.waiting of a review step | run.interrupt |
workflow.output.added | run.output |
workflow.step.progress | not sent (no model text in version 1) |
A review, and its answers
golem's run.review(draft, ask=) makes an open review: a step key, the ask text, the draft as JSON. Over the API it is an interrupt:
{"id": "review:reply", "kind": "review", "title": "Send this reply?", "ask": "Look at the reply before it goes out.", "draft": "Hello Ana, ..."}id is the review's step key (key= of run.review, else review:<ask>), so an answer names the same thing in both. ask is the question the workflow asked. It is the text of the review and has nothing to do with the [serve] ask setting above, which says who answers.
An answer is {id, verdict, text?}. The verdict names are golem's own (WorkflowReviewVerdict), not A2A's or AG-UI's:
| Verdict | Meaning | text | What the workflow gets |
|---|---|---|---|
approve | The draft as it is. | Optional. The draft when left out. | {"verdict": "approve", "text": <draft>} |
edit | The person's version. | Required. | {"verdict": "edit", "text": <text>} |
reject | No. | Optional, for a reason. | {"verdict": "reject", ...}. The workflow decides what that means. |
POST /v1/runs/{id}/resume must answer every open interrupt in one call. The daemon applies all the answers with one method, workflow.review.answer_all: it checks every answer first, saves them in one transaction (a review answered meanwhile undoes the lot), and the run continues once none of its reviews waits (the rule of ADR-062, reused as it is). A run that waits on no review is 409 run_not_waiting; a second identical resume finds the run no longer waiting, so it is 409 too. resume takes no Idempotency-Key: the table idempotency_keys ties a key to the run it started, and a key for a resume would need a second meaning in it. So a run with two reviews resumes once. An answer that misses an open id is 422 answers_incomplete, and the run stays as it was. An edit without text, an unknown id, or a verdict that is not one of the three is 422 answer_invalid.
Errors and codes
Every error is application/problem+json with type, title, status, detail, and two more members: code, a stable short string, and request_id. A client branches on code. The set only grows. Every response, success or not, carries X-Request-Id. A caller's own X-Request-Id is kept, and a traceparent is kept and passed on.
The codes are listed in ProblemCode of the YAML. They are: invalid_request, invalid_key, not_found, workflow_not_found, model_not_found, input_invalid, idempotency_conflict, idempotency_in_progress, run_not_waiting, answers_incomplete, answer_invalid, user_required, tools_not_supported, unsupported_parameter, payload_too_large, unsupported_media_type, events_expired, rate_limited, budget_exceeded, upstream_error, draining, not_ready, internal_error.
Polish from the first caller (step 21.18)
The first real caller found some things awkward. Each is now in the contract, and the choice between the two options the ticket gave is the simpler one for a caller.
- Cancel says what happened. The answer is the run plus
canceled_by_this_call, always200. A409for a run that has ended would make every retry an error to handle. - The events stream starts with the state. A fresh connection (no
Last-Event-ID, nostarting_after) first gets a syntheticrun.statuswith the run's current state, with noid:line. With no id it never moves the client's resume point, so a drop before the first stored event is a fresh connection again, and a drop after one resumes after that event's id. The cost is that the state may be sent twice. - Step events.
step.startedmeans the step is running;step.finishedcarries its final state. No new event type. - Events expire.
[serve] keep_events_days(default 30, 0 keeps for ever). The daemon trims a run that has ended to its end events. A resume before the first kept event is410 events_expiredwithfirst_seq; the recovery is to connect with no position and take the state plus what is kept. - Required inputs.
@workflow(required=[...])names them, so an older declaration keeps its meaning (nothing required). A start that misses one is422 input_invalidwithfield, and an error with the same words on the socket. traceparentis a field ofworkflow.startandserve.chat.run, stored with the run (workflow_runs.traceparent) or insession.created, and shown by the run's info and bytrace.get.
How the YAML is kept honest
The docs job has no OpenAPI linter and this adds no dependency. packages/daemon/tests/test_serve_api_spec.py parses the YAML (PyYAML is already a dependency of the daemon) and checks that every $ref resolves, every operation has a unique operationId and a problem response, every secured call can answer 401, and the run states, verdicts and event types are the ones this record names. A ticket that changes the YAML changes this record or says why not.
Alternatives Considered
Alternative 1: Chat first, runs later
- Pros: The OpenAI shape is known, and every SDK speaks it.
- Cons: newmonday needs a run with a review. A chat completion cannot pause for days, and golem's workflow engine already does.
- Why not: Build what the first caller needs. Chat is in the contract, so its shape is not an afterthought.
Alternative 2: Adopt A2A as the API
- Pros: A standard, with the right states and a push channel.
- Cons: JSON-RPC, agent cards and its own task model. The app would learn A2A to start one workflow.
- Why not: Use its state names. Leave an adapter for later.
Alternative 3: Trust the user id at the gateway only
- Pros: Less work in the daemon.
- Cons: One bug in the gateway shows one user's run to another. The daemon would be unaware of users.
- Why not: The daemon holds the data, so the daemon enforces the principal.
Alternative 4: Hold the request open until the run ends
- Pros: One call, no polling.
- Cons: A model call takes minutes, and a review takes days. Proxies cut idle requests.
- Why not:
202and a status resource is the standard pattern for this.
Alternative 5: Use golem's own state names on the API
- Pros: No map to keep.
- Cons: golem's
pending,waitinganddonemean what they mean to golem.waitingis not always a question for the app. A client that knows A2A would not recognise them. - Why not: One small, total map is cheaper than a second vocabulary for every client.
Consequences
Positive
- The gateway tickets (21.7, 21.9, 21.10, 21.11) and newmonday (22.10) build against one document.
- A run that waits on a review survives a restart, because the workflow engine already does.
- A client that speaks OpenAI, A2A's state names or Standard Webhooks finds nothing new to learn.
- The app is the only caller, and a key is the only credential, so there is no login code to write.
Negative
- The API is a profile, so it is not a drop-in for any one standard.
cancelledin golem andcanceledin the API are two spellings of one thing.askmeans two things in two places (a review's question, and the[serve] asksetting). The names are kept because each is the natural one where it is used.
Risks
| Risk | Handling |
|---|---|
| The draft standards move (idempotency key, rate limits, OAuth 2.1) | Only the settled parts are used: the header name, 429 and Retry-After. The rest is left out. |
| A workflow with a state that does not fit the map | The map is total over WorkflowRunStatus, and a test in step 21.9 covers each value. A new golem state fails that test. |
| The contract and the code drift | The YAML is checked in CI. Each serve ticket runs its calls against it, and the contract changes only by adding. |
deny hides a review a workflow needs | A run in deny says why in its events. Step 21.5's golem serve check can warn about a workflow that has a run.review. |
usage has no token counts today | The workflow journal keeps cost_usd for llm steps only. Step 21.9 sends usage.cost_usd as recorded and leaves the token counts out (absent, not zero) until a step keeps them. |
References
- Vision: serve mode
- The Serve API page and
serve-v1.yaml - ADR-028, ADR-050, ADR-062
- Phase 21 (#2010), this step (#2015)
- Mocks (on the maintainer's Mac):
golem-docs/mocks/serve-mode/