LocalAgent

rewind()

agent.rewind(n) → Promise<Outcome>

Go back to a message: the files return to what they were, the message and everything after it leave the conversation — and the answer names what could not be undone.

needs a sessionstop it firstnames what stays done
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

const outcome = await agent.rewind(2);
// {
//   n: 2,
//   removed: { messages: 11, turns: 5 },
//   files: { restored: [...], recreated: [...], deleted: [...], skipped: [...] },
//   kept: ["send_mail", "deploy"],
//   credits: { spent: 24, refunded: 0 }
// }
outcome = agent.rewind(2)
# {
#   "n": 2,
#   "files": {"restored": [...], "recreated": [...], "deleted": [...], "skipped": [...]},
#   "kept": [],
#   "credits": {"spent": 0, "refunded": 0}
# }

The workspace first

Files are restored before anything else, because that is the part that can fail. Then the conversation is cut, then the device journal, then the account's copy.

What it reports

ninteger

The message gone back to.

removedobject

{ messages, turns } — what left the conversation.

filesobject

restored, recreated, deleted, and skipped with a reason each.

keptstring[]

What left the machine and stays done.

creditsobject

{ spent, refunded: 0 }. The removed turns were billed and are not given back.

kept and refunded: 0 are the honest part

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 files.skipped means

ReasonMeans
too large to have been copiedOver 25 MB — recorded, never copied, cannot be restored
saved content is goneThe stored content was collected
could not be writtenLocked, in use, or refused by the file system
more than 5 000 files: the checkpoint is partialThe snapshot never held everything

Refusals

CodeStatusWhen
session_required400No session — memory: true is needed.
agent_running409It is answering. stop() first.
invalid_checkpoint400n is not a whole number of at least 1.
checkpoints_disabled400checkpoints: false.
checkpoint_compacted404That message was summarised away. The message names what is left.
checkpoint_not_found404No such message. The message lists the available numbers.

Rewinding and running in one call

await agent.run({ edit: 2, message: "Actually, rename them to kebab-case." });
agent.run(edit=2, message="Actually, rename them to kebab-case.")

The same rewind, then the run — with a rewound event carrying this outcome.