docs · control plane
Policies and the warn default#
Unreleased: after 0.11.0. Policies and the
warndefault are on Hekma's main branch and ship in the next release; Hekma 0.11.0 has neither. Scent-Check Modes other thanoffarrive with key custody, which is still planned. See Status and roadmap.
A developer running a dozen coding and personal agents wants one ceiling for all of them, and a looping session to be loud, not frozen mid-task. A team running CrewAI or LangGraph flows in production wants one rule for "every nightly research flow", including tomorrow's runs, that never stops production unless someone chose that.
A Policy is that rule: standing limits that apply to every Run its Selector matches, now and later. A Run is one unit of agent work, whether or not Hekma started it. The default Breach Action, what happens when a ceiling is reached, is warn.
What works in 0.11.0#
In Hekma 0.11.0, limits are per-agent config keys: budget.tokens.*, budget.dollars.*, cost.rate.*, and one budget.breach_action for all of an agent's caps. The Breach Action defaults to pause, and warn only writes a line to logs/breaches.log. A cap fires once per run, and raising it does not re-arm it. There are no Policies, no labels and no way to change the limits of a live Run.
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.
A Policy#
A Policy holds any mix of Token Budgets (per run and cumulative), Cost Caps (per run and cumulative, estimated from Rates), a flat Rate and a Breach Action. It names its Runs with a Selector, a label expression such as team=research,env=prod, and every term must match.
Selectors match only bound labels: labels the Operator set through an agent's labels configuration or with hekma label. Labels a Run sets about itself never pick its Policy, so an agent cannot choose a looser one.
hekma policy create nightly-research \
--selector team=research,env=prod \
--tokens-per-run 2000000 \
--dollars-per-run 25 \
--breach-action pauseCreating one says how many open Runs it matched, and list shows it beside the default Policy:
$ hekma policy create core-cap --selector team=core --tokens-per-run 4000 --breach-action pause
created Policy `core-cap`: 1 open Run(s) matched, 0 fall back to `warn` at their Control Depth
$ hekma policy list
core-cap team=core tokens/run 4000, on breach pause
default (every Run) on breach warnhekma policy list, show, create, change and delete manage them; each takes --json, and every write takes --dry-run, which reports what it would match and how many matched Runs fall back to warn at their depth, and writes nothing. The same operations are on the Control API as /v0/policies, and the command reference lists every flag. Every change is a policy event.
A named Policy also arms a child Run's own level when the child's bound labels match it. Every Run resolves at creation, at every depth change and at every label change, so nothing waits for the first usage event.
One limit at a time#
Hekma resolves each limit on its own, in this order:
| Source | Rule |
|---|---|
A malformed breach_action anywhere | Fails closed to pause with a diagnostic, before every other source, a Run's own action included. Only the action fails closed: the ceilings, the Rate and the model an agent set explicitly still apply. |
| Explicit limits on a Run, then on an agent | A limit set on the Run itself with hekma budget set comes first, then the agent's configuration (any layer). Both outrank every Policy. |
| Matching Policies | The most specific Selector wins; a tie goes to the tightest value. |
| The default Policy | Fills whatever is still unset. |
Selector A is more specific than B when A's terms are a strict superset of B's; Selectors that cannot be compared tie. From loosest to tightest, Breach Actions run warn < pause < stop < block. A tie between two ceilings goes to the lower one.
hekma budget show <run-id> and hekma run show <run-id> --json name where each of a Run's limits came from: the Run itself, the agent's configuration, a Policy by name, or the default Policy.
A limit set by a Caller — an agent or helper acting on its own Run through its Run Key, which is on main with Run Keys — is kept apart from all of these: it applies only while it is tighter than the limit the Operator, the Host or a Policy sets, and a Caller can tighten, never loosen (403 raise-forbidden).
Which one to use. A limit set with hekma budget set belongs to one Run: it ends with the Run, and the agent's next start opens a new Run without it. It is the tool for "give this Run more room" or "rein this one in now". Limits every future Run of an agent should carry go in its budget.* configuration; standing rules for a whole class of Runs, now and later, are Policies.
The default Policy#
default is a stored Policy you change like any other, with hekma policy change default. It starts with no ceiling, Breach Action warn and Scent-Check Mode off. It cannot be deleted or given a Selector.
It also carries a Rate table keyed by model, used for Runs with no Rate of their own. The table starts empty: Hekma never invents prices. Add an entry for the exact model name an agent's model key sets:
hekma policy change default --rate-for gpt-4.1 --rate-input 2.00 --rate-output 8.00
hekma policy change default --clear rate:gpt-4.1A Rate comes from the agent's own cost.rate.* keys first, then a matching Policy's flat Rate, then this table. A flat Rate belongs to a named Policy: setting one on default is refused, because only the table prices default's Runs. A Cost Cap set by a Policy on a Run whose model has no Rate cannot be enforced; the Run carries the unpriced-model Anomaly until a Rate resolves, so the gap is never silent.
The warn default#
With no Breach Action configured, a breach is recorded, raises the Run's breach Anomaly, and is published as an event (and as an OTLP metric when export is configured). warn acts on nothing and signals loudly. pause, stop and block stay opt-in. Nothing Hekma does on its own stops a Run unless an Operator configured it, and a Run is never treated differently for running long.
Upgrades keep your pause. An agent registered before this change that relied on the implicit pause default keeps pause. The first open of the upgraded state directory writes budget.breach_action = "pause" into the agent's configuration, records one breach_default_upgraded event, and shows a "kept on pause by upgrade" note until you set a Breach Action yourself. An agent whose configuration cannot be written still pauses. A malformed breach_action fails closed to pause with a diagnostic, never to warn.
If you run an agent in CI and want a spend cap to end the job, set budget.breach_action stop explicitly, as Agents in GitHub Actions does.
Changes apply at once#
A Policy change applies to every matched open Run immediately, by the same rule that hekma budget set and an agent's budget.* configuration write follow. Lowering a ceiling to or below a Run's usage breaches it now. Raising one above the usage re-arms its breach latch, so the next crossing fires again, and lifts the block fence for that ceiling on a live Run. Clearing a ceiling or deleting the Policy re-arms too, since a latch never outlives the ceiling that fired it. Cumulative ceilings compare against the agent's lifetime totals.
Changing a Policy's Selector re-resolves the Runs both the old and the new Selector match, so the Runs only the old one governed loosen as well. Deleting a Policy re-resolves the Runs it governed under what remains.
An unknown --clear field is refused (exit 2 on the CLI, 400 on the API): a typo would otherwise report success while clearing nothing.
Control Depth and fallback#
Each Run has a Control Depth, how far Hekma controls it. Where a Policy's Breach Action is beyond a Run's depth, such as block on an agent with no metering listener, or pause on a child Run inside an agent's process, the Run acts as warn for that ceiling and carries the depth-fallback Anomaly. The action takes effect if the Run's depth later allows it. Creating or changing a Policy reports how many matched Runs fall back.
block, the wire fence#
block is never a default. On a breach, the agent's metering listener refuses further model calls with HTTP 402 and a typed, non-retryable error. The fence lifts when the Run ends, or when the ceiling is raised above the Run's usage, whether by a Policy change, hekma budget set or an agent configuration write. It lifts reason by reason. An agent that bypasses the listener bypasses the fence too. Run Hekma as a service has the full rules.
What is coming#
- Scent-Check Modes (planned, with key custody). Every Policy carries a Scent-Check Mode, how Hekma treats a call without a valid Run Key:
off,shadow(served and recorded as unscented) orenforce(refused). Onlyoffis accepted on main;shadowandenforceare refused rather than stored and ignored. - Policy as data. Policies have no versions yet. Versioned, audited Policies with shadow mode and canary rollout come later.
Open questions#
- Scent-Check defaults per environment. The default Policy starts at
off. Whether a laptop and a server should start differently is still open; deciding it will not overwrite a default Policy you have edited. - Pinning a Policy for long Runs. For now a Run follows the latest Policy. Whether it should keep the one in force when it started will be decided with versioned policy-as-data.
Read next#
- Runs: Control Depth, Run Status, labels and
hekma budget. - Run Keys: each Run's own credential, and the key custody still to come.
- Budgets and cost: per-agent budgets and Rates.