Skip to content

What goes in /app ​

In serve mode (ADR-064) one container is one app. The app is a folder, /app in the image, that ships with the image and is read only. Everything golem writes goes somewhere else, on a volume. This page is the whole of that folder, so you do not have to piece it together from the settings, the run guide and the Serve API.

The layout ​

text
/app
├── config.toml        # settings: the default model, providers, [serve]
├── agents/            # one NAME.md for each agent. The names are the models of chat completions
├── workflows/         # one NAME.py for each workflow. The names are what POST /v1/workflows/NAME/runs starts
├── measure/           # one NAME.toml for each Measure set, run by golem serve measure before a deploy
└── skills/            # one folder for each skill, with a SKILL.md in it

Every part is optional. An app that only serves workflows has config.toml and workflows/. examples/serve/app is a small one.

golem does not write into /app. A write that would land there is refused with the name of the variable that moved it.

config.toml ​

The same file as the settings, with the keys that serve mode needs:

toml
default_model = "anthropic/<model-id>"   # a model of a provider below, or a [models.<name>] you define

[providers.anthropic]
api_key_env = "ANTHROPIC_API_KEY"        # the variable the key is read from. The key itself is never in this file

[serve]
ask = "deny"            # "deny": a review is answered "reject" at once. "app": the app's user answers it
drain_seconds = 25      # after SIGTERM, how long open requests and streams may finish
keep_events_days = 30   # how long a run's stored events are kept after it ends. 0 keeps them for ever
keep_days = 0           # 0 keeps runs for ever; 30 removes ended runs, and what belongs to them, after 30 days
metrics = false         # true turns on GET /metrics (needs a key of the app)

[serve.limits]          # all optional; what is shown is the default, and the two money limits have none
requests_per_minute = 600   # per key, kept by the gateway
streams_at_once = 64        # open event and chat streams per key, kept by the gateway
runs_at_once = 4            # per user, runs and chat turns that are executing
runs_at_once_total = 32     # the whole deployment
# user_usd_per_day = 2.00   # per user, per UTC day
# key_usd_per_day = 200.00  # per key, per UTC day

# [serve.webhooks]          # optional; leave it out and golem sends nothing
# url = "https://app.example/hooks/golem"
# secret = "secret:webhook/app"   # whsec_ and base64, read from /run/secrets/webhook_app
# events = ["run.completed", "run.failed", "run.canceled", "run.input_required"]
  • The default model is the model every agent and workflow uses unless its own file names another. A model is reached by an endpoint, so a provider with no endpoint (a local ollama with no base_url) is a problem for golem serve check: serve mode starts no local model server.
  • A provider has api_key_env, the name of an environment variable. A key written in the file is refused, and the file does not load.
  • [serve] is read from your file only. ask is "app" when the app's own user should answer a review (the API). keep_events_days is how long events live. keep_days removes old runs and what belongs to them (deleting a user and the sweep); golem serve check refuses a keep_events_days that is longer. metrics = true turns on GET /metrics (Watching a served golem). [serve.limits] keeps one user or one leaked key from running up the bill or starving the others: a caller over a limit gets 429 with Retry-After (Limits, the table). golem serve check reports values that make no sense. [serve.webhooks] tells your app when a run ends or needs an answer, so it does not have to poll (Webhooks). golem serve check refuses a URL that is not https (plain http is for localhost and private names, with a warning), a secret that is not set or not whsec_ and base64, and an unknown event name.

Agents, workflows and skills ​

FolderA file isUsed by
agents/NAME.md: a header (description, model, tools) and the system prompt. Only the tools serve mode has: no shell, no file writesPOST /v1/chat/completions with "model": "NAME", and run.agent in a workflow
workflows/NAME.py: a function marked @workflow(inputs={...}, required=[...]). See workflowsPOST /v1/workflows/NAME/runs
skills/NAME/SKILL.md, as in skillsan agent or a workflow step that names it

GET /v1/models lists the agents. A workflow file that does not load is not startable, and golem serve check says why.

Secrets ​

A secret is never in /app. In serve mode golem reads secrets from files and variables and never writes them. A secret named mcp/github is the file $GOLEM_SECRETS_DIR/mcp_github (the folder is /run/secrets unless set), else the variable GOLEM_SECRET_MCP_GITHUB. A provider's key is its api_key_env variable. The rule for the names is in settings.

Checking the folder ​

