Skip to main content

Crate agentstategraph_policy_wasm

Crate agentstategraph_policy_wasm 

Source
Expand description

WASM host runner for AgentStateGraph policies (0.7.5 §4b).

This crate is a host-side ExternalEvaluator that loads a WASM policy module via wasmtime and invokes it through a small, documented ABI. It is NOT compiled to WASM itself — it runs a WASM module inside the host process.

§ABI

The module MUST export a linear memory named memory plus three functions:

(func (export "asg_alloc")
  (param $size i32) (result i32))

(func (export "asg_free")
  (param $ptr i32) (param $size i32))

(func (export "asg_evaluate")
  (param $input_ptr i32) (param $input_len i32)
  (result i64))     ;; high 32 bits = output_ptr, low 32 bits = output_len

The host:

  1. Instantiates the module (no imports required).
  2. Calls asg_alloc(input_len) and writes the input JSON bytes into linear memory at the returned pointer.
  3. Calls asg_evaluate(input_ptr, input_len). The return value packs the output pointer in the high 32 bits and the output length in the low 32 bits of the i64.
  4. Reads output_len bytes from output_ptr in linear memory and parses them as JSON of Decision.
  5. Calls asg_free on both the input and the output buffers.

§Input JSON

{
  "situation": { "<fact-key>": "<fact-value>", ... },
  "action": "<action-name>",
  "agent_id": "<agent-id>"
}

§Output JSON

Serde tagged union matching Decision — see the agentstategraph-policy crate.

§Source variants

Structs§

WasmEvaluator
Host-side WASM runner.