public class LLMChatSession extends Object
High-level chat session with history, tool-calling and optional compaction. Mutable state belongs to one owner thread. Other threads consume published LLMContextUsage snapshots rather than reading this session concurrently.
| Modifier and Type | Member | Description |
|---|---|---|
| public readonly property | contextLengthTokenscontextLengthTokens as Int |
Configured context length in tokens. |
| public readonly property | contextTokenscontextTokens as Int |
Current cached context occupancy, read in O(1) on the session owner thread. |
| public readonly property | contextUsagecontextUsage as LLMContextUsage |
Captures accounting in O(1), without reading mutable message history. |
| public readonly property | contextUsagePercentcontextUsagePercent as Int |
Last known context usage percentage, capped to 100. |
| public readonly property | lastCompactionAfterUsagelastCompactionAfterUsage as LLMContextUsage |
Estimated replacement accounting before subsequent provider calls, or null. |
| public readonly property | lastCompactionBeforeUsagelastCompactionBeforeUsage as LLMContextUsage |
Accounting immediately before the last compaction attempt, or null. |
| public readonly property | lastCompletionTokenslastCompletionTokens as Int |
Last completion token count reported by the provider. |
| public readonly property | lastPromptTokenslastPromptTokens as Int |
Last prompt token count reported by the provider. |
| public readonly property | lastTotalTokenslastTotalTokens as Int |
Last total token count reported by the provider. |
| Modifier and Type | Member | Description |
|---|---|---|
| public | LLMChatSessionLLMChatSession(provider as Object) |
Creates a session bound to one provider. |
| Modifier and Type | Member | Description |
|---|---|---|
| public | appendMessageappendMessage(message as LLMThreadMessage) as Void |
Appends and checkpoints an externally supplied message on the owner thread. |
| public | ask | Sends one user prompt and returns the final assistant answer. |
| public | askMessageaskMessage(userMessage as LLMThreadMessage) as String throws Exception |
Sends a user message with optional image and attachment references. |
| public | compactcompact() as Boolean |
Compacts the active context on demand using the configured compactor. |
| public | consumeCompactionFlagconsumeCompactionFlag() as Boolean |
Returns and clears the compaction flag. |
| public | messagesmessages() as ArrayList<LLMThreadMessage> |
Returns a typed snapshot of the active context, not the uncompacted archive. |
| public | threadthread() as ArrayList |
Returns the legacy mutable history on the session owner thread. |
| public | withCompactionObserverwithCompactionObserver(observer as LLMCompactionObserver) as LLMChatSession |
Attaches an observer notified before the context compactor starts. |
| public | withCompactionProviderwithCompactionProvider(provider as LLMProvider) as LLMChatSession |
Selects a separate transport for context summaries, keeping ordinary requests on the session provider. |
| public | withCompactorwithCompactor(strategy as String, threshold as Int) as LLMChatSession |
Configures context compaction. |
| public | withContextWindowwithContextWindow(contextLengthTokens as Int, compactAtPercent as Int = 90) as LLMChatSession |
Configures token-based context accounting. |
| public | withHistoryObserverwithHistoryObserver(observer as LLMHistoryObserver) as LLMChatSession |
Installs a synchronous history journal; null disables checkpoint callbacks. |
| public | withMaxToolCallswithMaxToolCalls(limit as Int) as LLMChatSession |
Configures the maximum number of tool calls. |
| public | withMessageswithMessages(messages as ArrayList<LLMThreadMessage>) as LLMChatSession |
Restores an existing provider history without sharing its list container. |
| public | withSystemwithSystem(systemPrompt as String) as LLMChatSession |
Sets or replaces the system prompt. |
| public | withToolCallObserverwithToolCallObserver(observer as LLMToolCallObserver) as LLMChatSession |
Attaches an observer notified around every requested tool call. |
| public | withToolswithTools(tools as ToolRegistry) as LLMChatSession |
Attaches a tool registry. |