Menu

1 / 2

Spring AI 2.1 Session Memory: Build a Restart-Safe Agent with JDBC

DEV Community: java·jamilxt·about 9 hours ago
#kq97fmjE
#devtojava#devto#dev#session#spring
Reading 0:00
15s threshold

A support assistant can remember the last message perfectly and still forget the customer as soon as the application restarts. That is not a model problem. It is a state-management problem.

Spring AI 2.1.0-RC1 introduces session memory as a first-party way to keep conversation events in a repository and construct the model's active context from that history. The JDBC starter makes PostgreSQL, MySQL, MariaDB, and H2 available through Spring Boot auto-configuration. The important shift is architectural: the conversation log is durable state, while the prompt is a view built for a particular model call. Spring AI's release announcement and session reference describe the feature and its modules.

This tutorial wires a ChatClient to JDBC-backed sessions, passes a session identifier on each turn, and adds turn-aware compaction so the prompt does not grow without limit.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.