Spring AI 2.1 Session Memory: Build a Restart-Safe Agent with JDBC Spring AI 2.1.0-RC1 introduces first-party session memory that stores conversation events in an append-only repository and builds the model's active prompt as a view over that history, with a JDBC starter supporting PostgreSQL, MySQL, MariaDB, and H2 via Spring Boot auto-configuration. The release adds turn-aware compaction so prompts can be trimmed at turn boundaries without rewriting the underlying log, separating durable conversation state from per-call context. The feature is a release candidate, and the source notes that applications must still handle authentication and per-request session access themselves. 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 https://spring.io/blog/2026/10/23/spring-ai-2-1-0-RC1-available-now/ and session reference https://docs.spring.io/spring-ai/reference/2.1/api/session.html 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. It also covers the deployment and migration details that are easy to miss. Disclosure: This source-based tutorial draws on the Spring AI 2.1 reference and release notes. It does not document a production deployment, and the sample has not been validated against a live database. Spring AI 2.1.0-RC1 is a release candidate, so check the official project status before choosing it for a production system. A conventional chat-memory abstraction stores a list of messages under a conversation ID. That can be enough for a short exchange, but it gives you less structure when a conversation includes tool calls, long histories, or future workflow state. Spring AI's session model stores events in an append-only log. A session is the conversation's identity and metadata; events contain what happened. When the model needs context, the application reads a view of that event log. Compaction can change the active view without rewriting or deleting the original history. The session documentation describes turn-aware compaction: it works at turn boundaries so the model is not shown a tool call without its result or an answer without the question that led to it. The concepts guide explains sessions, events, turns, and views https://docs.spring.io/spring-ai/reference/2.1/api/session/concepts.html . That separation is useful, but it does not mean the framework decides who is allowed to read a session. Your application still has to authenticate the caller, associate the session with the right principal, and enforce access on every request. Use the Spring AI 2.1.0-RC1 dependency set through the project's Spring AI BOM, and include the session JDBC starter. The release candidate's documented starter is: