Skip to content

Workflows ​

Design of Phase 3 (#18). The decision is in ADR-062. This page is the shape of the thing: the words, the API, the storage, the events, and the order of work.

Paths below start with D/ for packages/daemon/golem/.

What a workflow is ​

A chat is great once. A workflow is for when the same job comes back: every Monday, on every new invoice, for each outdated package. Your Python decides the order. Models and helpers do the fuzzy steps. golem keeps the rest: every step saved, restarts survived, reviews that wait for days, real-world actions that happen once.

WordWho decides what happens nextFileExists
SkillThe model, following written instructionsSKILL.mdYes, Phase 2
HelperThe lead model starts it with delegate; a child session with a briefagents/*.mdYes, Phase 15
RoutineA trigger: a time, a new file, later a webhookroutines.tomlYes, Phase 4
WorkflowYour code; models and helpers do the stepsworkflows/*.pyNo: this design

How the layers sit:

LayerWhatExists
Workflow runRows in workflow_runs and workflow_stepsNew
Headless sessionOne per run, origin="workflow:<name>"Yes (4.0)
HelperEach run.agent is a child session of that sessionYes (ADR-059)
DispatcherEvery model call waits here. run.llm takes the job roleYes (ADR-060)

The API ​

The only module user code imports is golem.workflow (D/workflow/__init__.py).

NameMeaning
@workflow(inputs=)Marks an async function as a workflow. trigger= is still accepted but never used; a routine is the only "when".
RunThe object each workflow receives.
run.step(name, fn, *args, key=)A plain function. The result is saved.
run.parallel(...)Steps or agents at once.
run.agent(type, brief=, gets=, worktree=, budget=)A helper.
run.review(draft, ask=)Waits for you. Returns what you approved.
run.notify(text)Tells you.
run.llm(...)One model call through a dispatcher job slot.
run.tool(...)One tool, through the permission engine.
run.skill(...)One skill in the run's headless session.

Rules:

  • key= means "do this once". A finished keyed step never runs again. A crash between the action and saving its result leaves the step "may have run". On retry, the key goes to the receiver as an idempotency key.
  • Step keys are unique within a run and stable across restarts. A repeated key fails the run.
  • The model is written in the file (3.13.7): @workflow(model=) is the default and model= on a step overrides it; with neither, golem's default model is used. The old wish words (cheapest, stronger) still work. type names an agent file. See ADR-062, amended 2026-11-27.
  • gets= hands earlier results over as they are (saved artifacts), without retelling them.
  • worktree= needs copies (15.10). Until then, Check fails it with "copies arrive with 15.10".

Example: upgrade_dependencies ​

python
# workflows/upgrade_dependencies.py
from golem.workflow import Run, workflow
from .packages import list_outdated, open_pull_request

# A routine (`weekly mon 06:00`) starts it.
@workflow()
async def upgrade_dependencies(run: Run) -> None:
    outdated = await run.step("list outdated", list_outdated, run.repo)
    if not outdated:
        return
    upgrades = await run.parallel(
        run.agent("worker",
                  brief=f"Upgrade {p.name} to {p.latest}. Fix what breaks. Run the tests.",
                  worktree=f"upgrade/{p.name}", budget="$0.50")
        for p in outdated
    )
    notes = await run.agent("reviewer", gets=[u.diff for u in upgrades],
                            brief="Check each diff. One line per package.")
    green = [u for u in upgrades if u.tests_passed]
    await run.notify(f"{len(green)} ready, {len(upgrades) - len(green)} need you")
    approved = await run.review(green, notes, ask="Open these pull requests?")
    for u in approved:
        await run.step(f"PR {u.package}", open_pull_request, u,
                       key=f"pr:{u.package}:{u.version}")

The outline of the same file, read from the code by fixed rules:

#Step in plain wordsKind
1List the outdated packagescode
2For each package, at the same time: a worker upgrades it in its own copy, up to $0.50agents
3A reviewer checks every diffagent
4You are told how many are readynotify
5You are asked: open these pull requests?review
6For each approved one, a pull request is opened, exactly oncecode, keyed

The same rules name things in words. A title= or key= written as "A" if c else "B" shows A, and the other texts go to title_later and key_later. A code step is named by a # step: Some words comment above it, else by the name of the function it calls made readable (its docstring's first sentence is does), else by its source text, and then it is small (clients fold small steps into a line). The last return is the one end step (finish) and gives the keys or fields it returns. Any other return and every raise is not a step: it is an entry of next of the step before it (to is finish or fail, text says the message in words, scope is loop when it leaves a loop). maybe marks a step under an if. A step inside a for or while has a loop such as "Up to 2 tries", and next says where a step goes on an error, on an early return, or at the end of the loop. Old fields (for_each, condition, title) keep their meaning.

Run lifecycle ​

StateMeaning
queuedAsked for, not started.
runningThe code is running a step.
waitingA run.review waits for you. Nothing is held: no task, slot or model.
doneThe function returned.
failedA step raised and nothing handled it.
cancelledYou stopped it.
interruptedThe daemon stopped. The run continues on the next start (3.3).
Step stateMeaning
pending, running, done, failed, skippedAs the words say.
waitingA review step that waits for your answer.

Flow:

  1. workflow.start (a person, or a routine) makes a workflow_runs row. The headless session workflow:<name> is made later, the first time a step needs one (an agent, a skill, a tool that reads the session); a run of plain steps has none.
  2. The engine calls the function. Each run.* call becomes a workflow_steps row, keyed by its step key.
  3. A step that is already done returns its saved result and does not run.
  4. After a restart, the engine calls the function again from the top. Finished steps return saved results. Running agents continue from their last saved turn (reconcile_helpers, resume_helper).
  5. A review step writes a workflow_reviews row in the PendingItem shape and stops. The answer resumes the run.

A workflow file that changes while a run is open is versioning (3.7, stage F).

Storage ​

New tables in D/store/migrations.py, accessed through D/store/workflow_runs.py. Columns are a first sketch; ticket A.2 fixes them.

TableHoldsMain columns
workflow_runsOne row per runworkflow_run_id, workflow, session_id, state, inputs, trigger, started_at, ended_at, error
workflow_stepsOne row per stepworkflow_run_id, step_key, name, kind, state, result, helper_session_id, cost, started_at, ended_at
workflow_reviewsOne row per run.reviewworkflow_run_id, step_key, pending (a PendingItem), answer, answered_at

The engine is golem's own step journal in workflow_steps (ADR-062, section "Engine"). A run.agent row saves its child session_id as soon as the helper starts, so after a restart the step re-attaches to the child instead of starting a second one.

Events and commands ​

Names on the wire never use run.* (ADR-050). The id is workflow_run_id.

KindNameTicket
Commandworkflow.list, workflow.get, workflow.start, workflow.status, workflow.cancel, workflow.resumeA.1
Commandworkflow.resume, workflow.review.answerB
Commandworkflow.check, workflow.outlineE
Eventworkflow.run.started, workflow.run.waiting, workflow.run.done, workflow.run.failed, workflow.run.cancelledA.1
Eventworkflow.step.started, workflow.step.done, workflow.step.failed, workflow.step.waitingA.1

The exact list of events is fixed by A.1. Each protocol ticket takes the next minor version just before it ships (now 2.155).

How helpers are used ​

In a chat, the lead model calls delegate. In a workflow, your code calls run.agent. After that the machinery is the same: the same child session, agent file, limits, questions, card and slots.

Workflow fileWhat golem doesState
run.agent("worker", brief=...)One helper, a child session of the run's headless session, from agents/worker.md (15.1, 15.2)Built
No model=The agent's wish (cheapest or stronger), resolved by routing (15.3, Phase 9)Built
model="local"A wish for this one step (a model name works too, 3.13.7)Built
budget="$0.50"Helper limits: calls, working time, cost (15.6, D/sessions/helper_limits.py)In progress
The helper asks youA pending item in the run's session, shown in Runs, Inbox and on the phone (15.5)Built
run.parallel(run.agent(...) for ...)One batch. The dispatcher decides how many run at once (15.8, 18.2)15.8 open
worktree="upgrade/httpx"A copy under ~/.golem/copies, the helper writes only there and returns a diff (15.10)Not built
gets=[...]Earlier results handed over as saved artifactsNew
fix.diff, fix.applyThe worker's change set. Applying goes through Phase 16, so undo worksAfter 15.10
The helper card, Open, StopThe same card and panel as in a chat (15.7, 15.12)Built
Resume after a restartHelpers: reconcile_helpers, resume_helper. The workflow: saved steps (3.3)3.3 new
Settings › Agents "Use helpers"Does not apply. "Ask me first" is the Run dialog, shown on manual runs and skipped for routine runsDecided

The seam ​

D/workflows/agents.py holds WorkflowHelpers.start(run, step_key, specs). It resolves agent files, wishes and limits, then calls SessionManager.start_helper(parent=<run's session>, call_id="wf:<step key>", ...) and waits with helper_results. It never touches dispatcher internals. Ticket A.6 first moves the part of start_helpers that does not need the chat graph's state into a function that both paths call. When 15.8 and 15.10 change, only this file follows.

What can start when ​

WhenWhat works
NowA single run.agent on the run's headless session, read-only or writing in the project folder (with the permission engine), steps one after another. Enough for pr_digest, triage_issue, release_notes.
After 15.8run.parallel of agents as one batch with positions and wait reasons. Before that, agents start one by one and the dispatcher still overlaps their model calls.
After 15.10worktree=: workers in copies and diffs to review.

Local, cloud, mixed ​

SetupUpgrade workflowThe editor shows
Local onlyWorkers and reviewer on local models, slots decide how many at once, $0The model on this machine and its slots. A pinned paid model is a Check warning.
Cloud onlyWorkers on the cheapest hosted model, reviewer on the stronger. Provider caps decide how many at onceAn estimate that is never $0.
MixedWorkers local, reviewer hosted. A stuck worker may step up if its file allowsBoth chips. The Run dialog lists what is paid.

Each agent-step ticket states its behaviour and has a test for local-only and cloud-only.

Check and Try ​

CheckTry
Model usedNoneOnly for the steps that run
What it doesReads file, outline, agent files, inputs, trust. Reports what will not workRuns in a copy of the project, from a chosen step, using the last run's saved results for earlier steps
Stops beforeNothing runsEvery run.review and every step that touches the world (key= steps, run.notify)

Trust and broken files ​

  • Files load only from trusted folders (trusted_folders, same rule as agent files).
  • Each file is imported in a short-lived subprocess to list and check it, so a crash or hang at import never reaches the daemon. A run is an asyncio task in the daemon; an exception fails the run or the step, never the daemon. Sync functions run in a worker thread.
  • A broken file is listed as "broken" with its traceback. A fixed file loads again without a restart (hot reload).

Stages ​

Tickets are split one stage at a time, because Phase 15 and 18 keep moving. Each stage ends with something that works.

StageStepsYou canDepends on
0 Design3.0 (#739): ADR-062, this page, engine spikeRead one ADR; stage A tickets existNone
A Skeleton3.1 (#11) registry and golem workflow run; 3.2 (#12) workflow_runs, workflow_steps, events, run.step, run.parallel of plain stepsRun a code-only workflow from the CLI and see its steps0
B Durable and patient3.3 (#13) resume after kill -9; 3.4 (#14) run.review and run.notify; 3.5 (#15) key=Survives a restart, waits for you, posts onceA
C Agents3.6 (#16) run.agent (single agent first); 3.8 (#740) run.llm, run.tool, run.skillThe upgrade workflow, agents one after anotherA, B; 15.2 (built)
C2 Agents at once, in copiesrun.parallel of agents via 15.8's batch; worktree= via 15.10Five upgraders at once, each in a copy15.8 (#1216), 15.10 (#1218)
D Seen and triggered3.9 (#741) Workflows page and run detail on StepsList; Inspector Steps (R1, mostly 15.7); TUI /workflows, /runs; 4.8 (#794) routines start workflowsSchedule it Monday 06:00; watch it in web and TUIB (C for agent rows)
E Authoring3.10 (#1224) make from chat; 3.11 (#1225) editor, cut 1 (outline, code, ask golem, check), cut 2 (fields, try from step, outline in words)Edit, check, tryD; Phase 16 change set
F Later3.7 (#17) versioning; 4.5 (#84) hook start_workflow; bundled startersNone yetB

Milestones:

MilestoneStages
M40, A, B, C (single agent), D (with 4.8): the PR digest end to end
M5C2, E, 3.7

Bundled starters: pr_digest, upgrade_dependencies, flaky_test_hunt, invoices_to_sheet.

Stage A, split ​

TicketWhatFilesAfter
A.1Protocol: commands workflow.list, get, start, status, cancel; events workflow.run.*, workflow.step.*; codegen; vectors. One minor bumpgolem_protocol/{commands,events,methods,version}.py3.0 merged
A.2Storage: workflow_runs, workflow_steps: migration and storeD/store/migrations.py, D/store/workflow_runs.py3.0
A.3Public API skeleton: @workflow, Run, run.step, run.parallel (plain steps)D/workflow/__init__.py, D/workflows/engine.pyA.2
A.4Registry: find files, trust, import in isolation, "broken" with traceback, hot reloadD/workflows/registry.py3.0
A.5Server and CLI: handlers, golem workflow list and run with live stepsD/server/workflows.py, packages/cli/src/workflows-*.tsA.1, A.3, A.4
A.6Seam: split start_helpers so its graph-free part is callable, no behaviour changeD/sessions/manager.pyCoordinate with 15.8; after 15.8.1 is merged
A.7Outline from code (AST, fixed rules)D/workflows/outline.pyA.3
A.8Guide page and an example workflowdocs/guide/workflows.md, examples/A.5

A.2, A.4 and A.7 touch no shared file, so they can run while 15.x is busy in manager.py. A.6 is the only ticket that touches helper code.

Keeping out of the way of Phase 15 and 18 ​

RuleWhy
New code lives in its own modules: D/workflow/ (the public API) and D/workflows/ (registry, engine, outline, check, agents)Few merge fights
Shared files get only small, additive edits: D/sessions/manager.py (one entry point to start a helper under a workflow session), D/store/migrations.py, golem_protocol/methods.pySame
Protocol bumps: each Workflows ticket rebases and takes the next minor version just before it ships. Never stack Workflows protocol PRs on 15/18 PRsThe version number is the hot spot
run.agent calls the helper API only through start_helper and helper_resultsWhen 15.8 and 15.10 change, only C2 follows
Every stage's first ticket re-reads ADR-059, ADR-060 and the open 15/18 PRs before it is splitThey keep moving
One implementation lane for Workflows. The other lane stays with 15/18Mac load, review load

Where the code goes ​

PathHolds
D/workflow/__init__.pyThe public API: workflow, Run, schedule
D/workflows/registry.pyFind files, trust, isolated import, "broken", hot reload
D/workflows/engine.pyRun, save each step, resume, try from a step
D/workflows/outline.pyCode to outline (AST, fixed rules)
D/workflows/check.pyChecks that run no model
D/workflows/agents.pyrun.agent to start_helper (the seam)
D/store/workflow_runs.pyworkflow_runs, workflow_steps, workflow_reviews
D/server/workflows.pyThe workflow.* handlers
packages/view/src/workflows.tsOutline and run rows. Reuses steps-list.ts and runs.ts
packages/web/src/features/workflows/Library, editor, Run dialog (replaces the WorkflowsInProgress placeholder)
packages/tui/src/workflows-*.ts/workflows

Risks ​

See ADR-062, section "Risks".

Mocks ​

The agreed look and flow are on the maintainer's Mac in golem-docs/mocks/workflows/: index.html (the idea and the example), helpers.html (helpers), editor.html (the editor), runs.html (runs), plan.html (stages and risks).