# rewined

Canonical URL: https://developers.iagenify.com/pt/sdk/agent/events/rewound/
Language: pt

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

Una run che era chiesto per editare un messaggio anterior è tornat prima. Porta esattamente lo que rewind() restituisce — incluso quello che retorn non ha desfare.

Status: only with run({ edit }) · before anything else · names what stays done

## Quando è emitata {#when}

Solo su `run({ edit: n, message })` — editare un messaggio anterior significa tornare a lui e ricominciare con un nuovo testo. L'evento è emanato prima di ningun altro del run.

```javascript
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");
  },
});
```

## Campos {#fields}

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

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `n` | integer |  | Il messaggio ritornò a. |
| `removed` | object |  | Quants messaggi e assistente gira a sinistra la conversa. |
| `files` | object |  | - e `skipped`, con una ragione per cada. |
| `kept` | array |  | **Quanto ha lasciato la máquina e sta a posto** — un send, un deploy, un write de storage, un workflow, un comando. |
| `credits` | object |  | `{ spent, refunded: 0 }`. Le virajes remose sono fatturate, e non sono restituite. |

## manteve il campo da mostrar {#kept}

> **« Rewound » describe i files, non il mondo**
>
> Se tenuta non è vazio, qualcosa accadì che ritornante non inversa. Una interface che nasconde dice l'usuario la run era cancela, che è falso — e falso nella direzion che importa.

## Un rebobinat puè fail {#failures}

Lance antes di emettere qualquer cosa: `session_required`, `agent_running`, `checkpoints_disabled`, `checkpoint_compacted`, `checkpoint_not_found`, `invalid_checkpoint`. La run non inizia.

## Rewinding senza correre {#standalone}

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

- [Pontos de controle](/pt/sdk/agent/checkpoints): Tutto il meccanismo.
- [rewind()](/pt/sdk/ref/local-agent/rewind): Il metodo.
- [Limites da reversão](/pt/sdk/agent/checkpoints/limits): De d'ove vende.

```python
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,
)
```

```python
{
    "type": "rewound",
    "n": 2,
    "files": {"restored": [...], "recreated": [...], "deleted": [...], "skipped": [...]},
    "kept": [],
    "credits": {"spent": 0, "refunded": 0},
}
```

```python
outcome = agent.rewind(2)   # the same object, returned rather than emitted
```
