ChatSession

class ChatSession(broker: LlmBroker, model: String, systemPrompt: String? = null, tools: List<LlmTool> = emptyList(), config: CompletionConfig = CompletionConfig())

Multi-turn chat coordinator on top of an LlmBroker.

Owns the message history, an optional system prompt, and a default tool set so callers can send a single user prompt per turn without rebuilding the full message list each time. Mutable state is protected by a Mutex so the session is safe to share across coroutines.

Two surfaces mirror the broker:

  • send — suspending, single-shot turn returning the assistant text.

  • stream — cold Flow of StreamEvent; history is updated atomically once the flow completes.

The session is the Kotlin analogue of the Python reference's ChatSession.

Constructors

Link copied to clipboard
constructor(broker: LlmBroker, model: String, systemPrompt: String? = null, tools: List<LlmTool> = emptyList(), config: CompletionConfig = CompletionConfig())

Functions

Link copied to clipboard
suspend fun messages(): List<LlmMessage>

Return an immutable snapshot of the current message history.

Link copied to clipboard
suspend fun reset()

Drop all non-system messages. The system prompt (if any) is preserved.

Link copied to clipboard
suspend fun send(message: String): LlmGatewayResponse

Send a user message and return the assistant's response.

Link copied to clipboard
fun stream(message: String): Flow<StreamEvent>

Send a user message and stream the assistant's response.