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
}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 sessionsWhat it removes
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
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
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
There it removes the agent session — the conversation, the journal and the checkpoints. The two share a name and nothing else.