Where did you hear about us?
1 of 6
Sleep

Sleep - read back, rewrite.

The AI reads back its day and rewrites its files about itself and the people around it.

What sleep is

A Scroll 2 store holds the AI's own files: one core about itself, and four boxes the AI names and fills. The core is written with "I" as the subject: what it likes, what it won't do, and how it sees the people in its life. A sleep reads what came into the store since the last one and rewrites these files. The core can hold 70,000 tokens and each box 20,000, and every version of a file is kept.

Who runs it, and when

A sleep runs on the model your app picks, with your app's key. Wontopos runs no model. You pay the model's provider, and with no model named a sleep uses Claude Sonnet 5.5, which we measured at about $4.29 per million tokens of conversation read, at list price with prompt caching off.

A sleep runs only when you call it: at night, for a nap, or on a command. Past 10 million tokens of new memory since the last sleep the AI is marked sleepy (sleepy), and it need not sleep then either. Sleep is experimental.

Running a sleep

sleep_estimate

What a sleep would read and about what it would cost, before it runs: the memories and tokens since the last sleep, the input the model would be sent and the output it would write, the cost in dollars, and whether the AI is sleepy. For another model, pass its input and output prices. Pass the sleep_id the estimate returns to sleep, and the same memories are not read twice.

sleep

One sleep. It reads, rewrites the files, and ends the store's last sleep here.

  • llm the model that reads (required): anthropic_caller, openai_caller, or a function of your own.
  • being the name the sleep calls the AI by.
  • assistant the name on the assistant's own lines. Without it, the store's default name.
  • prompt the AI's prompt, written into the core the first time.
  • settings the size of the core and of each box.
  • done=False leaves the last sleep where it was, so the next sleep reads the same lines again.

The answer has the new version of each file written that night, what was not taken and why, and the tokens each model call used. A model call that meets a rate limit, an overload or a dropped connection is tried twice more; any other failure ends the sleep with nothing written. If something else changes the files while the sleep runs, it raises ConflictError and keeps none of that night's changes. Empty the recent conversation the sleep read with clear_window.

from wontopos import anthropic_caller

llm = anthropic_caller(model_key, model="claude-sonnet-5-5")   # your key, your model
plan = mem.sleep_estimate("jimin")
print(plan["memories"], plan["cost"], plan["sleepy"])
night = mem.sleep("jimin", llm=llm, being="Kai", sleep_id=plan["sleep_id"])
mem.clear_window("jimin")                                      # the recent turns it read
import { anthropicCaller } from "wontopos";

const llm = anthropicCaller({ apiKey: modelKey, model: "claude-sonnet-5-5" });   // your key, your model
const plan = await mem.sleepEstimate("jimin");
console.log(plan.memories, plan.cost, plan.sleepy);
const night = await mem.sleep("jimin", { llm, being: "Kai", sleepId: plan.sleep_id ?? undefined });
await mem.clearWindow("jimin");                                                  // the recent turns it read
use std::sync::Arc;
use wontopos::{anthropic_caller, AnthropicCallerOpts, SleepEstimateOpts, SleepOpts};

let llm = anthropic_caller(AnthropicCallerOpts {
    api_key: model_key, model: Some("claude-sonnet-5-5".into()), ..Default::default()
})?;                                                   // your key, your model
let plan = mem.sleep_estimate("jimin", &SleepEstimateOpts::default()).await?;
let night = mem.sleep("jimin", Arc::new(llm), &SleepOpts {
    being: "Kai".into(),
    sleep_id: plan["sleep_id"].as_str().map(str::to_string),
    ..Default::default()
}).await?;
mem.clear_window("jimin", None).await?;                // the recent turns it read

Reading the files

sleep_files returns the whole core and each box's title, version and size; open_sleep_file returns one file whole, an earlier version too; sleep_file_history lists every version of one file. To keep the files beside the model during a conversation, use sleep=True on the memory tools.

f = mem.sleep_files("jimin")
print(f["core"]["title"], [b["title"] for b in f["files"]])
box = mem.open_sleep_file(1, "jimin")              # 0 is the core, 1 to 4 the boxes
tools = mem.memory_tools("jimin", sleep=True)      # the files beside the model, every turn
const f = await mem.sleepFiles("jimin");
const box = await mem.openSleepFile(1, "jimin");    // 0 is the core, 1 to 4 the boxes
const tools = mem.memoryTools("jimin", { sleep: true });   // the files beside the model, every turn
let f = mem.sleep_files("jimin").await?;
let boxed = mem.open_sleep_file(1, "jimin", None).await?;   // 0 is the core, 1 to 4 the boxes
let tools = mem.memory_tools("jimin", None)?.with_sleep(true); // the files beside the model, every turn

Writing your own sleep

To build the steps yourself: sleep_read reads a day's memories a page at a time, sleep_verify checks that what a write cites came from this sleep, write_sleep_files writes new versions of the files, all or none, and sleep_done ends the store's last sleep at this one. sleep_notes and write_sleep_notes read and write the notes a sleep keeps for the next one.