Erase everything this agent has accumulated, in one call. For when the thing the agent represents is over — a phone number is released, an account closes, a case is settled — and what comes next must inherit nothing. Rather than hand-deleting each piece and hoping none was missed,protecteddestroy():Promise<void>
destroy() empties them together:
- State —
getStatereads backinitialState()again. - Timers — every pending
queue/schedule/everytask is removed,listSchedulesis empty, and the agent’s wake-up is cancelled. A 24-hour follow-up booked before the number changed hands never fires. - Conversation history —
this.messagesis emptied, seq counter included, so the next message isseq1. - Progress events —
this.eventslikewise. - Connections — every client the agent is holding is closed, and
attachmentsdrops to zero.
destroy() empties an agent; it does not remove it. The instance keeps
existing and stays usable: the very next call writes into a clean agent,
exactly as the first call to a brand-new one does. Removing the instance
itself is a separate, platform-level operation.
Two things are deliberately left alone, because the agent does not own
them:
- Objects in a bucket. Content offloaded through a
BlobStorelives in object storage under keys of your choosing, and may be large, shared between agents, or subject to your own retention rules. Delete what you no longer want through the bucket, before calling this. - Keys you wrote yourself. Anything the subclass put in
ctx.storagedirectly is yours to manage; only the agent’s own stores are emptied.
@rpc()-decorated method, a fetch
route, a task that fires when a retention window closes):
destroy must rename it (or align it to override this method).
Returns
Promise<void>