ChatSession class
Manages a chat session with an LLM, including history and context
Constructors
- ChatSession({required LlmInterface llmProvider, StorageManager? storageManager, String id = '', String? title, int? maxContextTokens})
- Create a new chat session
Properties
-
assistantMessages
→ List<
LlmMessage> -
Get all assistant messages
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String
-
final
- llmProvider → LlmInterface
-
final
- messageCount → int
-
Get the number of messages in history
no setter
-
messages
→ List<
LlmMessage> -
Get current chat history
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- storageManager → StorageManager?
-
final
-
systemMessages
→ List<
LlmMessage> -
Get all system messages
no setter
- title → String?
-
final
-
toolMessages
→ List<
LlmMessage> -
Get all tool messages
no setter
-
userMessages
→ List<
LlmMessage> -
Get all user messages
no setter
Methods
-
addAssistantMessage(
String content) → void - Add an assistant message to the chat
-
addSystemMessage(
String content) → void - Add a system message to the chat
-
addToolError(
String toolName, String errorMessage, {String? toolCallId}) → void - Add tool error with structured messages
-
addToolMessage(
LlmMessage message) → void - Add a pre-built tool message to the chat
-
addToolResult(
String toolName, Map< String, dynamic> arguments, List results, {String? toolCallId}) → void - Add tool result with structured messages
-
addUserMessage(
String content) → void - Add a user message to the chat
-
clearHistory(
) → void - Clear the chat history
-
getMessagesForContext(
{int? maxTokens}) → List< LlmMessage> - Get messages formatted for LLM context
-
loadHistory(
) → Future< void> - Load chat history from storage if available
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited