Persistent Agent
persist let x = y; serializes the variable to .turn_store/persist_<name>.json after every assignment. On the next boot, the Turn VM pre-loads these values automatically.
Run this script twice and observe run_count increment across restarts — zero database, zero boilerplate.
persistent_agent.tn
// Turn Language: Persistent Agent
// Run first: turn run impl/examples/persistent_agent.tn --id my_agent
// Run second: turn run impl/examples/persistent_agent.tn --id my_agent
// Observe: run_count increments across restarts.
call("echo", "[Persistent Agent] Booting...");
persist let run_count = 0;
persist let company = "NVDA";
persist let run_count = run_count + 1;
call("echo", "[Persistent Agent] Run #" + run_count + " - Analyzing: " + 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);
call("echo", "[Persistent Agent] State persisted. Next run: run_count = " + run_count + ".");Run it twice to see persistence in action:
turn run impl/examples/persistent_agent.tn --id my_agent turn run impl/examples/persistent_agent.tn --id my_agent
The full implementation is in impl/examples/persistent_agent.tn.