docs · control plane

Runs, Control Depth, ps and top#

Partly on main (Unreleased: after 0.11.0). Runs for supervised agents, run ids, Run Status and Anomalies, child Runs, labels from configuration, hekma run, hekma label, hekma ps, Selectors on the lifecycle verbs and hekma budget are on Hekma's main branch and ship in the next release; Hekma 0.11.0 has none of them. hekma top and Runs Hekma did not start are still in development or planned, and their names, commands and defaults may change before they ship. See Status and roadmap.

With a dozen agents on a laptop, you want one list of those that need you. With CrewAI or LangGraph flows in production, you want the flows that broke a limit, and one command for all of them. Hekma is making the Run the one thing every listing and verb acts on.

What works in 0.11.0#

In 0.11.0 a run is one life of a registered agent's process. hekma agent list shows the fleet, hekma agent usage NAME shows this run's tokens, and per-run budgets reset at each new run, including a restart after a crash. There are no run ids you can act on, no labels and no Selectors.

What works on main#

Unreleased: after 0.11.0. Everything in this section is on Hekma's main branch and ships in the next release. The output shown comes from real runs of a binary built from Hekma main, with stand-in agents that call no model.

Every supervised start is a Run#

hekma agent start creates a Run with a run id such as run_01M76G4PAEY4VYBV7WPD99QCX9: run_ and a ULID, so ids sort by creation time. Ids recorded by older versions (run-…) stay valid. The Run's Control Depth is supervised, or supervised (no wire) for an agent whose model calls do not pass through Hekma's metering listener (a self-reported adapter). hekma run show prints any Run:

$ hekma run show run_01M76G4PAEY4VYBV7WPD99QCX9
✓ Run run_01M76G4PAEY4VYBV7WPD99QCX9
  CONTROL      supervised (no wire)
  STATUS       active
  ANOMALIES    —
  PARENT       —
  INSTANCE     my-agent
  LABELS       team=core (bound, label-verb)
  LIMITS       —
  USAGE        4500 tokens (3600 in / 900 out), $0.00 (estimated)
  CHILDREN     1 open

--json prints the same Run as a document, {"schema_version": 1, "run": {…}}: under run are run_id, control_depth, status, anomalies, labels, limits, usage and, once it has ended, end_cause and ended_at. An id that matches no Run exits with code 3.

A crash relaunch keeps the Run. When the restart policy relaunches a crashed agent, the run id stays the same, so per-run token budgets and dollar caps keep counting from before the crash, a breach already recorded for the Run does not fire again, and a per-run block fence stays up. A pause or stop the Run had already fired on a breach is applied again to the relaunched agent, so an agent that crashes while paused by a breach comes back paused. Only start, by you or a Host, opens a new Run. In 0.11.0 a relaunch starts a fresh run with a fresh per-run budget; if you relied on that, raise the ceiling, or stop and start the agent.

Run Status follows the agent. A Run is active while its agent is starting, running or stopping, held while it is paused, and ended once it stops. A crash marks it with the failed Anomaly; the Anomaly clears when the relaunch is running again, and if the restart policy gives up (or the relaunch never runs because the command that planned it exited) the Run ends with it. A token budget or dollar cap breach marks the Run with the breach Anomaly, whatever the breach action, and the Anomaly stays on the ended Run.

Labels from configuration#

Set labels.<key> on an agent, and its Runs carry the label as a bound label:

$ hekma agent config set my-agent labels.team payments
✓ Set labels.team = payments on Agent Instance my-agent (instance layer)

Keys start with a lowercase letter and use a-z, 0-9, _, . and -, at most 63 characters. Values are 1 to 128 letters, digits or _ . : / @ + -, and never a secret: reference:

$ hekma agent config set my-agent labels.env secret:FOO
✗ invalid value 'secret:FOO' for config key 'labels.env': a label value cannot be a `secret:` reference. Nothing was changed. Fix the value and try again.

Labels merge per key across config layers, like any key, and are never passed to the agent. A label set with hekma agent config set while the agent runs updates its Run at once; a label in another layer applies at the next start. Use the labels key for labels every future Run of an agent should carry.

Bound labels on a Run: hekma label#

hekma label set binds labels to one Run (by run id), to an agent's open Run (by name), or to every open Run a Selector matches. hekma label remove takes them back:

hekma label set my-agent team=core
hekma label set run_01M76G4PAEY4VYBV7WPD99QCX9 env=prod tier=gold --json
hekma label set --selector team=core,env=prod tier=gold --dry-run
hekma label remove --selector team=core tier --yes
$ hekma label set my-agent team=core
✓ Run run_01M76G4PAEY4VYBV7WPD99QCX9 labeled: team=core (bound, label-verb)
$ hekma label remove my-agent team
✓ Run run_01M76G4PAEY4VYBV7WPD99QCX9 labeled: team=payments (bound, config)

A label set this way records its origin, label-verb. Per key it outranks the agent's labels configuration (origin config) and any label the Run set about itself, so a later labels.* write, a crash relaunch or a restart of Hekma never overwrites it. Labels belong to the Run: a relaunch keeps them, and a new start opens a new Run without them.

  • Removing a label set with the verb restores the configured value, if the configuration binds the same key, in the same change (as above). Removing an absent key changes nothing.
  • A label from configuration is changed with hekma agent config set, or overridden on the Run with hekma label set; hekma label remove refuses it and names the key to change. A label the Run set about itself (a caller label) cannot be removed here either.
  • An ended Run is refused: its labels cannot change.
  • A Caller cannot set a bound key. A caller label on a key that is already bound on the Run is refused (label-bound).

Each change is one labels-changed Run event naming the bound labels before and after.

--selector key=value[,key=value…] matches every open Run carrying all those labels, bound or caller. When it matches more than one Run, the set is listed and you are asked to confirm; --yes skips the question. Without a terminal the command is refused unless --yes is given, so a script never hangs:

$ hekma label set --selector tier=gold env=prod < /dev/null
The Selector matches 2 Runs:
  RUN ID                          CONTROL               STATUS   AGENT
  run_01M7TNTVS9EPDAR7JFDT32GC1E  supervised (no wire)  active   my-agent
  run_01M7TNV98VJ0FN39P7C2AK06R0  supervised (no wire)  active   worker
✗ the Selector matches 2 Runs and there is no terminal to confirm on — pass --yes to label them all, or --dry-run to see each Run's outcome first

--dry-run prints each Run's planned change and writes nothing. Each Run reports its own result (labeled, unchanged, would label, or why it was refused), and a refusal on one Run does not stop the others. The exit code is the first failure's: 3 no such Run, 4 refused by the Run's state or labels, 2 an invalid request. A Selector that matches no Run is a success with a note; one that matches more than 1000 Runs is refused. --json prints the one results document every set-taking verb shares, {schema_version, verb, dry_run, matched, results} with verb label, and each Run's labels and prior_labels. The same change is on the Control API as PATCH /v0/runs/{id}/labels, and over a selected set as one PATCH /v0/runs/labels. A --dry-run prints each refusal on stdout as Run <id> would refuse (<code>): <reason>, as every set-taking verb does. The CLI reference lists every flag.

Child Runs: hekma run#

A Host can open a child Run under an agent's Run for one unit of its own work, with its own ceilings:

$ hekma run open --parent my-agent --label task=review --token-budget 20000
✓ Run run_01M76G4PBT0DSPWP472Z26FMZC opened
  CONTROL      announced
  STATUS       active
  ANOMALIES    —
  PARENT       run_01M76G4PAEY4VYBV7WPD99QCX9
  INSTANCE     my-agent
  LABELS       task=review (caller)
  LIMITS       20000 tokens per run (warn)
  USAGE        0 tokens (0 in / 0 out), $0.00 (estimated)
  CHILDREN     0 open
$ hekma run close run_01M76G4PBT0DSPWP472Z26FMZC
✓ Run run_01M76G4PBT0DSPWP472Z26FMZC closed
  CONTROL      announced
  STATUS       ended
  ANOMALIES    —
  PARENT       run_01M76G4PAEY4VYBV7WPD99QCX9
  INSTANCE     my-agent
  LABELS       task=review (caller)
  LIMITS       20000 tokens per run (warn)
  USAGE        0 tokens (0 in / 0 out), $0.00 (estimated)
  CHILDREN     0 open
  ENDED        closed
  • --parent takes a run id or an agent name, meaning that agent's open Run. A child of a supervised agent is depth announced and runs inside that agent's process; opened while the agent is paused, it starts held.
  • Its usage counts on itself and on every ancestor, and every ancestor's ceilings apply to it: a child's own ceiling breaching records a breach on the child, and its parent's breaching acts on the agent as configured.
  • Its own ceilings (--token-budget, --dollar-cap "3.00") take the warn breach action. --breach-action pause, stop or block on a child is refused (exit code 2) until Hekma can hold or reject one Run's calls.
  • Labels given at open (--label key=value, repeatable) are caller labels. --external-id makes a retried open return the same Run.
  • Pausing or stopping the agent holds or ends its child Runs too, recording parent-paused, parent-resumed, parent-stopped or parent-ended.
  • Runs nest at most 8 levels. A parent that does not exist (exit code 3) or has ended (exit code 4) is refused with an error naming the cause. close on a Run that has already ended changes nothing and succeeds.

