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_lenThe host:
- Instantiates the module (no imports required).
- Calls
asg_alloc(input_len)and writes the input JSON bytes into linear memory at the returned pointer. - 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 thei64. - Reads
output_lenbytes fromoutput_ptrin linear memory and parses them as JSON ofDecision. - Calls
asg_freeon 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
EvaluatorSource::Inline—bodyis interpreted as the raw bytes of the WASM module (as a string, so binary modules should be embedded viaFilePathinstead in practice;Inlineis useful mainly for WAT fixtures).EvaluatorSource::FilePath— read the module bytes from disk.EvaluatorSource::CommitRef— not supported by this runner; returnsExternalError::SourceResolution. The dispatcher is responsible for resolving commit refs in a future milestone.
Structs§
- Wasm
Evaluator - Host-side WASM runner.