docs · reference

Adapter manifest#

An adapter.toml file tells Hekma how to run any program as an agent: the command that starts it, what it can do on each OS, where its token counts come from, and how config keys reach it. This page is the field reference; Bring your own agent walks through writing one.

You register a manifest with hekma agent register NAME --manifest DIR, where DIR holds adapter.toml (or point at the file itself). Hekma parses and checks the whole file before writing anything. Unknown fields are rejected, so a typo fails registration instead of being ignored, and the error names the section at fault.

Complete example#

contract_version = "1.0.0"

[adapter]
kind = "worker"
name = "Worker"

[lifecycle.start]
exec = "/usr/local/bin/worker"
args = ["--serve"]
env = { LOG_LEVEL = "info" }

[capabilities.pause]
linux = "guaranteed"
macos = "guaranteed"
windows = "best-effort"

[capabilities.interaction]
linux = "guaranteed"
macos = "guaranteed"
windows = "guaranteed"

[metering]
source = "self-reported"

[interaction]
channel = "stdio"

[config.model]
env = "MODEL"

[config."memory.dir"]
env = "WORKER_MEMORY_DIR"
SectionRequiredPurpose
contract_versionyesThe adapter contract version the file is written for.
[adapter]yesThe adapter's kind and display name.
[lifecycle]yes, with startHow to launch the agent.
[capabilities]yesWhat the agent supports on each OS.
[metering]yesWhere token counts come from.
[interaction]noWhich input channel the agent uses.
[config]noHow config keys reach the agent.
[readiness] (Unreleased: after 0.11.0)noA probe that must pass before the agent counts as running.
[liveness] (Unreleased: after 0.11.0)noA signal that must keep proving the agent is alive.
[exit_codes] (Unreleased: after 0.11.0)noWhat the agent's own exit codes mean.
[drain] (Unreleased: after 0.11.0)noThe bounded wait behind hekma agent drain.

Hekma reports the first required section that is missing or invalid.

A service-mode example#

Unreleased: after 0.11.0. Contract 1.1.0 and the sections in this example are on Hekma's main branch and ship in the next release. Hekma 0.11.0 rejects [readiness], [liveness], [exit_codes] and [drain] as unknown sections.

A gateway is the typical long-running agent: it opens a local HTTP port and only then is ready, it proves it is alive by rewriting a heartbeat file, it asks to be relaunched by exiting with code 75, and it can stop taking work on request and say when it is idle. This manifest declares all of that. It is the same shape as the gateway test agent Hekma's conformance kit runs through every section:

contract_version = "1.1.0"

[adapter]
kind = "my-gateway"
name = "My Gateway"

# --dump lets the conformance kit read the environment the agent received.
[lifecycle.start]
exec = "my-gateway"
args = ["--port", "8080", "--dump", "config-dump.txt"]

# The agent stops and resumes taking work under its own program.
[lifecycle.pause]
exec = "my-gateway"
args = ["--pause"]

[lifecycle.resume]
exec = "my-gateway"
args = ["--resume"]

[capabilities.pause]
linux = "guaranteed"
macos = "guaranteed"
windows = "guaranteed"

[capabilities.interaction]
linux = "guaranteed"
macos = "guaranteed"
windows = "guaranteed"

[metering]
source = "self-reported"

# The start reaches `running` only once this answers 200.
[readiness]
kind = "http-get"
timeout_ms = 8000
url = "http://127.0.0.1:8080/models"
expected_status = 200

# While running, the agent rewrites this file; stale for 1.5 s fails it.
[liveness.heartbeat_file]
path = "gateway.heartbeat"
max_age_ms = 1500

# Exit code 75 asks for a relaunch without counting as a crash.
[exit_codes]
restart_requested = [75]

# hekma agent drain: pause, wait up to 10 s for the idle file, then stop.
[drain]
timeout_ms = 10000
idle_file = "gateway.idle"

[config.model]
env = "GATEWAY_MODEL"

[config."memory.dir"]
env = "GATEWAY_MEMORY_DIR"

The pause and resume here are the agent's own commands, which run the same way on every OS (pause and resume commands); a budget's pause still uses the signal. Each of the five service-mode declarations, [readiness], [liveness], [exit_codes], the pause and resume pair, and [drain], is optional. A manifest that leaves one out reads not_applicable in the conformance kit section that would have tested it.

contract_version#

The version of the adapter contract the manifest targets. Hekma 0.11.0 speaks 1.0.0, so write:

contract_version = "1.0.0"

