# AgentSession


```
public interface AgentSession extends AutoCloseable
```

<br />

*** ** * ** ***

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

Encapsulates the `https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentSession#sessionId()`, turn execution via `https://developers.google.com/android/reference/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 methods |
|---|---|
| `abstract void` | `https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentSession#close()()` Closes this session handle and asynchronously evicts its in-memory dialogue history. |
| `abstract void` | `https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentSession#delete()()` Deletes this session's in-memory conversation history and cancels active turns. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentSession#getSessionId()()` The unique identifier tracking conversation history in memory for this session. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentEvent>` | `https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentSession#runAsync(com.google.mlkit.genai.prompt.Content)(@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/Content content)` Executes an interaction turn within this session using multimodal `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/Content`. |

## Public methods

### close

```
abstract void close()
```

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/com/google/mlkit/genai/agent/AgentSession#sessionId()`, invoke `https://developers.google.com/android/reference/com/google/mlkit/genai/agent/AgentSession#delete()` instead.

### delete

```
abstract void delete()
```

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/com/google/mlkit/genai/agent/AgentSession#sessionId()`.

### getSessionId

```
abstract @NonNull String getSessionId()
```

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

### runAsync

```
abstract @NonNull Flow<@NonNull AgentEvent> runAsync(@NonNull Content content)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/Content content` | The multimodal content (text, images, etc.). |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/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/com/google/mlkit/genai/agent/AgentEvent`s emitted during execution. |