> ## 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.

# Chat

> Low-level conversational object for session-scoped control

`Chat` represents one conversation and gives direct control over prompts, context, and streaming.

Use `IllaSDK#createChat` unless you need custom dependency wiring.

## Construction

```ts theme={null}
new Chat({
  coreApiProvider,
  contextManager,
  userContext,
  id,
  asyncToolChecker,
  defaultRole,
  personalityContext,
  modelContext,
})
```

## Properties

### `getId(): string`

Returns the chat identifier.

### `messages: Promise<MessageHistoryType>`

Returns current message history from the context manager.

## Core methods

### `sendMessage(prompt, options?)`

```ts theme={null}
sendMessage(
  prompt: Prompt | Prompt[],
  options?: SendMessageOptions,
): Promise<SendMessageResult>
```

Rules:

* Single `Prompt` must be text-kind.
* `Prompt[]` is for tool-result prompts only.

### `sendMessageStreaming(prompt, options?)`

```ts theme={null}
sendMessageStreaming(
  prompt: Prompt,
  options?: SendMessageStreamingOptions,
): Promise<void>
```

Streams telemetry and final result via callbacks.

### `getContext()` / `setContext(snapshot)`

```ts theme={null}
getContext(): Promise<ChatContextSnapshot>
setContext(snapshot: ChatContextSnapshot): Promise<void>
```

Read/replace persisted chat context.

### `awaitAction(descriptor)`

```ts theme={null}
awaitAction(descriptor: AwaitableActionDescriptor): Promise<AwaitActionResult>
```

Requires `asyncToolChecker` at construction. Descriptor fields are `toolName`, `protocol`, and `args`.

## Example

```ts theme={null}
import {
  AsyncToolChecker,
  Chat,
  ContextManager,
  CoreApiProvider,
  InMemoryCache,
  Prompt,
} from '@illalabs/sdk'

const provider = new CoreApiProvider({
  headers: { 'x-api-key': process.env.ILLA_API_KEY! },
})

const contextManager = new ContextManager(new InMemoryCache())
const checker = new AsyncToolChecker({ coreApiProvider: provider })

const chat = new Chat({
  coreApiProvider: provider,
  contextManager,
  asyncToolChecker: checker,
  userContext: { address: '0x1234...' },
})

const result = await chat.sendMessage(new Prompt({ text: 'What is my wallet balance?' }))
if (!result.response.isError) {
  console.log(result.response.data.text)
}
```

## See also

* [ILLA SDK](/sdk/api/illa-sdk)
* [Streaming events](/sdk/api/streaming-events)
