# AgentSession


```
interface AgentSession : AutoCloseable
```

<br />

*** ** * ** ***

A scoped session handle representing an ongoing multi-turn conversational thread with an `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentRunner`.

Encapsulates the `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentSession#sessionId()`, turn execution via `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentSession#runAsync(com.google.mlkit.genai.prompt.Content)`, and session history lifecycle. Closing the session evicts its in-memory dialogue history.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentSession#close()()` Closes this session handle and asynchronously evicts its in-memory dialogue history. |
| `suspend https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentSession#delete()()` Deletes this session's in-memory conversation history and cancels active turns. |
| `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentEvent>` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentSession#runAsync(com.google.mlkit.genai.prompt.Content)(content: https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/prompt/Content)` Executes an interaction turn within this session using multimodal `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/prompt/Content`. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentSession#sessionId()` The unique identifier tracking conversation history in memory for this session. |

## Public functions

### close

```
fun close(): Unit
```

Closes this session handle and asynchronously evicts its in-memory dialogue history.

Dialogue history cleanup is dispatched asynchronously in the background. If you require guaranteed synchronous eviction before immediately recreating a session with the same `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentSession#sessionId()`, invoke `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentSession#delete()` instead.

### delete

```
suspend fun delete(): Unit
```

Deletes this session's in-memory conversation history and cancels active turns.

This suspending call synchronously completes in-memory and ADK history deletion before returning. Use this when you require guaranteed immediate history eviction before recreating a session with the same `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentSession#sessionId()`.

### runAsync

```
fun runAsync(content: Content): Flow<AgentEvent>
```

Executes an interaction turn within this session using multimodal `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/prompt/Content`.

| Parameters |
|---|---|
| `content: https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/prompt/Content` | The multimodal content (text, images, etc.). |

| Returns |
|---|---|
| `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentEvent>` | A cold `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentEvent`s emitted during execution. |

## Public properties

### sessionId

```
val sessionId: String
```

The unique identifier tracking conversation history in memory for this session.