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

# ContextManager

> Persist and manage per‑chat message history and tool config

Stores and retrieves a chat's message history and tools configuration.

## Constructor

```ts theme={null}
new ContextManager(cache: ICache, options?: ContextManagerOptions)
```

| Option               | Type                    | Description                                                 |
| -------------------- | ----------------------- | ----------------------------------------------------------- |
| `cacheKeyPrefix`     | `string`                | Key prefix for cache entries (default: `"illa:sdk:ctx"`)    |
| `cacheEntryOptions`  | `CacheEntryOptions`     | Default TTL settings forwarded to the cache                 |
| `defaultToolsConfig` | `ToolAutorouterRequest` | Default tool routing config returned when no data is stored |

## Methods

* `getContext(chatId): Promise<{ messages, toolsConfig }>`
* `clearContext(chatId): Promise<void>`
* `setMessages(chatId, messages): Promise<void>`
* `appendMessages(chatId, messages): Promise<void>`
* `setToolsConfig(chatId, toolsConfig): Promise<void>`
* `deleteContext(chatId): Promise<void>`

Notes:

* `clearContext` resets message history and tools config to defaults for a chat but keeps the chat ID registered. Use `deleteContext` to remove everything including the cache entry.
* The manager deep‑clones stored data to avoid accidental mutation by callers.

## Example

```ts theme={null}
const snapshot = await chat.getContext()
await chat.setContext(snapshot)
```