All three commands take --json. The same operations are on the Control API at /v0/runs, and in the engine for embedders. Until model calls carry a Run's identity, usage reaches child Runs only from Hosts that embed the engine; the shared Metering Proxy will attribute calls to them.

The Runs that need you: hekma ps#

hekma ps is one exception-first listing over every Run in the state directory, newest first (the command reference):

hekma ps
hekma ps --selector team=core,env=prod
hekma ps --all --limit 100

With nothing to report it says so and exits 0. After one of two agents has crossed a Policy's ceiling and been paused, the same command lists that Run:

$ hekma ps
• note: no Runs need attention — no Anomalies and no held, silent or stale statuses
• note: 0 listed · 2 healthy open Runs not shown (--all lists them)
$ hekma ps
▸ Runs (1 row)
RUN         CONTROL               STATUS  ANOMALIES      LABELS               Usage (tok, est. $)  Headroom (tok, est. $)
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
my-agent    supervised (no wire)  held    breach[pause]  team=core,tier=gold  4500 tok             0 tok policy:core-cap 
• note: 1 listed · 1 healthy open Run not shown (--all lists them)

The table follows the terminal's width (this one was 150 columns); in a narrow one the cells are cut with …, and --json always carries every value whole.

A Run is listed when it carries an Anomaly (an ended Run only within seven days of its end) or a held, silent or stale status. Healthy open Runs are counted in the footer, not listed, and --all lists every Run inside that window. The window is a read-side bound of seven days (the retention default) until compaction lands: older ended Runs stay in the store and are reachable by id, they just age out of listings.

Rows are ordered by run id, newest first. ULID ids encode creation time, so that is creation order. The footer prints the exact command for the next page (the same view, Selector and --limit, plus the --cursor value), and paging neither duplicates nor skips: a Run that changes status between two pages neither moves nor repeats, a Run deleted between pages is skipped, and one that starts matching below the cursor is not chased. A page that is exactly full and last prints no next page. Legacy run-… ids sort below every run_… id and so land last.

Each row carries:

  • the CONTROL depth (supervised (no wire) for an agent whose model calls skip the metering listener), the Run Status, and the Anomalies with each latched Breach Action (breach[block]), so a fenced agent never reads as merely healthy;
  • the labels, with a caller label suffixed;
  • the Run's subtree usage, and its headroom against the resolved limits, naming the Policy that set them, with the cumulative token headroom on process-owning rows and no dollar figure where no Rate prices one.

The RUN column shows the agent's name on process-owning rows and the run id on child Runs. --json carries every figure whole: each row's labels with source and origin, its latches, its resolved limits with each limit's source, the effective Breach Action after the depth fallback, and the kept_on_pause marker where the breach-default upgrade holds an agent on pause.

