> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kazzle.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Agents and threads API

> Create native agents and reusable conversations from an app.

# Agents and threads API

Agents hold instructions, tools, memory, and assigned resources. Threads hold conversations. Both are normal resources with create, list, get, update, and delete operations.

```ts theme={"theme":"material-theme-darker"}
import { Kazzle } from '@kazzle/app/sdk';

const kazzle = new Kazzle();
const agent = await kazzle.agents.create({
  name: 'Order support',
  instructions: 'Help customers with their orders.',
});

const thread = await kazzle.threads.create({ agentId: agent.id });
await saveThreadIdForCustomer(customerId, thread.id);
const reply = await thread.send('Where is my order?').text();
```

Reuse the saved thread for later messages:

```ts theme={"theme":"material-theme-darker"}
const thread = kazzle.threads.fromId(savedThreadId);
const reply = await thread.send('What was the tracking number?').text();
```

Use `kazzle.agents` and `kazzle.threads` for CRUD. A thread handle also provides `messages()`, `watch()`, `stop()`, `retry()`, `resume()`, and `approve()`.

For a customer-facing app, store any customer-to-thread mapping in the app's database. Kazzle does not need the customer's ID.

All calls use the server-side `KAZZLE_API_KEY`. The key limits access to its Kazzle space. Do not expose it to browser code.
