Persistent Agent
Turn agents can remember things across runs. remember("key", value) writes a value into the agent's durable key-value store. recall("key") reads it back, even after the process exits, the VM restarts, or the machine reboots. The store lives in .turn_store/ as a JSON file keyed to the agent's --id.
This is not an external database. It is a first-class language primitive. No connection strings, no ORM, no migrations. The VM manages the store automatically.
// Turn Language: Persistent Agent
// Run with: turn run persistent_agent.tn --id my_agent
// Run it again and observe run_count increment across restarts.
call("echo", "[Persistent Agent] Booting...");
let run_count = recall("run_count");
let company = "NVDA";
if run_count == null {
remember("run_count", 1);
run_count = 1;
} else {
run_count = run_count + 1;
remember("run_count", run_count);
}
call("echo", "[Persistent Agent] Run #" + run_count + " - analysing: " + company);
let prompt = "In one sentence, assess the investment risk for " + company + ". Run #" + run_count + ".";
let analysis = infer Str { prompt; };
call("echo", "[Persistent Agent] Risk: " + analysis);
remember("last_analysis_" + company, analysis);
call("echo", "[Persistent Agent] State persisted. Run count: " + run_count + ".");How It Works
The first time the agent runs, recall("run_count") returns null because nothing has been stored yet. The agent writes 1 to memory and proceeds.
On every subsequent run, recall returns the previous count. The agent increments it, writes the new value back, and continues. The state survives across process exits because the .turn_store file is written to disk before the VM exits.
The agent's identity is established by the --id flag. Every agent with the same --id shares the same persistent store. Omitting --id gives the run an ephemeral store that is discarded on exit.
remember and recall work for any serializable Turn value: Num, Str, Bool, List, or a Map.
Running It
export TURN_LLM_PROVIDER=openai
export OPENAI_API_KEY=sk-...
# First run
turn run persistent_agent.tn --id my_agent
# Second run: run_count increments
turn run persistent_agent.tn --id my_agent
The full source is in impl/examples/persistent_agent.tn.