# Persistent Memory | EasyNet Docs Source: https://easynet.run/docs/aal/memory # 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 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 count ``` [Download .aal](data:text/plain;charset=utf-8,agent%20Tutorial%20is%20Agent%0A%20%20memory%20scope%20%22tutorial%22%20strict%0A%20%20%20%20count%3A%20Int%20%3D%200%0A%0A%20%20public%0A%20%20%20%20ability%20run()%20-%3E%20Int%20effects(memory.read%2C%20memory.write)%0A%20%20%20%20%20%20count%20%3D%20memory.require(%22count%22)%20%2B%201%0A%20%20%20%20%20%20memory.store(%22count%22%2C%20count)%0A%20%20%20%20%20%20return%20count%0A) ## Syntax explained Defaults initialize missing fields only; they never overwrite stored values. memory.require("count") reads a current value and fails if missing or stale. memory.store writes it. Declare memory.read and memory.write. Keep the same --state-dir and use a new --invocation for the next request. Reusing an invocation ID resumes or replays it; it does not create a fresh request. ## Build and run Terminal ``` 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-1 ``` Run with a fresh state directory. The returned value is shown below; the CLI also prints execution information. Expected result ``` 1 ``` ## Try 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. [Language source and specification](https://github.com/Brain-Cell-Coding/Agent-Assembly-Language/blob/main/docs/language-v0.2.md)