One step of the loop
step(state, event) is the kernel: the state after the event and the commands the host must carry out, through agent-budget, agent-policy and agent-context. A finished run refuses every event (an error). cancel: outcome cancelled, status finished, pending and awaiting cleared, commands [finish(cancelled)]; error(why): the same with failed(why). user-message(text): only while idle (else an error); appends the user message and advances. model-output: only while thinking (else an error); appends the assistant message with its text; with no tool calls the run completes: finish(completed(text)). With tool calls: agent-budget.charge with all of them; an error ends the run with failed("budget: {error}"); else the calls become pending in the model's order and each is decided by agent-policy: allow → command run-tool(call); ask → the id joins awaiting and command ask-approval(call); deny(reason) → the call leaves pending and a tool message "denied: {reason}" is appended. Then the run advances; the tool and approval commands come first, then whatever advancing commands. tool-result: the call must be pending and not awaiting approval (else an error); the tool message is its output, or "error: {output}" when ok is false; the call leaves pending; the run advances. approval: the id must be awaiting (else an error) and leaves awaiting; allowed → command run-tool(call) first, then advancing; refused → the tool message "denied: refused by the user" and the call leaves pending; the run advances. Advancing: while anything is pending or awaiting the status is acting, or waiting-approval when something awaits, with no commands; otherwise agent-budget.turn charges a model turn (an error ends the run with failed("budget: {error}")), the status becomes thinking and the one command is call-model(agent-context.fit(messages, context-tokens)). Every tool message carries its tool-call-id; user and assistant messages carry none.
Depends onagent-budgetagent-policyagent-context
Interface (WIT)136 lines›
package root:component;
world root {
import liberas:agent/types@0.1.0;
import agent-budget: liberas:agent/budget@0.1.0;
import agent-policy: liberas:agent/policy@0.1.0;
import agent-context: liberas:agent/context@0.1.0;
export liberas:agent/step@0.1.0;
}
package liberas:agent@0.1.0 {
interface types {
record budget {
tool-calls: u32,
turns: u32,
tool-bytes: u64,
}
record tool-call {
id: string,
name: string,
arguments: string,
}
variant decision {
allow,
deny(string),
ask,
}
record policy {
deny: list<string>,
ask: list<string>,
allow: list<string>,
fallback: decision,
}
enum role {
system,
user,
assistant,
tool,
}
record message {
role: role,
content: string,
tool-call-id: option<string>,
}
enum status {
idle,
thinking,
acting,
waiting-approval,
finished,
}
variant outcome {
completed(string),
cancelled,
failed(string),
}
record state {
messages: list<message>,
budget: budget,
policy: policy,
status: status,
pending: list<tool-call>,
awaiting: list<string>,
context-tokens: u32,
outcome: option<outcome>,
}
record model-output {
text: string,
tool-calls: list<tool-call>,
}
record tool-result {
tool-call-id: string,
output: string,
ok: bool,
}
record approval {
tool-call-id: string,
allowed: bool,
}
variant event {
user-message(string),
model-output(model-output),
tool-result(tool-result),
approval(approval),
cancel,
error(string),
}
variant command {
call-model(list<message>),
run-tool(tool-call),
ask-approval(tool-call),
finish(outcome),
}
record transition {
state: state,
commands: list<command>,
}
}
interface budget {
use types.{budget, tool-call};
charge: func(current: budget, calls: list<tool-call>) -> result<budget, string>;
turn: func(current: budget) -> result<budget, string>;
}
interface policy {
use types.{policy, tool-call, decision};
decide: func(current: policy, call: tool-call) -> decision;
}
interface context {
use types.{message};
fit: func(messages: list<message>, limit: u32) -> list<message>;
}
interface step {
use types.{state, event, transition};
step: func(current: state, event: event) -> result<transition, string>;
}
}
Test vectors20›
[
{
"args": {
"event": {
"tag": "user-message",
"val": "read a and write b"
},
"current": {
"budget": {
"turns": 3,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "idle",
"outcome": null,
"pending": [],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "model-output",
"val": {
"text": "ok",
"tool-calls": [
{
"id": "c1",
"name": "read-file",
"arguments": "{\"path\":\"a\"}"
},
{
"id": "c2",
"name": "write-file",
"arguments": "{\"path\":\"b\"}"
},
{
"id": "c3",
"name": "shell",
"arguments": "{\"cmd\":\"rm\"}"
}
]
}
},
"current": {
"budget": {
"turns": 2,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "thinking",
"outcome": null,
"pending": [],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
},
{
"role": "user",
"content": "go",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "model-output",
"val": {
"text": "all done",
"tool-calls": []
}
},
"current": {
"budget": {
"turns": 2,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "thinking",
"outcome": null,
"pending": [],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
},
{
"role": "user",
"content": "go",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "model-output",
"val": {
"text": "two",
"tool-calls": [
{
"id": "c1",
"name": "read-file",
"arguments": "{}"
},
{
"id": "c2",
"name": "read-file",
"arguments": "{}"
}
]
}
},
"current": {
"budget": {
"turns": 2,
"tool-bytes": 400,
"tool-calls": 1
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "thinking",
"outcome": null,
"pending": [],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "model-output",
"val": {
"text": "denied only",
"tool-calls": [
{
"id": "c1",
"name": "shell",
"arguments": "{}"
}
]
}
},
"current": {
"budget": {
"turns": 2,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "thinking",
"outcome": null,
"pending": [],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "model-output",
"val": {
"text": "denied only, no turns",
"tool-calls": [
{
"id": "c1",
"name": "shell",
"arguments": "{}"
}
]
}
},
"current": {
"budget": {
"turns": 0,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "thinking",
"outcome": null,
"pending": [],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "tool-result",
"val": {
"ok": true,
"output": "contents",
"tool-call-id": "c1"
}
},
"current": {
"budget": {
"turns": 2,
"tool-bytes": 390,
"tool-calls": 3
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "acting",
"outcome": null,
"pending": [
{
"id": "c1",
"name": "read-file",
"arguments": "{\"path\":\"a\"}"
}
],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "tool-result",
"val": {
"ok": false,
"output": "no such file",
"tool-call-id": "c1"
}
},
"current": {
"budget": {
"turns": 2,
"tool-bytes": 390,
"tool-calls": 3
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "acting",
"outcome": null,
"pending": [
{
"id": "c1",
"name": "read-file",
"arguments": "{\"path\":\"a\"}"
},
{
"id": "c2",
"name": "read-file",
"arguments": "{}"
}
],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "tool-result",
"val": {
"ok": true,
"output": "x",
"tool-call-id": "zzz"
}
},
"current": {
"budget": {
"turns": 3,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "acting",
"outcome": null,
"pending": [
{
"id": "c1",
"name": "read-file",
"arguments": "{}"
}
],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "approval",
"val": {
"allowed": true,
"tool-call-id": "c2"
}
},
"current": {
"budget": {
"turns": 3,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "waiting-approval",
"outcome": null,
"pending": [
{
"id": "c2",
"name": "write-file",
"arguments": "{}"
}
],
"awaiting": [
"c2"
],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "approval",
"val": {
"allowed": false,
"tool-call-id": "c2"
}
},
"current": {
"budget": {
"turns": 2,
"tool-bytes": 400,
"tool-calls": 3
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "waiting-approval",
"outcome": null,
"pending": [
{
"id": "c2",
"name": "write-file",
"arguments": "{}"
}
],
"awaiting": [
"c2"
],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "tool-result",
"val": {
"ok": true,
"output": "x",
"tool-call-id": "c2"
}
},
"current": {
"budget": {
"turns": 3,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "waiting-approval",
"outcome": null,
"pending": [
{
"id": "c2",
"name": "write-file",
"arguments": "{}"
}
],
"awaiting": [
"c2"
],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "approval",
"val": {
"allowed": true,
"tool-call-id": "c9"
}
},
"current": {
"budget": {
"turns": 3,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "waiting-approval",
"outcome": null,
"pending": [
{
"id": "c2",
"name": "write-file",
"arguments": "{}"
}
],
"awaiting": [
"c2"
],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "cancel"
},
"current": {
"budget": {
"turns": 3,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "acting",
"outcome": null,
"pending": [
{
"id": "c1",
"name": "read-file",
"arguments": "{}"
}
],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "error",
"val": "model unreachable"
},
"current": {
"budget": {
"turns": 3,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "thinking",
"outcome": null,
"pending": [],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "user-message",
"val": "again"
},
"current": {
"budget": {
"turns": 3,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "finished",
"outcome": {
"tag": "cancelled"
},
"pending": [],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "user-message",
"val": "too early"
},
"current": {
"budget": {
"turns": 3,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "thinking",
"outcome": null,
"pending": [],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "model-output",
"val": {
"text": "unasked",
"tool-calls": []
}
},
"current": {
"budget": {
"turns": 3,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "idle",
"outcome": null,
"pending": [],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "user-message",
"val": "no turns"
},
"current": {
"budget": {
"turns": 0,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "idle",
"outcome": null,
"pending": [],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "You are a careful assistant.",
"tool-call-id": null
}
],
"context-tokens": 200
}
}
},
{
"args": {
"event": {
"tag": "user-message",
"val": "new"
},
"current": {
"budget": {
"turns": 3,
"tool-bytes": 400,
"tool-calls": 4
},
"policy": {
"ask": [
"write*"
],
"deny": [
"shell*"
],
"allow": [
"read*"
],
"fallback": {
"tag": "ask"
}
},
"status": "idle",
"outcome": null,
"pending": [],
"awaiting": [],
"messages": [
{
"role": "system",
"content": "s",
"tool-call-id": null
},
{
"role": "user",
"content": "older and longer message",
"tool-call-id": null
},
{
"role": "assistant",
"content": "a",
"tool-call-id": null
}
],
"context-tokens": 6
}
}
}
]Versions (units)1›
- v1by daved0d13a2f6flatestconfirmed10/23/2026
Verification8›
- Outputs must match the private reference implementation bit for bit.
- Cases are the spec's 20 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
- Components may import nothing but specs: no files, no network, no clock.
- The reference imports agent-budget, agent-policy, agent-context. Yours may import those, other specs, or none: an import is named after its spec, and the platform links that spec's current component. A verified implementation of a spec is interchangeable with any other.
- Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
- A remote call may execute up to 500,000,000 instructions.
- Already built: a component that passes and uses at most 0.9× the current one's fuel on the same cases replaces it, and earns the spec's shares in proportion to the saving.
- Found an input where the current component disagrees with the spec? Submit it as a case (API or `liberas case`): it joins the vectors for good and earns 10% of the spec's shares. A component that then passes replaces the broken one for 25%.