--selector matches bound and caller labels alike in either view, and a listing pages past the 1000-Run cap the label verb keeps. --limit defaults to 50 and serves at most 1000 (0 means the maximum; above the cap it clamps with a note). hekma ps is a read-only read: it opens the state database read-only, never starts a host, creates nothing, and exits 0 with a note when nothing needs attention (the footer's counts still print). Exit 2 is an invalid selector, cursor or limit; 1 a store failure. hekma agent list keeps its own projection of supervised instances, unchanged, beside it. The same listing is on the Control API as GET /v0/runs.

Selectors on the lifecycle verbs#

hekma agent stop, pause, resume and drain, and hekma run close, take an agent, a run id, or --selector:

hekma agent pause run_01JZ6Q9G3S8V2X7K4M1N5P0R2T
hekma agent stop --selector team=core --dry-run
hekma agent stop --selector team=core --yes --json
hekma run close --selector task=review --yes

On the Run that owns an agent's supervised process, the verb is the agent's own: the same stop ladder, the same drain bound, the same notes. Pausing a run id pauses its agent, and the Run goes held. Any other Run answers from the verb table below: until Hekma can hold or reject one Run's calls, stop, pause, resume and drain on a child Run are refused, naming its depth, and a child held because its parent is paused is refused naming the parent.

A Run is never skipped silently. Every Run the Selector matched gets its own result (stopped, paused, would-stop, or refused with the reason), a refusal never stops the others, and the exit code is the first failure's class with the count in its message. The set is listed and confirmed as for hekma label: only when it holds more than one Run, only on a terminal. A pipe is refused unless --yes is given, and stdin is never read. --dry-run plans each Run from its status and depth, writes nothing and starts no Service Host. --json prints the shared results document. start and send take no Selector: a Selector matches open Runs, so there is nothing to start, and send carries text to one agent's input.

A Selector act runs on exactly the set you saw. The CLI asks the Service Host to select the Runs (POST /v0/runs/select), which answers with a set token, and acts with one call that carries it (Selector sets). A Run that ended between the selection and the act is that Run's run-ended refusal; the rest act. Slow verbs run their windows one after another, so a set's worst case is the sum of its windows. The CLI waits at most 10 seconds plus each Run's bound (capped at 10 minutes), then says it stopped waiting while the acts may still be committing. The command reference has the arguments, flags and exit codes.

Limits on a Run: hekma budget#

hekma budget show reads a Run's limits: each ceiling with where it comes from (run, instance, policy:<name>, default), its usage, the headroom, the Breach Action and any latched breach. hekma budget set writes limits on the Run itself:

hekma budget show my-agent
hekma budget set my-agent --tokens-per-run 500000
hekma budget set run_01JZ6Q9G3S8V2X7K4M1N5P0R2T --dollars-per-run 3.00 --breach-action pause
hekma budget set --selector team=core --clear tokens-per-run --yes

Here a Policy named core-cap caps the Run at 4000 tokens with pause, and the Run has crossed it. Raising the ceiling on the Run re-arms the breach:

$ hekma budget show my-agent
Run run_01M7TNTVS9EPDAR7JFDT32GC1E (agent my-agent, supervised (no wire), held)
  tokens per-run     4000 (policy:core-cap)  used 4500  headroom 0
  tokens cumulative  —  used 4500
  dollars per-run    —  used $0.00
  dollars cumulative —  used $0.00
  breach action      pause (policy:core-cap)
  latched            tokens per-run (pause)
  set on this Run    no Run-level limit
$ hekma budget set my-agent --tokens-per-run 500000
✓ Run run_01M7TNTVS9EPDAR7JFDT32GC1E raised: tokens per-run 500000; re-armed tokens per-run — set on this Run only: it ends with the Run, and a new start opens a new Run without it — for limits every future Run should carry, use the agent's budget.* configuration or a Policy

The agent stays paused until you resume it: re-arming a breach does not undo the pause it caused.

A limit set on a Run outranks the agent's budget.* configuration and every Policy for that limit. It belongs to the Run, like a label set with hekma label: a crash relaunch keeps it, it ends with the Run, and a new start opens a new Run without it, so every result says it is Run-scoped (run_scoped and a note in --json). For limits every future Run should carry, set the agent's budget.* configuration or a Policy.

  • Cumulative ceilings go on an agent's own Run only, because they count the agent's lifetime usage. A child Run takes per-run ceilings.
  • A ceiling raised above the usage re-arms its breach at once and lifts a matching block fence. One lowered to or below the usage breaches at once and applies the Breach Action, with no wait for the next model call.
  • --clear hands a limit back to the next layer, which may raise or lower it.
  • A limit a Caller sets is kept apart and applies only while it is tighter than the one the Operator, the Host or a Policy sets.
  • Each change is one limits-changed Run event naming the Run's limits before and after.

Over a Selector, set confirms like every set-taking verb; show with a Selector, or with no target, lists Runs as hekma ps --all does and pages with --limit and --cursor. The same operations are on the Control API as GET and PATCH /v0/runs/{id}/limits, and the command reference has every flag.

Every Run has a Run Key#

Each supervised launch gets its own Run Key in HEKMA_RUN_KEY, and a child Run opened over the Control API gets its own Run Key and refresh credential once. A Run Key acts as its Run's Caller: it may open child Runs beneath its Run, close them and tighten their limits, and nothing else. Keys are stored as hashes, revoked when their process exits, when their Run ends, or with hekma run revoke-keys; hekma run keys lists them by token id. A used refresh credential presented again raises the credential-reuse Anomaly.

What is coming#

A Run is one unit of agent work with a stable run id, a Control Depth, labels, budgets and a Run Status, whether or not Hekma started its process: a supervised agent, a child Run inside a Host or framework flow, or a client Hekma found.

PartStage
Runs for supervised agents, run ids, labels from configuration, parent and child Runs, hekma label with --selector, --dry-run and --yesOn main (Unreleased: after 0.11.0)
hekma ps, Selectors on listingsOn main (Unreleased: after 0.11.0)
Run Keys: a key per launch, child Run credentials, refresh, revocationOn main (Unreleased: after 0.11.0)
Selectors, --dry-run and --yes on stop, pause, resume, drain and run close; hekma budgetOn main (Unreleased: after 0.11.0)
Hold, release, reroute and reject on a setIn development
hekma topPlanned
Runs Hekma did not start (depths wire, announced, observed)Planned

Control Depth says how far Hekma controls a Run, on a ladder where each rung includes the one below: observed (known from telemetry or an announcement only) < wire (its model calls pass through the Metering Proxy) < announced (wire, plus the Run declared itself and keeps a Lease, its claim to be alive) < supervised (Hekma owns the process). A Run keeps its id when its depth changes. A supervised agent whose calls skip the proxy shows as supervised (no wire).

Which verbs work depends on the depth; “no” means the verb fails at once with an error naming the depth. A conformance fixture pins this table, cell by cell, as each one ships.

Verbobservedwireannouncedsupervised
List, usageestimated, from telemetryper callper callper call, plus process state
logsnoper callper callprocess output, per call
Budgets with warnfrom telemetryyesyesyes
pause / resumenoholds its callsholds its callspauses the process
stopnorejects its callsrejects its calls, ends the Leasestops the process
send, attachnononoas the adapter declares
hold, release, reroute, rejectnoyesyesyes

hekma run show --json also carries the Run's resolved Policy limits, each with its source (the Run, the agent's configuration, a Policy by name, or the default Policy), plus the depth-fallback and unpriced-model Anomalies a Policy can raise.

