Events

rewound

{ type: "rewound", n, removed, files, kept, credits }

A run that was asked to edit an earlier message went back first. It carries exactly what rewind() returns — including what going back did not undo.

only with run({ edit })before anything elsenames what stays done
Using Python?

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

When it is emitted

Only on run({ edit: n, message }) — editing an earlier message means going back to it and starting again with new text. The event is emitted before anything else of the run.

await agent.run({
  edit: 2,                                  // go back to just before message 2
  message: "Actually, rename them to kebab-case.",
  onEvent: (e) => {
    if (e.type === "rewound") console.log("undid", e.removed.messages, "messages");
  },
});
def on_event(event):
    if event["type"] == "rewound":
        print("restored", len(event["files"]["restored"]), "files")

agent.run(
    edit=2,                                   # go back to just before message 2
    message="Actually, rename them to kebab-case.",
    on_event=on_event,
)

Fields

{
  type: "rewound",
  n: 2,
  removed: { messages: 11, turns: 5 },
  files: { restored: [...], recreated: [...], deleted: [...], skipped: [...] },
  kept: ["send_mail", "deploy"],
  credits: { spent: 24, refunded: 0 }
}
{
    "type": "rewound",
    "n": 2,
    "files": {"restored": [...], "recreated": [...], "deleted": [...], "skipped": [...]},
    "kept": [],
    "credits": {"spent": 0, "refunded": 0},
}
ninteger

The message gone back to.

removedobject

How many messages and assistant turns left the conversation.

filesobject

What was restored, recreated, deleted — and skipped, with a reason each.

keptarray

What left the machine and stays done — a send, a deploy, a storage write, a workflow, a command.

creditsobject

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

kept is the field to show

« Rewound » describes the files, not the world

If kept is not empty, something happened that going back does not reverse. An interface that hides it tells the user the run was undone, which is false — and false in the direction that matters.

A rewind can fail

It throws before emitting anything: session_required, agent_running, checkpoints_disabled, checkpoint_compacted, checkpoint_not_found, invalid_checkpoint. The run does not start.

Rewinding without running

const outcome = await agent.rewind(2);   // the same object, returned rather than emitted
outcome = agent.rewind(2)   # the same object, returned rather than emitted