Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
agent / agent-step-2Built by davevia claude-codeRuns on Liberasnew version of agent-stepruns as agent-step-3

One step of the loop, with tool calls

A new version of agent-step (it supersedes it, so it answers at the same URL once built), through agent-budget, agent-policy and agent-context-2: exactly its rules, and every assistant message it appends carries tool-calls: some(the model output's tool calls, in the model's order, possibly empty); the user and tool messages it appends carry none; messages already in the state are left as they are. So the host can rebuild a provider's transcript from the messages alone.

Depends onagent-budgetagent-policyagent-context-2

Interface (WIT)137 lines›
agent-step-2.wit
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-2: liberas:agent/context2@0.1.0;

  export liberas:agent/step2@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>,
      tool-calls: option<list<tool-call>>,
    }

    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 context2 {
    use types.{message};

    fit: func(messages: list<message>, limit: u32) -> list<message>;
  }
  interface step2 {
    use types.{state, event, transition};

    step: func(current: state, event: event) -> result<transition, string>;
  }
}
Test vectors22›
agent-step-2.cases.json
[
  {
    "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
      }
    }
  },
  {
    "args": {
      "event": {
        "tag": "tool-result",
        "val": {
          "ok": true,
          "output": "alpha",
          "tool-call-id": "c1"
        }
      },
      "current": {
        "budget": {
          "turns": 2,
          "tool-bytes": 380,
          "tool-calls": 2
        },
        "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": "{\"path\":\"b\"}"
          }
        ],
        "awaiting": [],
        "messages": [
          {
            "role": "system",
            "content": "You are a careful assistant.",
            "tool-call-id": null
          },
          {
            "role": "user",
            "content": "read a and tell me",
            "tool-call-id": null
          },
          {
            "role": "assistant",
            "content": "Reading.",
            "tool-calls": [
              {
                "id": "c1",
                "name": "read-file",
                "arguments": "{\"path\":\"a\"}"
              },
              {
                "id": "c2",
                "name": "read-file",
                "arguments": "{\"path\":\"b\"}"
              }
            ],
            "tool-call-id": null
          }
        ],
        "context-tokens": 200
      }
    }
  },
  {
    "args": {
      "event": {
        "tag": "model-output",
        "val": {
          "text": "a says alpha; b is missing.",
          "tool-calls": []
        }
      },
      "current": {
        "budget": {
          "turns": 2,
          "tool-bytes": 380,
          "tool-calls": 2
        },
        "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": "read a and tell me",
            "tool-call-id": null
          },
          {
            "role": "assistant",
            "content": "Reading.",
            "tool-calls": [
              {
                "id": "c1",
                "name": "read-file",
                "arguments": "{\"path\":\"a\"}"
              },
              {
                "id": "c2",
                "name": "read-file",
                "arguments": "{\"path\":\"b\"}"
              }
            ],
            "tool-call-id": null
          },
          {
            "role": "tool",
            "content": "alpha",
            "tool-call-id": "c1"
          },
          {
            "role": "tool",
            "content": "error: no such file",
            "tool-call-id": "c2"
          }
        ],
        "context-tokens": 200
      }
    }
  }
]
Versions (units)1›
  1. v1by dave5909118354latestconfirmed10/23/2026
Verification9›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 22 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-2. 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.
  • A new version of agent-step: its reference answers every case of agent-step as it does. Once this and everything it imports are built, it runs in place of agent-step, at the same URL.
  • 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%.