<!--
 ⚠️  AUTO-GENERATED FILE - DO NOT EDIT MANUALLY
 This file is automatically generated by scripts/docs-generator.js
 To make changes, edit the source TypeScript files or update the generator script
-->

[sessions](../../) / [Exports](../modules) / ConversationSession

# Class: ConversationSession

Conversation Session for a single conversation/session with enhanced features

Implements ConversationHistoryInterface with additional features like
duplicate prevention and API format conversion.

## Implements

- `ConversationHistoryInterface`

## Table of contents

### Constructors

- [constructor](ConversationSession#constructor)

### Methods

- [addMessage](ConversationSession#addmessage)
- [addUserMessage](ConversationSession#addusermessage)
- [addAssistantMessage](ConversationSession#addassistantmessage)
- [addSystemMessage](ConversationSession#addsystemmessage)
- [addToolMessage](ConversationSession#addtoolmessage)
- [addToolMessageWithId](ConversationSession#addtoolmessagewithid)
- [getMessages](ConversationSession#getmessages)
- [getMessagesByRole](ConversationSession#getmessagesbyrole)
- [getRecentMessages](ConversationSession#getrecentmessages)
- [getMessagesForAPI](ConversationSession#getmessagesforapi)
- [getMessageCount](ConversationSession#getmessagecount)
- [clear](ConversationSession#clear)

## Constructors

### constructor

• **new ConversationSession**(`maxMessages?`): [`ConversationSession`](ConversationSession)

#### Parameters

| Name           | Type     |
| :------------- | :------- |
| `maxMessages?` | `number` |

#### Returns

[`ConversationSession`](ConversationSession)

#### Defined in

agents/dist/node/index.d.ts:453

## Methods

### addMessage

▸ **addMessage**(`message`): `void`

Add any message to history

#### Parameters

| Name      | Type                                                |
| :-------- | :-------------------------------------------------- |
| `message` | [`TUniversalMessage`](../modules#tuniversalmessage) |

#### Returns

`void`

#### Implementation of

ConversationHistoryInterface.addMessage

#### Defined in

agents/dist/node/index.d.ts:457

---

### addUserMessage

▸ **addUserMessage**(`content`, `metadata?`): `void`

Add user message

#### Parameters

| Name        | Type                        |
| :---------- | :-------------------------- |
| `content`   | `string`                    |
| `metadata?` | `TUniversalMessageMetadata` |

#### Returns

`void`

#### Implementation of

ConversationHistoryInterface.addUserMessage

#### Defined in

agents/dist/node/index.d.ts:461

---

### addAssistantMessage

▸ **addAssistantMessage**(`content`, `toolCalls?`, `metadata?`): `void`

Add assistant message with optional tool calls

#### Parameters

| Name         | Type                        |
| :----------- | :-------------------------- |
| `content`    | `null` \| `string`          |
| `toolCalls?` | `IToolCall`[]               |
| `metadata?`  | `TUniversalMessageMetadata` |

#### Returns

`void`

#### Implementation of

ConversationHistoryInterface.addAssistantMessage

#### Defined in

agents/dist/node/index.d.ts:465

---

### addSystemMessage

▸ **addSystemMessage**(`content`, `metadata?`): `void`

Add system message

#### Parameters

| Name        | Type                        |
| :---------- | :-------------------------- |
| `content`   | `string`                    |
| `metadata?` | `TUniversalMessageMetadata` |

#### Returns

`void`

#### Implementation of

ConversationHistoryInterface.addSystemMessage

#### Defined in

agents/dist/node/index.d.ts:469

---

### addToolMessage

▸ **addToolMessage**(`content`, `toolCallId`, `toolName?`, `metadata?`): `void`

Add tool result message

#### Parameters

| Name         | Type                        |
| :----------- | :-------------------------- |
| `content`    | `string`                    |
| `toolCallId` | `string`                    |
| `toolName?`  | `string`                    |
| `metadata?`  | `TUniversalMessageMetadata` |

#### Returns

`void`

#### Defined in

agents/dist/node/index.d.ts:473

---

### addToolMessageWithId

▸ **addToolMessageWithId**(`content`, `toolCallId`, `toolName`, `metadata?`): `void`

Add tool execution result message with tool call ID (for tool calling format)
High-level API matching core package with duplicate prevention

Throws error if a tool message with the same toolCallId already exists.

#### Parameters

| Name         | Type                        |
| :----------- | :-------------------------- |
| `content`    | `string`                    |
| `toolCallId` | `string`                    |
| `toolName`   | `string`                    |
| `metadata?`  | `TUniversalMessageMetadata` |

#### Returns

`void`

#### Implementation of

ConversationHistoryInterface.addToolMessageWithId

#### Defined in

agents/dist/node/index.d.ts:480

---

### getMessages

▸ **getMessages**(): [`TUniversalMessage`](../modules#tuniversalmessage)[]

Get all messages in chronological order

#### Returns

[`TUniversalMessage`](../modules#tuniversalmessage)[]

#### Implementation of

ConversationHistoryInterface.getMessages

#### Defined in

agents/dist/node/index.d.ts:484

---

### getMessagesByRole

▸ **getMessagesByRole**(`role`): [`TUniversalMessage`](../modules#tuniversalmessage)[]

Get messages filtered by specific role

#### Parameters

| Name   | Type                    |
| :----- | :---------------------- |
| `role` | `TUniversalMessageRole` |

#### Returns

[`TUniversalMessage`](../modules#tuniversalmessage)[]

#### Implementation of

ConversationHistoryInterface.getMessagesByRole

#### Defined in

agents/dist/node/index.d.ts:488

---

### getRecentMessages

▸ **getRecentMessages**(`count`): [`TUniversalMessage`](../modules#tuniversalmessage)[]

Get the most recent n messages

#### Parameters

| Name    | Type     |
| :------ | :------- |
| `count` | `number` |

#### Returns

[`TUniversalMessage`](../modules#tuniversalmessage)[]

#### Implementation of

ConversationHistoryInterface.getRecentMessages

#### Defined in

agents/dist/node/index.d.ts:492

---

### getMessagesForAPI

▸ **getMessagesForAPI**(): `APIMessage`[]

Get messages formatted for API consumption

#### Returns

`APIMessage`[]

#### Defined in

agents/dist/node/index.d.ts:496

---

### getMessageCount

▸ **getMessageCount**(): `number`

Get total message count

#### Returns

`number`

#### Implementation of

ConversationHistoryInterface.getMessageCount

#### Defined in

agents/dist/node/index.d.ts:500

---

### clear

▸ **clear**(): `void`

Clear all conversation history

#### Returns

`void`

#### Implementation of

ConversationHistoryInterface.clear

#### Defined in

agents/dist/node/index.d.ts:504
