Package com.google.genkit.ai.session


package com.google.genkit.ai.session
Provides session management for multi-turn agent conversations with persistence.

The session package provides a stateful layer on top of Genkit's generation capabilities, enabling:

  • Persistent conversation history across multiple interactions
  • Custom session state management
  • Multiple named conversation threads within a session
  • Pluggable storage backends via SessionStore

Key Components

Example Usage

Create a session with custom state:

 Session session = genkit.createSession(SessionOptions.builder().initialState(new MyState("John")).build());

 Chat chat = session
                .chat(ChatOptions.builder().model("openai/gpt-4o").system("You are a helpful assistant.").build());

 // Multi-turn conversation (history is preserved automatically)
 chat.send("What is the capital of France?");
 chat.send("And what about Germany?");

 // Access session state
 MyState state = session.getState();

 // Load an existing session
 Session loadedSession = genkit.loadSession(sessionId, options).get();
 

Custom Session Stores

Implement SessionStore to provide custom persistence backends (e.g., database, Redis, file system).

See Also: