Persistent Memory
Share declared state across invocations.
Local variables belong to the current execution. memory scope declares persistent agent fields; strict requires declared fields. This counter reads the stored value, increments it and saves it.
Complete example
Save the example as memory.aal
agent Tutorial is Agent
memory scope "tutorial" strict
count: Int = 0
public
ability run() -> Int effects(memory.read, memory.write)
count = memory.require("count") + 1
memory.store("count", count)
return countSyntax explained
-
Defaults initialize missing fields only; they never overwrite stored values.
-
memory.require("count")reads a current value and failsifmissing or stale.memory.storewrites it. Declarememory.readandmemory.write. -
Keep the same
--state-dirand use a new--invocationforthe next request. Reusing an invocation ID resumes or replays it; it does not create a fresh request.
Build and run
cargo run --locked --bin aalc -- check memory.aal
cargo run --locked --bin aalc -- build memory.aal -o memory.aalc
cargo run --locked --bin aalc -- run memory.aalc \
--agent Tutorial --ability run \
--args '{}' \
--state-dir .aal-tutorial/memory --invocation memory-1Run with a fresh state directory. The returned value is shown below; the CLI also prints execution information.
1Try it yourself
Keep the state directory and use memory-2 as the invocation ID. The result is 2. Reusing memory-2 replays that result instead of incrementing again.