This sample demonstrates session-based multi-turn chat with persistence in Genkit Java.
- Multi-turn conversations - Automatic conversation history management
- Session state - Track user preferences and conversation context
- Session persistence - Save and load sessions across interactions
- Tool integration - Using tools (note-taking) within chat sessions
- Multiple personas - Choose between assistant, tutor, and creative modes
- Java 21 or later
- Maven
- OpenAI API key
- Java 21+
- Maven 3.6+
- OpenAI API key
# Set your OpenAI API key
export OPENAI_API_KEY=your-api-key-here
# Navigate to the sample directory
cd java/samples/chat-session
# Run the sample
./run.sh
# Or: mvn compile exec:javaRun the automated demo to see all features:
cd java/samples/chat-session
mvn exec:java -Dexec.args="--demo"# Set your OpenAI API key
export OPENAI_API_KEY=your-api-key-here
# Navigate to the sample directory
cd java/samples/chat-session
# Run with Genkit CLI
genkit start -- ./run.shThe Dev UI will be available at http://localhost:4000
During interactive chat, you can use these commands:
| Command | Description |
|---|---|
/history |
Show conversation history |
/notes |
Show saved notes |
/state |
Show session state |
/topic X |
Set conversation topic to X |
/quit |
Exit the chat |
What's your name? Alice
Choose a chat persona:
1. Assistant (general help)
2. Tutor (learning & education)
3. Creative (storytelling & ideas)
Enter choice (1-3): 2
✓ Session created: a1b2c3d4-e5f6-...
✓ Persona: tutor
You: What is photosynthesis?