agents / Exports / 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
Methods
- addMessage
- addUserMessage
- addAssistantMessage
- addSystemMessage
- addToolMessage
- addToolMessageWithId
- getMessages
- getMessagesByRole
- getRecentMessages
- getMessagesForAPI
- getMessageCount
- clear
Constructors
constructor
• new ConversationSession(maxMessages?): ConversationSession
Parameters
| Name | Type | Default value |
|---|---|---|
maxMessages | number | 100 |
Returns
Defined in
packages/agents/src/managers/conversation-history-manager.ts:700
Methods
addMessage
▸ addMessage(message): void
Add any message to history
Parameters
| Name | Type |
|---|---|
message | UniversalMessage |
Returns
void
Implementation of
ConversationHistoryInterface.addMessage
Defined in
packages/agents/src/managers/conversation-history-manager.ts:707
addUserMessage
▸ addUserMessage(content, metadata?): void
Add user message
Parameters
| Name | Type |
|---|---|
content | string |
metadata? | ConversationMessageMetadata |
Returns
void
Implementation of
ConversationHistoryInterface.addUserMessage
Defined in
packages/agents/src/managers/conversation-history-manager.ts:714
addAssistantMessage
▸ addAssistantMessage(content, toolCalls?, metadata?): void
Add assistant message with optional tool calls
Parameters
| Name | Type |
|---|---|
content | null | string |
toolCalls? | { id: string ; type: "function" ; function: { name: string ; arguments: string } }[] |
metadata? | ConversationMessageMetadata |
Returns
void
Implementation of
ConversationHistoryInterface.addAssistantMessage
Defined in
packages/agents/src/managers/conversation-history-manager.ts:721
addSystemMessage
▸ addSystemMessage(content, metadata?): void
Add system message
Parameters
| Name | Type |
|---|---|
content | string |
metadata? | ConversationMessageMetadata |
Returns
void
Implementation of
ConversationHistoryInterface.addSystemMessage
Defined in
packages/agents/src/managers/conversation-history-manager.ts:736
addToolMessage
▸ addToolMessage(content, toolCallId, toolName?, metadata?): void
Add tool result message
Parameters
| Name | Type |
|---|---|
content | string |
toolCallId | string |
toolName? | string |
metadata? | ConversationMessageMetadata |
Returns
void
Defined in
packages/agents/src/managers/conversation-history-manager.ts:743
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? | ConversationMessageMetadata |
Returns
void
Implementation of
ConversationHistoryInterface.addToolMessageWithId
Defined in
packages/agents/src/managers/conversation-history-manager.ts:753
getMessages
▸ getMessages(): UniversalMessage[]
Get all messages in chronological order
Returns
Implementation of
ConversationHistoryInterface.getMessages
Defined in
packages/agents/src/managers/conversation-history-manager.ts:770
getMessagesByRole
▸ getMessagesByRole(role): UniversalMessage[]
Get messages filtered by specific role
Parameters
| Name | Type |
|---|---|
role | UniversalMessageRole |
Returns
Implementation of
ConversationHistoryInterface.getMessagesByRole
Defined in
packages/agents/src/managers/conversation-history-manager.ts:777
getRecentMessages
▸ getRecentMessages(count): UniversalMessage[]
Get the most recent n messages
Parameters
| Name | Type |
|---|---|
count | number |
Returns
Implementation of
ConversationHistoryInterface.getRecentMessages
Defined in
packages/agents/src/managers/conversation-history-manager.ts:784
getMessagesForAPI
▸ getMessagesForAPI(): APIMessage[]
Get messages formatted for API consumption
Returns
APIMessage[]
Defined in
packages/agents/src/managers/conversation-history-manager.ts:791
getMessageCount
▸ getMessageCount(): number
Get total message count
Returns
number
Implementation of
ConversationHistoryInterface.getMessageCount
Defined in
packages/agents/src/managers/conversation-history-manager.ts:813
clear
▸ clear(): void
Clear all conversation history
Returns
void
Implementation of
ConversationHistoryInterface.clear
Defined in
packages/agents/src/managers/conversation-history-manager.ts:820