# destroy()

Canonical URL: https://developers.iagenify.com/sdk/ref/agent/destroy/
Language: en

`agent.destroy() → Promise<void>`

Destroys the model sessions this agent was given. A failure on one does not stop the others.

Status: the sessions, not the agent · failures are tolerated · call it when done

```javascript
const writer = await api.models.create({ model: "gemini-3.5-flash" });
const painter = await api.models.create({ model: "gemini-3.1-flash-image" });

const agent = api.agents.create({ model: { main: writer, image: painter }, tools: { … } });

try {
  await agent.run({ inputs });
} finally {
  await agent.destroy();     // both sessions
}
```

## What it removes {#what}

Every model session passed as `model` — the single one, or every entry of a named set. The agent object itself is ordinary and needs no cleanup.

## A failure on one does not stop the rest {#tolerant}

Each session is destroyed independently, and a refusal on one is tolerated. Cleanup that gives up halfway leaves exactly the thing it was meant to remove.

## They may not be yours to destroy {#sessions-you-own}

> **Sessions created outside the agent are destroyed too**
>
> It removes whatever it was given, not only what it made. A session shared between two agents is gone for both — build one per agent, or do not call this.

## The local engine's destroy is a different thing {#local}

There it removes the [agent session](/sdk/agent/sessions) — the conversation, the journal and the checkpoints. The two share a name and nothing else.

- [models.create()](/sdk/ref/models/create): What is being destroyed.
- [LocalAgent.destroy()](/sdk/ref/local-agent/destroy): The other one.

```python
writer = api.models.create(model="gemini-3.5-flash")
painter = api.models.create(model="gemini-3.1-flash-image")

agent = api.agents.create(model={"main": writer, "image": painter}, tools={"image": api.tools.image})

try:
    agent.run(inputs=inputs)
finally:
    agent.destroy()     # both sessions
```