sh
GOLEM_APP=./app golem serve check

It starts nothing and calls no model. It prints one line for each problem and exits 1: a config.toml that does not parse, an agent or workflow that does not load, a tool an agent names that serve mode does not have, a secret that is named and not set, a model with no endpoint, [serve] ask = "owner", and a [serve.webhooks] with a url that is not https, a secret that is not set, or an event golem does not have, and a keep_events_days that is longer than keep_days. Run it in CI before you build the image. It reads the Measure sets too (see Measure before you deploy).

Keys ​

The API is called with a key. Make one inside the running container:

sh
docker compose exec golem golem serve keys create --name demo   # prints the key once
docker compose exec golem golem serve keys list
docker compose exec golem golem serve keys revoke demo

golem keeps only a digest of a key, so a lost key is revoked and made again.

The three variables ​

The image sets them. Set them yourself when you run golem serve outside it.

VariableIn the imageIs
GOLEM_APP/appThe definition: the folder on this page. Read only. Without it, the definition is GOLEM_HOME
GOLEM_HOME/dataThe state: databases, logs, anything golem writes. Put it on a volume. One replica uses one
GOLEM_RUN/run/golemThe socket between the listener and the daemon, and the pid lock

The socket is a file under GOLEM_RUN, and an operating system limits its path: about 100 bytes (104 on macOS, 108 on Linux). Keep GOLEM_RUN short. /run/golem is. A long path under a build directory or a temporary folder is the usual cause of a daemon that will not start.

Measure before you deploy ​

A Measure set is a file measure/NAME.toml in the app folder. It lists cases. A case asks one of the app's agents a question, or starts one of its workflows, and checks the text that comes back. golem serve measure runs the sets before the new version takes traffic and stops the deploy when the agents got worse.

toml
description = "the support agent still answers"
pass_mark = 0.8            # optional: the share of cases that must pass. Without it --min-score is used

[[case]]
name = "refund"
agent = "support"          # an agent of the app. Or: workflow = "NAME" with inputs = { n = 4 }
ask = "How do I get a refund?"
contains = ["30 days"]     # every text must appear (case does not matter)
not_contains = ["sorry"]   # none may appear
matches = "\\d+ days"      # a regular expression that must match

A case passes when all its checks hold. The score of a set is the share of its cases that pass, from 0 to 1. A set passes when its score reaches its pass mark: its own pass_mark, else --min-score, else 1 (every case).

sh
GOLEM_APP=./app golem serve measure --min-score 0.8
OptionDoes
--set NAMERuns only this set. Repeat it for more
--min-score NThe pass mark of a set that has none (0 to 1)
--max-usd NStops the run when the spend reaches N dollars. The sets not run yet fail
--jsonPrints one JSON document instead of lines
--home DIRKeeps the state in DIR, so two runs can be compared. Without it a temporary folder is used and removed

The exit code is the verdict: 0 every set passed, 1 a set failed (or --max-usd stopped the run), 2 it could not run: a set that does not load, an agent or workflow a case names that is not in the app, a model key that is not set, or a state folder that is the live one. It prints one line for each set (score, cases passed, cost) with the failed cases named under it, then the cost of the whole run and the verdict.

It runs with the app's own agents, workflows and config.toml, in serve mode (no ask waits for a person, only the tools serve mode has), and it calls the model for real, so it costs money. It starts no listener and takes no traffic. It runs a daemon of its own on a state folder of its own and never opens the data of the live deployment; --home may not be the live GOLEM_HOME. Each run writes its report to DIR/evals/gate/. golem serve check reads the sets too.

The image runs any command you put after its name instead of the server, so the gate is a one-off container of the image you are about to ship. With --read-only, give it a --tmpfs /tmp for its temporary state folder.

In GitHub Actions, run it on the image you are about to ship, with the provider key as a secret:

yaml
- name: Measure before deploy
  run: |
    docker run --rm -e ANTHROPIC_API_KEY=${{ secrets.ANTHROPIC_API_KEY }} \
      ghcr.io/example/my-app:${{ github.sha }} golem serve measure --min-score 0.8 --max-usd 2
- name: Deploy
  run: ./deploy.sh   # runs only when the step above exited 0

In compose, run it as a one-off before you bring the new version up. The app service is the same as the one that serves:

sh
docker compose run --rm app golem serve measure --min-score 0.8 --max-usd 2 \
  && docker compose up -d app

Next ​