Why agents forget
Most modern agents forget everything when a run ends. What they learn lives in the conversation: the decisions you made together, who reviews what, where the work stopped. When the run ends, so does the conversation, and the next run starts from nothing. You explain it all again. The agent was told. It just has nowhere to keep it.
The usual fixes get harder over time. Pasting the old conversation into each new prompt works for a few runs. Then every prompt grows longer and slower, and the one decision that matters is buried under pages of chat. A database just for memory means a schema to design, and nobody can easily open it to see what the agent believes.
The usual setup
What we’ll build
In this guide we’ll do something simpler. Each agent gets a folder of plain files, stored in your own bucket. It writes down what it learns as it learns it. The next run opens the same folder and reads only the lines it needs. And because every save is kept, you can see when a memory was made, and take back the wrong ones.
What we’re building
By the end, you’ll have:
- A memory folder for one agent, with a file for decisions, people and progress.
- A key the agent can use to reach that folder and nothing else.
- A remember function that saves each new fact the moment the agent learns it.
- A recall function that starts every run with a short, relevant summary.
- A full history of the agent’s memory, and a way to undo a wrong note.
You’ll need a Skywake API key and Node. Set SKYWAKE_API_KEY, then install the SDK with npm i skywake.
Step 1
Give the agent a folder
Our agent is called agent-37. Its memory will be three small Markdown files, one per kind of thing worth keeping:
memory-agent-37/
- decisions.md# what we chose, and what we ruled out
- people.md# who does what, and how they like to work
- notes.md# where the last run stopped
In Skywake, a folder like this is a disk: a set of files with branches and history. Every disk starts with a branch called main. Think of it like a Git branch: each save is a commit, and every older version stays. The first write creates the disk.
import { Skywake } from "skywake";
const sky = new Skywake();
await sky.disk("memory-agent-37").write(
{
"decisions.md": "# Decisions\n",
"people.md": "# People\n",
"notes.md": "# Where I left off\n",
},
{ message: "Empty memory" },
);The agent now has an empty memory with three headings. It lives in your bucket, not on the machine the agent runs on, so it stays when that machine is gone.
Step 2
Give it a key to that folder only
The agent should not run with your key. If it did, a confused run could read or change another agent’s memory. So we make it a key of its own that opens one disk.
const { key } = await sky.createKey({
name: "agent-37",
role: "write",
only: ["memory-agent-37"],
});The write role lets the agent read and save files, and only keeps it to this one disk. The key is shown only this once. If the agent tries to open memory-agent-12, the server answers “no access”.
Step 3
Save what it learns
Don’t wait for the end of the run to save. Runs crash, time out and get stopped. Save each fact the moment the agent learns it. We’ll write one small function for that, and give it to the agent as a tool.
const agent = new Skywake({ key });
const memory = agent.disk("memory-agent-37");
async function remember(file: string, line: string) {
const before = await memory.read(file);
await memory.write(file, `${before}- ${line}\n`, { message: line });
}The agent gets its own client with its own key. In a real run, give the key to the agent’s process as SKYWAKE_API_KEY, and new Skywake() picks it up. remember reads the file, adds one line at the end, and saves it as one commit. The line itself becomes the commit message, so the history reads like a diary. Say that on Monday you and the agent work on a new login flow together. Here is what that run saves:
await remember("decisions.md", "Login uses passkeys, not SMS codes.");
await remember("people.md", "Maya reviews all auth changes.");
await remember("notes.md", "Stopped at: the sign-up form.");Three facts, three commits. If the run had crashed after the first one, the passkeys decision would already be safe.
Tip: one fact per line
Ask the agent to write short lines that make sense alone, like “Login uses passkeys, not SMS codes.” A line like “Agreed, let’s do that” means nothing on Thursday.
Step 4
Start the next run from its notes
On Thursday a new run starts, on a new machine, with the same key. Before it does anything, it should know where it stopped and what it already decided. But it doesn’t need everything. Asked about login, it doesn’t need to know who reviews pull requests.
So recall reads notes.md in full, then searches the memory for lines about the task at hand. grep returns each matching line and the file it came from. ignoreCase tells it to ignore upper and lower case.
async function recall(topic: string) {
const notes = await memory.read("notes.md");
const hits = await memory.grep(topic, { ignoreCase: true });
const known = hits.map((hit) => `${hit.path}: ${hit.text}`);
return [notes, `About ${topic}:`, ...known].join("\n");
}
const context = await recall("login");Put context at the top of the run’s prompt. It holds two short facts: the run stopped at the sign-up form, and login uses passkeys. The note about Maya is left out, because it says nothing about login. Now Thursday goes differently:
Add login to the mobile app.
Should login use passwords, SMS codes or passkeys?
Without memoryPicking up after the sign-up form. Login uses passkeys, as we decided on Monday.
With memory · from notes.md, decisions.mdThe prompt stays small however long the agent has been working. It grows with what matters to today’s task, not with every run that came before.
Step 5
Read what it remembered
An agent’s memory is only useful if you can trust it, and you can only trust what you can read. Agents make mistakes too. On Tuesday the agent misread a message in a long thread, and saved a decision nobody made:
await remember("decisions.md", "Keep SMS codes as a backup login.");Nobody noticed. Because each fact is a commit, the log shows what the agent learned and when. This time we use your own key, not the agent’s:
const review = sky.disk("memory-agent-37");
for await (const commit of review.log({ limit: 10 })) {
console.log(commit.id.slice(0, 7), commit.message);
}
await review.download("./agent-37");The log is newest first, and Tuesday’s wrong note is at the top:
- Keep SMS codes as a backup login.Tuesday
- Stopped at: the sign-up form.Monday
- Maya reviews all auth changes.Monday
- Login uses passkeys, not SMS codes.Monday
download also copies the memory into a local folder, as plain files. Open ./agent-37 in your editor and read the agent’s mind like any other notes.
Step 6
Undo a wrong memory
A wrong memory is worse than none. The agent will act on it with confidence, run after run. So we take it back. A revert makes a new commit that undoes an old one, and leaves everything else as it is.
for await (const commit of review.log({ limit: 10 })) {
if (commit.message.startsWith("Keep SMS codes")) {
await review.revert(commit.id, { message: "Forget: SMS backup" });
break;
}
}The SMS line is gone from decisions.md, and the passkeys decision stays. The next recall("login") no longer brings back the SMS backup. But nothing is erased from history: review.log({ path: "decisions.md" }) still shows the wrong note, and the commit that removed it. If you ever wonder why the agent did something on Tuesday, the answer is still there.
Running it for real
One agent with three files is the whole idea. A few things help when you run many agents for months:
- One disk per agent, with one prefix. Name them
memory-agent-37,memory-agent-12and so on. Each agent’s key opens only its own. - One read key to see them all. A dashboard, or a lead agent that checks the others’ work, can get a key for every memory disk. It can read every memory and change none.
const reader = await sky.createKey({
name: "memory-reader",
role: "read",
only: ["memory-*"],
});Hand reader.key to the dashboard. The * covers every disk whose name starts with memory-, including agents you add later.
- Keep files short. When a file gets long, ask the agent to rewrite it as a short summary, in one commit. The long version stays in history if you ever need it.
- Search by meaning when memory gets big. Line search is enough for most agents. If one keeps thousands of notes, search them by meaning with
memory.query, as in the knowledge base guide. - It all stays yours. Every memory is a plain file in your own bucket. There is no separate memory database to run or pay for.