akm docs

Author's Guide: Writing Workflows

Deprecated. Workflows are removed in 0.11, when tasks take over ordered steps. See STABILITY.md.

This guide walks through writing and testing a workflow definition: the Markdown structure, a minimal complete example, common authoring mistakes, and how to verify gates and outputs before you publish. It assumes you already know what a workflow is; for the exhaustive, exact-syntax reference — every frontmatter key, the reference grammar, gates, and outputs — see Workflow Schema. For operating a run once it's written, see Running Workflows.

Start from the template

A workflow is a Markdown file: OKF-conformant frontmatter carries the orchestration graph and the body carries instructions and gate rubrics.

Use akm workflow create --print to print a valid starter, then edit it and register it with akm workflow create. Validate with akm lint:

akm workflow create my-release --print   # Print the template, without writing
akm workflow create my-release --from ./my-release.md
akm lint --type workflows                # Check for structural errors before using it

Markdown is the only workflow format. The GitHub-shaped .yml format was removed in 0.10: a .yml file under workflows/ is skipped at index time with a warning that it must use .md.

A minimal complete example

---
type: workflow
description: Ship a tagged release to production
params:
  version: { type: string, description: The semver version string to release }
steps:
  - id: validate
  - id: build
    inputs: [steps.validate.output]
---

# Ship Release

## validate

Check that the `version` parameter follows semver and the tag does not
already exist.

### gate

- `git tag v<version>` does not already exist.
- The version string matches `^\d+\.\d+\.\d+$`.

## build

Run `npm run build && npm test`, using the validation from `validate`,
attached to this unit as input. Fix any failures before proceeding.

Walking through it: validate and build are both bare unit steps — neither declares unit: or map:, so each is "still a unit step," the minimal declaration. build names steps.validate.output in inputs:, so the engine attaches validate's result to build's dispatched context, and build's own re-dispatch on a resumed run is keyed to that exact slice — not the whole run. validate has a ### gate; build does not, so build completes as soon as its unit succeeds, with no verification pass.

For a richer example — fan-out with map, retries, and a run budget — see Workflow Schema: Richer example.

Deterministic steps: run a command, gate on it

Not every step needs a model. Running the test suite, building, linting, or invoking a script is deterministic work: there is exactly one right answer and the command already knows it. A step whose unit: declares exec: runs that command directly — no LLM, no agent, no tokens, no nondeterminism.

The canonical shape is a test step that gates the rest of the run:

---
type: workflow
description: Fix a failing test, then verify the suite is green
params:
  failure: { type: string, description: The failing test name or error }
steps:
  - id: fix
  - id: test
    inputs: [steps.fix.output]
    unit:
      exec:
        command: ["bun", "run", "test:unit"]
      timeout: "10m"
      retry: { max: 1, on: [timeout] }
  - id: report
    inputs: [steps.test.output]
---

# Fix and Verify

## fix

Find the cause of the failure described in the run parameters and fix it.
Explain what you changed and why.

## test

Run the unit test suite. This step is deterministic: the command's exit code
decides whether the run continues.

## report

Summarize the fix and the test results attached to this unit.

What this buys you:

Getting a typed result instead of raw text

If the command can print JSON, declare an output schema on the unit and the step artifact becomes a validated structure:

  - id: test
    unit:
      exec:
        command: ["bun", "run", "test:unit", "--reporter=json"]
      output:
        type: object
        required: [passed, failed]
        properties:
          passed: { type: number }
          failed: { type: number }

stdout must then be exactly one JSON value — no log noise around it — and downstream steps can address steps.test.output.failed.

Agent in, exec out

A common pair is an agent step that writes something and an exec step that acts on it. Give each unit its own output schema:

steps:
  - id: draft
    unit:
      output:
        type: object
        required: [status, markdown]
        additionalProperties: false
        properties:
          status: { type: string, enum: [done, blocked] }
          markdown: { type: string, minLength: 1 }
  - id: publish
    inputs: [steps.draft.output]
    unit:
      exec:
        command: ["node", "publish.mjs"]
      output:
        type: object
        required: [posted]
        properties:
          posted: { type: boolean }

The command is an argv array, so nothing is spliced into it. publish.mjs reads the draft from AKM_INPUTS, a JSON object keyed by each inputs: reference string exactly as written, and prints one JSON value that matches its own unit.output:

const inputs = JSON.parse(process.env.AKM_INPUTS ?? "{}");
const draft = inputs["steps.draft.output"];
// ...post draft.markdown; log to stderr, never stdout...
process.stdout.write(JSON.stringify({ posted: draft.status === "done" }));