Hekma's main branch speaks 1.1.0 (Unreleased: after 0.11.0), which adds the optional [readiness], [liveness], [exit_codes] and [drain] sections and the pause and resume command pair. A 1.0.0 manifest loads there unchanged. Write 1.1.0 when you use one of the new sections; Hekma 0.11.0 still loads a 1.1.0 manifest that uses none of them, since only the major is compared, but rejects the new sections as unknown.

The value must be a full X.Y.Z version: 1.0, 1 and v1.0.0 are rejected. A suffix such as 1.0.0-rc.1 is accepted. Hekma loads a manifest only when its major version matches its own; the minor and patch parts are not compared. A mismatch fails registration with exit code 1 and names both versions:

✗ The adapter manifest at '/Users/you/agents/worker/adapter.toml' cannot load: incompatible adapter contract: manifest declares 2.1.0, engine speaks 1.0.0 — compatible iff the major versions match (contract v1 policy, docs/adapter-contract.md#versioning). Ask the adapter author to retarget the manifest's contract_version to this engine's contract major — see docs/adapter-contract.md.

Versions 0.x are rejected too. See Versioning for the full rule.

[adapter]#

FieldTypeRequiredMeaning
kindstringyesThe adapter's identifier, shown in the Kind column. Lowercase letters, digits, - and _, starting with a letter or digit.
namestringnoA display name.

[lifecycle]#

[lifecycle.start] is required. It is the command Hekma runs to start the agent.

FieldTypeRequiredMeaning
execstringyesThe program: a name found on PATH when the agent starts, or an absolute path.
argslist of stringsnoIts arguments. Default none.
envtable of stringsnoExtra environment variables. Default none.

The agent runs with its Agent Home as its working directory and inherits the environment of the hekma command that started it, plus env and any mapped config. A config mapping that sets the same variable as env wins, and Hekma prints a note saying so at start.

Hekma copies the start command when you register. Editing adapter.toml later does not change an agent that is already registered; remove it and register it again.

You may also write [lifecycle.stop], [lifecycle.pause] and [lifecycle.resume] with the same three fields. Hekma 0.11.0 checks them but never runs them. Stopping is always done by signal: SIGTERM to the agent's process group on Unix, then SIGKILL after the stop timeout; on Windows Hekma waits out the timeout and then ends the process's job. Pausing uses SIGSTOP and SIGCONT where the capabilities say guaranteed. On Hekma's main branch a declared pause and resume pair is run instead (Unreleased: after 0.11.0; below); [lifecycle.stop] is still checked and never run.

An agent should therefore exit cleanly on SIGTERM. An agent that exits on its own while running, even with code 0, counts as a crash and is handled by the restart policy, unless an [exit_codes] section (Unreleased: after 0.11.0) gives that code a meaning. An agent that exits within the first 300 milliseconds fails the start instead.

Pause and resume commands#

Unreleased: after 0.11.0. Running the pause and resume pair is on Hekma's main branch and ships in the next release (contract 1.1.0). Hekma 0.11.0 checks the two tables and never runs them.

Some agents can stop taking new work and pick it up again on request, which is gentler than freezing the process. Declare how:

[lifecycle.pause]
exec = "my-gateway"
args = ["--pause"]

[lifecycle.resume]
exec = "my-gateway"
args = ["--resume"]
  • Both or neither. A manifest with only one of the two is refused at registration, naming both: a pause the adapter cannot undo would leave the agent paused for good.
  • The command replaces the signal. hekma agent pause runs the pause command in the Agent Home instead of sending SIGSTOP, the same way on every OS, even where [capabilities.pause] says unsupported. The state change records the cause pause-cooperative (or resume-cooperative) with the command it ran, never its environment.
  • The command must succeed within 30 seconds. A command that exits with a nonzero code, cannot start, or runs past 30 seconds is stopped and the verb fails with exit code 1, leaving the agent's state unchanged. The command's last stderr lines are part of the error.
  • Resume undoes the pause that happened. Only a pause that ran the command runs the resume command. An agent frozen by signal, for example by a budget, is resumed by signal.
  • A budget still freezes. The pause breach action keeps using the signal, because a budget needs a process that has really stopped. Stopping an agent paused by its own command sends no resume signal first, since there is nothing to unfreeze.
  • It stays paused between commands. When the program holding a cooperatively paused agent exits, the agent stays paused: it is not frozen, it is honouring its own pause. A later resume runs the resume command.
  • hekma agent drain runs the pause command as its first step; see [drain].

[capabilities]#

The capability declaration: one table per capability, rating it per OS.

[capabilities.pause]
linux = "guaranteed"
macos = "guaranteed"
windows = "best-effort"
CapabilityWhat it governs
pausehekma agent pause and resume, and the pause breach action.
interactionWhether the agent gets a stdin pipe and accepts hekma agent send.

Each table takes the keys linux, macos and windows, each set to one of:

LevelMeaning
guaranteedHekma relies on it. A pause really suspends the process.
best-effortHekma does it, and labels the result as cooperative. On Windows, pause is never stronger than this.
unsupportedThe command fails at once with exit code 5, quoting the declaration.

An OS left out of a table counts as unsupported. The manifest must declare at least one capability that is not unsupported on some OS, or registration fails.

Declare interaction supported only if the agent reads stdin. An agent with interaction support gets a stdin pipe when started without --detach; one without it gets a closed stdin, so it never blocks reading input that will not arrive.

[metering]#

Where the agent's token counts come from, its metering source.

[metering]
source = "self-reported"
sourceHow usage is counted
self-reportedThe agent prints a usage line on stdout for each model call (below).
engine-observedHekma runs a proxy on 127.0.0.1 and reads token counts from the model provider's responses. Map metering.base_url in [config] so the agent sends its requests to the proxy, and set metering.upstream_base_url on the agent. Such an agent cannot be started with --detach.

A self-reporting agent prints one line per usage event to stdout, starting with KTESIO_USAGE and a space, then a JSON object with sequence, input_tokens, output_tokens and optionally cached_tokens:

KTESIO_USAGE {"sequence": 0, "input_tokens": 1200, "output_tokens": 300, "cached_tokens": 400}

Hekma adds the agent name, run, source and time itself, and counts each sequence once per run. A line that breaks the format is skipped without stopping the agent. Self-reported usage is the full reference for the fields and rules; Meter token usage covers both sources step by step.

[interaction]#

Optional. Names the channel the agent takes input on.

FieldTypeMeaning
channel"stdio" or "http"stdio: the agent reads stdin. http: the agent takes input over its own HTTP API.

The field is descriptive in 0.11.0: Hekma behaves the same for both values. Whether the agent gets a stdin pipe depends on the interaction capability, and hekma agent send always writes to stdin. An HTTP-only agent can declare http so the manifest describes it accurately, but send will not reach it. Any other value is rejected.

[config]: config key mapping#

Optional. Maps config keys to the agent's own settings, so the same key works for every agent. Each [config.KEY] table names exactly one target:

# As an environment variable.
[config.model]
env = "MODEL"

# As a command-line flag: appended as two arguments, --model <value>.
[config.model]
flag = "--model"

# As a value in a TOML file in the Agent Home, at a dotted key.
[config.model]
file = { path = "config/agent.toml", key = "llm.model" }

(Pick one; a key can have only one target.)

TargetRules
env = "NAME"The variable is set in the agent's environment.
flag = "--name"The flag and the value are appended to [lifecycle.start] args.
file = { path, key }Hekma writes a TOML file at path, relative to the Agent Home, with the value at the dotted key. path may not be absolute or contain ... Several keys mapped to the same file are written to one document.

Keys a mapping can name:

  • Any key on Config keys, such as model. A key nobody sets is simply not delivered.
  • The reserved key memory.dir: the path of the agent's memory/ folder when a filesystem memory backing is attached. Quote it: [config."memory.dir"]. Without this mapping the folder is still kept, but the agent is not told where it is, and Hekma says so on stderr at start.
  • The reserved key metering.base_url: the proxy address for engine-observed metering, usually mapped to the variable the agent reads its API base URL from, such as OPENAI_BASE_URL.
  • The reserved keys run.key and run.refresh_key (Unreleased: after 0.11.0): a supervised launch's Run Key and refresh credential, env targets only. See Reserved credential keys.

You do not map agent.* keys: Hekma always passes agent.NAME as the environment variable NAME.

Things to know when you write mappings:

  • Secrets. A secret:NAME value is delivered in clear text to the target. Prefer env or file for secrets. A flag puts the secret on the command line, where other local users can read it; Hekma warns when that happens.
  • JSON-configured agents. The file target writes TOML only. For an agent that reads JSON config, map a key to the environment variable it reads whole config from (for example OpenCode's OPENCODE_CONFIG_CONTENT).
  • Placeholders. If the agent fills {env:VAR} placeholders in its own config and treats a missing variable as empty, make sure every such variable is mapped and set, or the agent will run with an empty value without warning.
  • Self-updating agents. Map the agent's setting that turns off self-update, so the version you tested is the one that runs.
  • Isolation. If several agents of the same program share a machine, map the settings that move the program's data and config folders into each Agent Home (for example XDG_DATA_HOME and XDG_CONFIG_HOME for XDG-based programs). The adapter contract lists these duties.

Reserved credential keys#

Unreleased: after 0.11.0. The reserved credential keys are on Hekma's main branch and ship in the next release; Hekma 0.11.0 does not have them.

Two reserved keys carry a supervised launch's credentials (see Run Keys): run.key (the launch's Run Key) and run.refresh_key (a refresh credential). The engine delivers them; an operator never sets them.

# Also deliver the Run Key in the agent's own variable (it always gets HEKMA_RUN_KEY).
[config."run.key"]
env = "MY_AGENT_HEKMA_KEY"

# Ask for a refresh credential too (none is issued unless this is mapped).
[config."run.refresh_key"]
env = "MY_AGENT_HEKMA_REFRESH"
  • Every agent receives its Run Key in HEKMA_RUN_KEY, whatever the manifest maps.
  • Only an env target is accepted for either key. A flag or file target is refused at registration, naming the key: an argv is readable by other local users, and a file would put the credential in the Agent Home.
  • A refresh credential is issued to a supervised launch only when run.refresh_key is mapped to an env target.
  • No Adapter Contract change: these are ordinary [config] mappings of two reserved keys.

[readiness]#

Unreleased: after 0.11.0. The [readiness] section is on Hekma's main branch and ships in the next release (contract 1.1.0). Hekma 0.11.0 rejects it as an unknown section.

Optional. One probe that must pass before the agent counts as running. Without it, an agent is running once it has survived its first 300 milliseconds. With it, hekma agent start waits in starting until the probe passes:

[readiness]
kind = "http-get"
timeout_ms = 5000
url = "http://127.0.0.1:8080/health"
expected_status = 200
FieldKindMeaning
kindallhttp-get, file-fresh or log-contains. One probe per manifest.
timeout_msallHow long the probe may take in all, 1 to 600000 milliseconds. Hekma polls about every 100 milliseconds within it.
url, expected_statushttp-getAn http:// URL on a literal loopback address (127.0.0.0/8 or [::1], optional port, query allowed, no #fragment), and the one status, 100 to 599, that means ready. Host names are rejected, localhost included, so the probe never looks anything up. A refused connection or another status is not ready yet, and the probe keeps polling.
path, max_age_msfile-freshA regular file the agent writes to show it is ready, relative to the Agent Home, and how recently it must have been modified, from 1 to timeout_ms milliseconds. On file systems with coarse timestamps (1 to 2 seconds on some Windows volumes), keep max_age_ms well above that.
linelog-containsText that must appear in this run's captured stdout. It is a plain substring, not a pattern; for an ACP agent it must match the protocol text as captured. With log capture = "off" there is no log, so this probe always times out.

Fields that belong to another kind are rejected, as are control characters in url, path and line.

The probe is the last step of the start, after the 300 millisecond survival window and, for ACP agents, the session handshake. Hekma notes on stderr when the wait begins and when it passes, with the time it took. A detached start waits too, and returns once the agent is ready or failed.

If the probe does not pass within timeout_ms, the agent lands failed with the cause readiness-timeout, naming the probe and the time waited (hekma agent show prints it). That failure is final: the restart policy is not consulted, because an agent that never becomes ready would fail the same way again. An agent that exits while the probe waits is a crash and is handled by the restart policy as usual.

The wait holds up the supervision of the other agents in the same engine for up to timeout_ms, so keep probe timeouts short when one host runs many agents.

[liveness]#

Unreleased: after 0.11.0. The [liveness] section is on Hekma's main branch and ships in the next release (contract 1.1.0). Hekma 0.11.0 rejects it as an unknown section.

Optional. One check that must keep passing while the agent is running. Without it, Hekma watches only that the process exists. With it, an agent whose check fails without a break for max_age_ms lands failed with the cause unresponsive, naming the check and how long it failed, and the restart policy handles it like a crash: restarts with backoff, and the crash-loop limit after five in a row.

[liveness.heartbeat_file]
path = "heartbeat.marker"
max_age_ms = 5000

or

[liveness.http_get]
url = "http://127.0.0.1:8080/health"
expected_status = 200
max_age_ms = 5000
FieldKindMeaning
pathheartbeat_fileA file the agent rewrites to show it is alive, relative to the Agent Home. A missing file counts as failing.
url, expected_statushttp_getThe same loopback-only http:// URL rules as [readiness], and the one status that means alive. Any other status, or no answer, is a failing check.
max_age_msbothHow long the check may fail before the agent is failed, 250 to 600000 milliseconds.

Declare exactly one of the two tables. A failure shorter than max_age_ms is a blip: Hekma notes on stderr once when it starts and once when it recovers, and after three such pairs it notes that the signal is flapping and stops repeating itself. Hekma checks about every 250 milliseconds, so the failure lands within max_age_ms plus up to two checks. Choose a window comfortably longer than the agent's real heartbeat interval.

  • A paused agent is never checked. A suspended process cannot write a heartbeat, so a pause can never fail it.
  • The window starts again after a restart, after an engine adopts the agent, and after a resume, so the agent may get up to one extra window of grace each time.
  • A detached agent is checked only while an engine holds it: a hekma command, a Service Host or a program embedding the engine. Nothing checks it in between.

[exit_codes]#

Unreleased: after 0.11.0. The [exit_codes] section and the stable-run reset are on Hekma's main branch and ship in the next release (contract 1.1.0). Hekma 0.11.0 rejects the section as an unknown section, and counts every exit of its own as a crash.

Optional. Gives the agent's own exit codes a meaning, so Hekma acts on why it exited rather than only that it did:

[exit_codes]
restart_requested = [75]
clean = [0]
FieldMeaning
restart_requestedCodes the agent exits with to ask for a relaunch (75 by convention). The agent lands failed with the cause restart-requested and is relaunched on the restart policy's backoff, but the exit does not count toward the five-crash limit.
cleanCodes the agent exits with when it has finished on purpose. The agent lands stopped with the cause clean-exit, as if you had stopped it, and is not restarted.

Codes must be between 0 and 255; Windows codes above 255 never match. A code in both lists, or twice in one list, is refused at registration.

  • Only exits from running are classified. An exit while still starting (in the survival window, a readiness probe or the ACP handshake) fails the start as before, and a process killed by a signal has no code.
  • never wins. With the restart policy never, a restart_requested exit lands failed and is not relaunched.
  • Relaunch requests never reach the crash limit, but the delay between them still grows with each one in a row, up to 60 seconds. The count of requests in a row is shown in the cause (requested-recycle N) and starts over when Hekma restarts.
  • An adopted agent on Linux and macOS is not Hekma's child, so its exit code cannot be read and its exit is a crash. On Windows the code can be read and is classified.

On the same branch, Hekma also forgives an agent that ran well: an agent that crashes after at least 30 seconds of uninterrupted running has its crash count reset first, so that crash counts as the first, and the cause says so. Time spent paused does not count toward the 30 seconds, and for an adopted agent the time counts from the adoption. This applies with or without an [exit_codes] section.

[drain]#

Unreleased: after 0.11.0. The [drain] section and hekma agent drain are on Hekma's main branch and ship in the next release (contract 1.1.0). Hekma 0.11.0 rejects the section as an unknown section.

Optional. Declares how long hekma agent drain waits for the agent to finish its work before stopping it:

[drain]
timeout_ms = 30000
idle_file = "idle.marker"
FieldTypeRequiredMeaning
timeout_msintegeryesThe longest the drain waits, 1 to 600000 milliseconds, covering the pause command and the idle wait together.
idle_filestringnoA file the agent touches when its work in progress reaches zero, relative to the Agent Home. It counts as idle when it was modified within the last 2 seconds; a missing file is not idle. Leave it out when the pause command's exit is the only wait.

A drain has three steps:

  1. Stop new work. Hekma runs the pause command. If the command fails or cannot start, the drain is refused with exit code 1 and nothing changes.
  2. Wait. Hekma polls idle_file until it is fresh or time runs out, and stops waiting early if the agent exits on its own.
  3. Stop. Hekma stops the agent through the usual stop sequence. This step always runs.

The wait is bounded by --timeout-ms on the command if given, else timeout_ms here, else 30 seconds. A drain that runs out of time still stops the agent, and records completed: false on its final drain-stopped state change, with the time it waited; a drain that finished its wait records completed: true. Either way the command exits with code 0, and a drain that ran out of time says so on stderr. A pause command that runs past the bound is stopped, and the drain carries on to the stop.

With neither a pause command nor an idle_file, there is nothing to wait for: the drain stops the agent at once, records a zero wait and notes it. Without the pause command but with an idle_file, the drain waits for the file and then stops.

Only a running agent can be drained: any other state is refused with exit code 4, and a --timeout-ms outside 1 to 600000 is a usage error (exit code 2). Like a readiness probe, the wait holds up the supervision of other agents in the same engine, so keep timeout_ms short when one host runs many agents. The idle check compares the file's time with the system clock, so a large clock change can briefly misread it.