Run Status is active, held, silent (no recent heartbeat or traffic), stale (its machine is unreachable) or ended; main has active, held and ended. An Anomaly is a condition Hekma makes loud, such as a budget breach or a Run gone silent; main has failed and breach, a Policy can also raise depth-fallback and unpriced-model, and a reused refresh credential raises credential-reuse. It never acts on a Run, and no Run is stopped for running long: only a verb you run or a Policy you configure acts on one.

How it will work#

Labels are key=value pairs that record their source. Bound labels come from you or your Host: an agent's labels config key and hekma label (both on main, above), a Run Key, or a Metering Proxy endpoint. Caller labels come from the agent or framework itself (a Caller). A Caller cannot set a bound key, and only bound labels select Policies, so an agent cannot label its way into looser limits.

Parent Runs. Runs are flat unless one names a parent (on main). A verb on a parent will reach its children only through a Selector, except that stopping or pausing the Run that owns a supervised process also stops or pauses the child Runs inside it.

A Selector (key=value,…) names a set of Runs on any listing or verb, as it already does for hekma label, hekma ps, hekma budget and the lifecycle verbs. When it matches more than one Run on a verb, the verb shows the set and asks you to confirm (--yes skips this); --dry-run only shows it. Listing Selectors page past the 1000-Run cap the verbs keep.

hekma top will show each Run's status, depth, tokens per second, burn rate and budget left, live. Hotkeys will pause, stop, hold, raise a limit and attach, confirming as the matching command does. It can watch a remote hekma serve; the /v0/events stream's Selector filter and resume (see the Control API) are the seam it builds on.

Every filter, Selector and page parameter of hekma ps has a Control API equivalent, GET /v0/runs?selector=&view=&limit=&cursor=, so teams can work from scripts and their own observability stack. The goal is that listing stays fast from thousands to millions of Runs.

Open questions#

  • The Control API stays at version 0 until a second Host validates it; whether another milestone can make it stable is undecided, so expect the Run routes to change.