The rule: a unit schema (unit.output) types that unit's result. A step schema (step-level output:) validates the promoted step artifact, which for a map step is the reducer's result. On a solo step with no unit.output, a step-level output: is also used as the unit's schema; writing it under unit: says so explicitly.

An agent that cannot do the work still "succeeds": it returns something that fits the schema, such as status: blocked, and the step completes. If the run must stop when the work was not done, make the unit schema require evidence of the work, such as a required non-null string with minLength: 1 (a URL, a path, a commit id) that the agent can only fill by doing it.

What the command can see

The command inherits your environment, as it would typed in your shell: PATH, HOME, the toolchain variables and any credential of the process that ran akm run reach it. Then come your env: bindings, then the AKM_* context variables. Ordinary commands (bun, git, make, cargo) work unchanged.

  - id: build
    unit:
      env: [env/build]
      exec:
        command: ["cargo", "build", "--release"]

Fixed values belong in exact named env: bindings, and they reach the journal as they are. A credential belongs in secrets/, bound by a ${secrets/name} token inside the env asset; only values substituted from such a ref are redacted out of everything journaled (see Binding a secret to a unit). A value the command inherited is not redacted.

exec.pass_env:, the list of names an earlier release copied into an otherwise empty environment, still parses and selects nothing. Workflow starts freeze the durable plan v4 family's current executable format (irVersion: 8), which rejects inherit_env; the command inherits the environment without it. Pre-irVersion-5 stored plans do not execute; start a new run after updating the source.

Named bindings are part of the unit's input hash, so changing them re-runs the command instead of reusing a row recorded under another scope. What the command sees is described under Workflow Schema: The child's environment.

Using scripts, env and secrets from other bundles

