Memory & Working Knowledge

Every Turn process has a built-in, durable key-value memory store. You write to it with remember, read from it with recall, and it persists automatically across suspend boundaries and VM restarts. No external database is required.


The Problem with Ad-Hoc Memory

In most agent systems, "memory" means either:

  • A messages list Unbounded, context-polluting, with no retrieval strategy.
  • A vector database An entirely separate service to maintain, query, and synchronize.

Turn makes memory a first-class component of the process state, stored alongside the agent's environment, context window, and mailbox. It is durable and automatic.


remember : Writing to Memory

syntax
remember("key", value);

Stores a value in the agent's persistent memory under the given key. Memory persists across turns, suspend boundaries, and process restarts.

example
// Store any Turn value: strings, numbers, maps, lists
remember("user_name", "Alice");
remember("preferred_style", "concise, bullet-point format");
remember("session_count", 7);
remember("last_context", current_summary);

NOTE

Memory is isolated per process. Each spawned actor has its own memory namespace. A child process cannot read or write the parent's memory.


recall : Reading from Memory

syntax
let value = recall("key");

Retrieves the value stored under the given key. Returns null if the key does not exist.

example
let name = recall("user_name");
if name == null {
  remember("user_name", "Guest");
} else {
  call("echo", "Welcome back, " + name);
}

let style = recall("preferred_style");
let result = infer Summary {
  "Summarize this report in " + style + ": " + report_text;
};

Memory Across Sessions

Memory survives process restarts. This is the primary mechanism for building agents that accumulate knowledge over time:

persistent_agent.tn
// Read state from previous sessions
let run_count = recall("run_count");
let last_result = recall("last_result");

if run_count == null {
  remember("run_count", 1);
  call("echo", "First run. No prior state.");
} else {
  let new_count = run_count + 1;
  remember("run_count", new_count);
  call("echo", "Run #" + new_count + ". Last result was: " + last_result);
}

let result = infer Report { "Analyze current market conditions."; };
remember("last_result", result["summary"]);

Memory vs. Context

These are two distinct primitives with different lifetimes and purposes:

mental model
memory   =  the agent's DURABLE KNOWLEDGE
           persisted to .turn_store/ automatically
           survives restarts, suspend boundaries
           exact key-value lookup via recall()

context  =  the agent's WORKING SCRATCHPAD for this turn
           token-bounded, per-process
           what the LLM sees when infer is called
           written with context.append()
MemoryContext
LifetimePermanent (persists across restarts)Per-turn (cleared on completion)
CapacityUnlimitedToken-budgeted
AccessExact key lookup (recall("key"))Automatic (injected into every infer)
Written withremember("key", val)context.append(val)
Read withrecall("key")Automatic

Use memory for facts that should persist across conversations, sessions, and process restarts. Use context for the working scratchpad of the current inference call.


Next Steps