Undo logs do not work for an agent. A file written by a command has no previous version, a file created after the fact has no « before », a rename has no inverse. So the engine keeps a snapshot instead of a list of reversals.
Using it
const agent = api.agents.create({
runtime: "local", machine: pc, model: "gemini-3.5-flash",
memory: true, // checkpoints need a session
mode: "auto",
});
await agent.run({ inputs: "Rename every component to PascalCase." });
await agent.run({ inputs: "Now update the imports." });
const points = await agent.checkpoints();
// [{ n: 1, at, text: "Rename every component…", files: 184, partial: false, outside: [] },
// { n: 2, at, text: "Now update the imports.", files: 184, partial: false, outside: [] }]
await agent.rewind(2); // back to just before the second messageagent = api.agents.create(
runtime="local", machine=pc, model="gemini-3.5-flash",
memory=True, # checkpoints need a session
mode="auto",
)
agent.run(inputs="Rename every component to PascalCase.")
agent.run(inputs="Now update the imports.")
points = agent.checkpoints()
# [{"n": 1, "at", "text": "Rename every component…", "files": 184, "partial": False},
# {"n": 2, "at", "text": "Now update the imports.", "files": 184, "partial": False}]
agent.rewind(2) # back to just before the second messageA point is a message, not a step
n counts your messages in the session. Rewinding to n restores the files as they were before that message and removes the message and everything after it from the conversation, the device journal and the account.
What rewind reports
{
n: 2,
removed: { messages: 11, turns: 5 },
files: { restored: [...], recreated: [...], deleted: [...], skipped: [...] },
kept: ["send_mail", "deploy"], // what left the machine and stays done
credits: { spent: 24, refunded: 0 }
}{
"n": 2,
"files": {"restored": [...], "recreated": [...], "deleted": [...], "skipped": [...]},
"kept": [], # what left the machine and stays done
"credits": {"spent": 0, "refunded": 0},
}A message that was sent is sent. A site that was published is online. Credits that were spent are spent. The answer names them rather than letting « rewind » suggest the world was put back.
What it needs
| Requirement | Otherwise |
|---|---|
memory: true | session_required — there is no session to attach points to. |
| Not currently answering | agent_running — call stop() first. |
checkpoints not turned off | checkpoints_disabled. |
| Not a subagent | A subagent keeps none: it has no conversation of its own to cut. |
Turning it off
api.agents.create({ runtime: "local", machine: pc, model, memory: true, checkpoints: false });api.agents.create(runtime="local", machine=pc, model=model, memory=True, checkpoints=False)Reasonable on a huge workspace, or where the storage quota matters more than going back. A snapshot that cannot be taken never blocks an answer — it is skipped and the run continues.