A workflow in one bundle can run a script from a second bundle, with an env asset from a third that names a secret in a fourth. Each is addressed by its akm ref, [bundle//]conceptId, inside a ${...} token:

  - id: status
    unit:
      env: [ci//env/status]                       # env/status.env in bundle ci
      exec:
        command: ["bun", "${tools//scripts/lab-status/fetch.ts}"]
# env/status.env in bundle ci
REGION=east
TOKEN=${vault//secrets/status_token}

${tools//scripts/...} becomes the script's absolute path when the unit dispatches, ${vault//secrets/status_token} becomes the secret's value, and REGION reaches the child as it is. Nothing in the plan records where any of them lives, so updating a bundle in the middle of a run is harmless. The unit runs in the root of the bundle that holds the workflow (cwd: is relative to it, or absolute). See Workflow Schema: The exec contract.

Things to get right

Full reference: Workflow Schema: Exec (shell) units.

Common authoring mistakes

Typing what a step returns

An output: schema (and each params: entry) is a JSON Schema, and the engine validates the result against it before the step can complete. The runtime enforces a bounded subset of JSON Schema — anything outside it is an authoring error at akm lint, never a silent no-op, because a gate depending on a schema that constrains nothing is worse than a loud failure.

Enforced: type, enum, properties, required, items, additionalProperties: false, minItems, maxItems, minLength, maxLength, minimum, maximum, and the combinators allOf, anyOf, oneOf, not.

  - id: release
    unit:
      output:
        type: object
        required: [version, verdict]
        additionalProperties: false
        properties:
          version: { type: string, minLength: 1 }
          verdict: { type: string, enum: [pass, fail] }
          detail:
            oneOf:
              - { type: string, minLength: 1 }
              - { type: "null" }

release is a solo step, so its schema sits under unit: (see Agent in, exec out).

Outside the subset (each fails lint with the keyword named, its line, and a suggested replacement where one exists): $ref/$defs — inline the schema instead, since nothing resolves references; const — use a single-value enum; pattern and format — no regex or string-format constraint is evaluated at run time, so list the allowed values with enum when you can, bound the size with minLength/maxLength, and otherwise check the shape in the step's ### gate rubric, which can also say why a value is wrong; patternProperties, if/then/else, uniqueItems, multipleOf, tuple-form items, and schema-form additionalProperties (only additionalProperties: false is enforced). Annotation keywords — description, title, default, examples — always pass through untouched, and documenting each property is worth the keystrokes.

If lint reports a very broken workflow, note that its errors are sorted by line, so fix from the top and re-run — the later ones are usually fallout from the first.

Choosing where a step runs and which model

A step that dispatches a model runs on your default harness, or on akm's own runtime over your default connection when you have no harness. Leave that to the machine the workflow runs on. Name one only when a step needs it: harness: or connection: in defaults (or per-unit unit.harness / unit.connection), where a name the machine has not configured is an error that names it and lists what the machine has, so a workflow shared across machines should name a program only when it needs that one. Set defaults.model/unit.model to an alias rather than hardcoding an exact model id, so the workflow stays portable. The aliases are fast, balanced, reasoning and any a connection or harness maps in its models; see Workflow Schema: Model references for the exact resolution order.

Point reasoning work at a capable model and keep high-volume fan-out units on fast/balanced. The richer example's review map step is a good template: reasoning on the per-item reviewer, balanced as the run default for everything else.

Fan-out width

A map step runs its items in parallel by default, 4 at a time. Map units are independent by construction, so parallel is the default; the number is a modest 4 rather than "whatever the machine can take" so it stays predictable across the machines a workflow gets shared with.

Say so explicitly when the default is wrong for a step:

  - id: review
    map:
      over: steps.discover.output.files
      concurrency: 1     # serial — this step's units are NOT independent

concurrency: 1 is a genuine opt-out and always wins. Reach for it when the units touch a shared resource, when their side effects must happen in list order, or when they hit an external service you must not burst. To change the default for every workflow on a machine instead, including making fan-out serial wholesale, set akm config set workflow.defaultMapConcurrency 1.

The declared width is a ceiling, not a promise. Three other limits clamp it and the smallest wins: workflow.maxConcurrency, the selected connection's concurrency, and the host's CPU cap. The connection limit is the one that surprises people: a connection pointed at localhost defaults to 1, because local model servers hold a single loaded model and fall over under concurrent requests — so a map against a local model stays serial no matter what the step declares, until you raise that connection's own concurrency. Remote endpoints default to 4, and a step on a harness has no limit of this kind. See Workflow Schema: Fan-out and concurrency for the full table.

All of it is frozen into the run when it starts, so an in-flight or resumed run keeps the widths it began with even if you edit config or upgrade akm.

A fan-out runs N agents at once, not one. Document every params entry and describe destructive steps plainly in the body, so a reader (human or agent) can see what a run will do before starting it.

Verify before you publish

  1. Lint the structure.

    akm lint --type workflows
    

    This catches the body-rule violations above, plus every static reference check (unknown step, unknown param, bad path).

  2. Run it for real. A dry inspection of the markdown doesn't tell you whether a gate actually rejects bad output or an output schema actually matches what units return. Run the workflow against representative params:

    akm run workflows/my-release --version 1.2.3
    
  3. Inspect the evidence. Check that each step's promoted artifact is what you expect, and that a gate's rubric is judging that artifact, not engine prose:

    akm workflow status <run-id> --units
    

    --units shows per-unit diagnostics (status, failure_reason, raw result/error text) without polluting the deterministic artifact a gate judges — see Running Workflows: Check status.

  4. Deliberately break a gate once. Run the workflow with params you expect to fail validation, and confirm the gate actually rejects rather than silently passing — a missing judge (no connection or harness to run it) or a malformed verdict rejects the gate rather than bypassing it (see Workflow Schema: Gates and verification), so this is worth confirming once per workflow rather than assuming.

Running a child workflow (Experimental)

A step can run another workflow and use its result. The step names the child in its unit: bag and binds the child's params: with with::

---
type: workflow
params:
  topic: { type: string }
steps:
  - id: investigate
    unit:
      workflow: workflows/research
      with:
        topic: { from: params.topic }
  - id: report
    inputs: [steps.investigate.output]
---

## investigate

Runs the research workflow as a child run.

## report

Summarise the research finding.

A with: value is a literal (checked against the child's param type when the workflow is frozen) or { from: <reference> }, where the reference is params.<name> or steps.<id>.output(.<segment>)*, resolved just before the step runs. The child's last step output is the composing step's output, so report reads it through inputs:. Inspect what a step would pass, without running anything, with akm doctor explain workflows/<name> --format json; the per-step inputBindings show each literal and each unresolved reference.

Child workflows are Experimental. See Workflow Schema: Child workflows for blocked-child recovery and the limits.

Troubleshooting

A step that dispatches a model needs a harness or a connection. Freezing resolves where each unit runs: its unit.harness or unit.connection, else the document's defaults, else your default harness, else akm's own runtime over your default connection. With none of those, freezing fails and the error points at akm setup. A workflow made only of exec steps needs neither.

A workflow with a non-empty ### gate also needs one for the gate judge, which runs where model work runs: your default connection, else your default harness. An exec-only workflow with a gate still needs it.

akm setup normally configures both. On a bare container or CI image, run it with the answers as flags, or add one by hand:

akm setup --yes --endpoint http://localhost:11434/v1   # a model endpoint
akm setup --yes --harness claude                       # or an agent program you have

See also