---
title: "ChatSession"
sidebar_label: "ChatSession"
description: "Kotlin binding reference: ChatSession."
---

<!-- Generated by tools/api_reference/generate_api_docs.py. Do not edit. -->

//[clika-runtime](../../../index.md)/[io.clika.modelverse](../index.md)/[ChatSession](index.md)

# ChatSession

[common]\
class [ChatSession](index.md)

A conversation over a [GenerativeModel](../GenerativeModel/index.md): the turns so far ([messages](messages.md)), a [send](send.md) that appends the user turn and the reply, a [respond](respond.md) that replies to the turns as they stand, the tools channel ([tools](tools.md), [toolCalls](toolCalls.md), [addToolResult](addToolResult.md)) and the last reply's [report](report.md). The whole conversation goes to the model on every turn, rendered through the checkpoint's chat template; the model's cache serves the earlier turns ([GenerationReport.cachedPromptTokens](../GenerationReport/cachedPromptTokens.md)). One session speaks at a time, on the model's own worker thread; a second session over the same model waits its turn. The session owns no weights: [close](close.md) ends it and leaves the model open. Built by [GenerativeModel.chatSession](../GenerativeModel/chatSession.md).

Tools: the session's [tools](tools.md) are offered on every turn, and a turn may offer its own list instead. A reply that calls tools ends with [FinishReason.TOOL_CALLS](../FinishReason/TOOL_CALLS/index.md); its calls are [toolCalls](toolCalls.md) (and ride the assistant turn as [ChatMessage.toolCalls](../ChatMessage/toolCalls.md), each with an id, `call_<n>` when the model's format wrote none), and [addToolResult](addToolResult.md) appends a tool turn answering one, after which [respond](respond.md) continues. A model that takes no tools ([Capabilities.supportsTools](../Capabilities/supportsTools.md) false) refuses an offer before any turn is appended.

## Properties

| Name | Summary |
|---|---|
| [messages](messages.md) | [common]<br>val [messages](messages.md): [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[ChatMessage](../ChatMessage/index.md)&gt;<br>The conversation so far, the system turn first when one was given; a copy. |
| [model](model.md) | [common]<br>val [model](model.md): [GenerativeModel](../GenerativeModel/index.md)<br>The model the session speaks through. |
| [report](report.md) | [common]<br>var [report](report.md): [GenerationReport](../GenerationReport/index.md)?<br>The last reply's report; null before the first reply ends and after [reset](reset.md). |
| [toolCalls](toolCalls.md) | [common]<br>var [toolCalls](toolCalls.md): [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[ToolCall](../ToolCall/index.md)&gt;<br>The calls the last reply made, ids filled in; empty when it made none, or before the first reply. |
| [tools](tools.md) | [common]<br>val [tools](tools.md): [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[ToolDef](../ToolDef/index.md)&gt;<br>The tools every turn offers unless the turn names its own; empty offers none. |

## Functions

| Name | Summary |
|---|---|
| [addToolResult](addToolResult.md) | [common]<br>fun [addToolResult](addToolResult.md)(callId: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html), content: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html), name: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) = &quot;&quot;)<br>Append a tool's result as a tool turn answering the call [callId](addToolResult.md) (a [ToolCall.id](../ToolCall/id.md) from [toolCalls](toolCalls.md)), with the tool's [name](addToolResult.md) when given; a [respond](respond.md) then continues the conversation. |
| [close](close.md) | [common]<br>open fun [close](close.md)()<br>End the session; the model stays open, and a later [send](send.md) or [respond](respond.md) refuses. |
| [reset](reset.md) | [common]<br>fun [reset](reset.md)(keepSystem: [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) = true)<br>Forget the conversation, the last report and its calls; [keepSystem](reset.md) keeps the system turn. |
| [respond](respond.md) | [common]<br>fun [respond](respond.md)(config: [GenerationConfig](../GenerationConfig/index.md) = model.capabilities.defaults, tools: [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[ToolDef](../ToolDef/index.md)&gt;? = null): [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)<br>Reply to the conversation as it stands, blocking: the last turn must be a user turn or a tool result. The reply's visible text is appended as the assistant turn and answered.<br>[common]<br>fun [respond](respond.md)(listener: [GenerationListener](../GenerationListener/index.md), config: [GenerationConfig](../GenerationConfig/index.md) = model.capabilities.defaults, tools: [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[ToolDef](../ToolDef/index.md)&gt;? = null): [GenerationHandle](../GenerationHandle/index.md)<br>Reply to the conversation as it stands, streamed through [listener](respond.md); the assistant turn is appended when [GenerationListener.onDone](../GenerationListener/onDone.md) arrives. |
| [send](send.md) | [common]<br>fun [send](send.md)(content: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html), config: [GenerationConfig](../GenerationConfig/index.md) = model.capabilities.defaults, images: [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[ByteArray](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html)&gt; = emptyList(), tools: [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[ToolDef](../ToolDef/index.md)&gt;? = null): [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)<br>Send one user turn and block for the reply: [content](send.md) with [images](send.md) is appended, the conversation is sent under [config](send.md) (the model's defaults when omitted) with [tools](send.md) offered (the session's when null), and the reply's visible text is appended as the assistant turn and answered. A failure throws [ModelverseException](../ModelverseException/index.md) with the library's message and leaves the user turn in place, so [respond](respond.md) may try again; an offer to a model that takes no tools throws IllegalArgumentException and appends nothing.<br>[common]<br>fun [send](send.md)(content: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html), listener: [GenerationListener](../GenerationListener/index.md), config: [GenerationConfig](../GenerationConfig/index.md) = model.capabilities.defaults, images: [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[ByteArray](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html)&gt; = emptyList(), tools: [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[ToolDef](../ToolDef/index.md)&gt;? = null): [GenerationHandle](../GenerationHandle/index.md)<br>Send one user turn and stream the reply: [listener](send.md) hears the pieces on the model's worker thread ([GenerationListener](../GenerationListener/index.md)), each call the reply made through [GenerationListener.onToolCall](../GenerationListener/onToolCall.md), and the assistant turn is appended when [GenerationListener.onDone](../GenerationListener/onDone.md) arrives, with the text streamed so far on a canceled reply. The returned handle cancels. |