惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
Google DeepMind News
Google DeepMind News
Hugging Face - Blog
Hugging Face - Blog
D
Docker
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
Project Zero
Project Zero
Engineering at Meta
Engineering at Meta
J
Java Code Geeks
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Simon Willison's Weblog
Simon Willison's Weblog
S
Security Affairs
NISL@THU
NISL@THU
T
Tor Project blog
A
About on SuperTechFans
宝玉的分享
宝玉的分享
腾讯CDC
S
Schneier on Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Privacy & Cybersecurity Law Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
P
Privacy International News Feed
雷峰网
雷峰网
C
Cyber Attacks, Cyber Crime and Cyber Security
Vercel News
Vercel News
Cisco Talos Blog
Cisco Talos Blog
D
DataBreaches.Net
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Google Online Security Blog
Google Online Security Blog
Recorded Future
Recorded Future
L
LINUX DO - 热门话题
Microsoft Security Blog
Microsoft Security Blog
Latest news
Latest news
C
Check Point Blog
有赞技术团队
有赞技术团队
T
The Exploit Database - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
云风的 BLOG
云风的 BLOG
SecWiki News
SecWiki News
Application and Cybersecurity Blog
Application and Cybersecurity Blog
爱范儿
爱范儿
月光博客
月光博客
V
Vulnerabilities – Threatpost
T
Threat Research - Cisco Blogs
P
Palo Alto Networks Blog
T
The Blog of Author Tim Ferriss
C
Cisco Blogs
Webroot Blog
Webroot Blog
S
Security @ Cisco Blogs

Spring

This Week in Spring - July 14th, 2026 Spring Office Hours Podcast: S5E18 - The Latest from OpenAI, Anthropic and Spring AI 2.0 A Bootiful Podcast: Spring Boot legend Moritz Halbritter on the latest and greatest in Spring Boot 4 and 4.1 This Week in Spring - July 7th, 2026 A New Home for Spring Cloud Contract: Transitioning to Stubborn.sh Spring Office Hours Podcast: S5E17 - Spring Boot 4.1 with Phil Webb A Bootiful Podcast: Sébastien Deleuze on the latest-and-greatest in Spring AI and Spring Framework This Week in Spring - June 30th, 2026 A Bootiful Podcast: My friend Francesco Ciulla on developer advocacy and more Spring Boot 3.5.16 available now Spring Data 2025.0.13 released This Week in Spring - June 23rd, 2026 Self-Correcting Structured Output in Spring AI 2.0 MongoDB-backed Spring Batch jobs and more in Spring Boot 4.1 A Bootiful Podcast: DaShaun Carter on patching, Spring Boot 4.1, and security in the world of AI This Week in Spring - June 16th, 2026 Spring Tools 5.2.0 released Tool Calling in Spring AI 2.0: A Composable, Agentic Architecture Spring AI 1.0.9, 1.1.8 Available Now Spring AI 2.0.0 GA Available Now A Bootiful Podcast: Spring Security lead Rob Winch answers some security questions for me Spring Modulith 2.1 GA, 2.0.7, and 1.4.12 released Spring Shell 4.0.3 and 3.4.3 are out! Spring Cloud 2025.0.3 (aka Northfields) Has Been Released Spring Cloud 2025.1.2 (aka Oakwood) Has Been Released Spring for GraphQL 1.4.6 and 2.0.4 released Spring gRPC 1.1.0 available now Spring Vault 4.0.3 and 3.2.1 available Spring Vault 4.1 Generally Available Spring Batch 6.0.4 and 5.2.6 available now Spring Boot 3.5.15 available now Spring AI 2.0.0-RC1 Available Now A Bootiful Podcast: JetBrains' Marit van Dijk This Week in Spring - June 2nd, 2026 Spring and Security In The Times Of AI A Bootiful Podcast: Microsoft's Martijn Verburg Spring AI 2.0.0-M8 Available Now This Week in Spring - May 26th, 2026 Spring AI 1.0.8, 1.1.7, 2.0.0-M7 Available Now A Bootiful Podcast: Hadi Hariri, Jetbrains legend This Week in Spring - May 19th, 2026 Spring Office Hours Podcast: S5E16 - May Release Train Shift & What's Coming in Spring Boot 4.1 A Bootiful Podcast: the legendary Adib Saikali This Week in Spring - May 12th, 2026 May Release Train Date Changes Spring Office Hours Podcast: S5E15 - Upgrading Spring and OSS Security Spring AI 1.0.7, 1.1.6, 2.0.0-M6 Available Now Spring Cloud Function and Config Have Been Released To Address Several CVEs A Bootiful Podcast: Daniel Garnier-Moiroux on his new book 'Testing Spring Boot Applications' This Week in Spring - May 5th, 2026 Spring Office Hours Podcast: S5E14 - Spec Driven Development with Simon Martinelli Ronald Dehuysser, founder of JobRunr, on their ambitious new JavaClaw-like agent runtime This Week in Spring - April 28th, 2026 Spring AI 1.0.6, 1.1.5, 2.0.0-M5 Available Now Spring Modulith 2.1 RC1, 2.0.6, and 1.4.11 released Spring Shell 4.0.2 is out! A Bootiful Podcast: A Bootiful Podcast: Dr. Venkat Subramaniam and James Ward on Intelligent Kotlin and So Much More Spring Boot 3.5.14 available now Spring Boot 4.0.6 available now Spring Boot 4.1.0-RC1 available now Spring for Apache Kafka 4.1.0-RC1, 4.0.5, and 3.3.15 Available Spring for Apache Pulsar 1.2.17 and 2.0.5 are now available This Week in Spring - April 21st, 2026 Spring Authorization Server 1.5.7 Available Now Spring Security 2026.04 Releases - Contains CVE Fixes Spring Integration 7.1.0-RC1 Available Spring Vault 4.1.0-RC1 and 4.0.2 released Spring Data 2026.0.0-RC1 enters release candidate phase Spring Data 2025.1.5 and 2025.0.11 released Spring Framework 6.2.18 and 7.0.7 Available Now A Bootiful Podcast: the legendary Craig Walls This Week in Spring - April 14th, 2026 Catch the Spring Team at Spring I/O 2026! A Bootiful Podcast: Mark Kropf on AI orchestration Spring Office Hours Podcast: S5E12 - Developer Soft Skills with Arun Gupta Spring AI Agentic Patterns (Part 6): AutoMemoryTools — Persistent Agent Memory Across Sessions
Spring AI Agentic Patterns (Part 7): Session API — Event-Sourced Short-Term Memory with Context Compaction
2026-04-15 · via Spring

A New Session API for Spring AI — Structured, Compactable, Multi-Agent-Ready

Part 7 of the Spring AI Agentic Patterns series completes the memory picture. After covering Agent Skills, AskUserQuestionTool, TodoWriteTool, Subagent Orchestration, A2A Integration, and AutoMemoryTools for long-term cross-session memory, we now add the complementary short-term layer: Spring AI Session. Storing conversation history as a flat message list works for short exchanges but breaks down as sessions grow — naive truncation silently discards tool-call sequences mid-exchange, leaving the model with orphaned results and broken turn structure. Spring AI Session solves this by automatically recording every message, tool call, and result for the active exchange and managing the context window intelligently, while AutoMemoryTools retains curated facts that must survive beyond the session. A complete agent memory stack needs both; neither replaces the other.

Roadmap: Incubating in spring-ai-community; targets Spring AI 2.1 (November 2026), when ChatMemory will be deprecated in its favour.

ChatMemory evicts the oldest messages with no turn safety, no event identity, no multi-agent support, and no record of what was discarded. Spring AI Session replaces it with an event-sourced log, pluggable compaction strategies, branch isolation, and keyword-searchable recall storage.

🚀 Want to jump right in? Skip to the Getting Started section.


Session API Architecture

Spring AI Session API Classes

Session and SessionEvent

Session is an immutable metadata-only value object — it holds the session ID, user ID, TTL, and arbitrary metadata. The event log lives separately in the repository, fetched on demand.

SessionEvent wraps a Spring AI Message and adds what Message intentionally omits: a UUID, sessionId, timestamp, an optional branch label for multi-agent hierarchies, and framework flags like METADATA_SYNTHETIC.

SessionService service = new DefaultSessionService(InMemorySessionRepository.builder().build());

Session session = service.create(
    CreateSessionRequest.builder().userId("alice").build()
);

service.appendMessage(session.id(), new UserMessage("What is Spring AI?"));
service.appendMessage(session.id(), new AssistantMessage("Spring AI is..."));

List<Message> history = service.getMessages(session.id()); // ready to pass to an LLM

Turns

A turn is the atomic unit of conversation: one UserMessage plus all following events — assistant replies, tool calls, tool results — up to the next UserMessage. All compaction strategies operate at turn granularity, so the kept window always starts on a USER message. The model never sees an orphaned tool result or a split exchange.

Turn 1: [USER "What is Spring AI?"]  [ASSISTANT "Spring AI is..."]
Turn 2: [USER "Can it use tools?"]   [ASSISTANT (tool call)]  [TOOL result]  [ASSISTANT "Yes,..."]

Context Compaction

Compaction reduces the event history to fit the context window while preserving coherence. It is driven by two composable abstractions: triggers and strategies.

Triggers

new TurnCountTrigger(20);                                   // fires when > 20 turns
TokenCountTrigger.builder().threshold(4000).build();        // fires at 4000 estimated tokens

// OR-composite — fires if either condition is met
CompositeCompactionTrigger.anyOf(
    new TurnCountTrigger(20),
    TokenCountTrigger.builder().threshold(4000).build()
);

Strategies

Strategy LLM call? Best for
SlidingWindowCompactionStrategy No Cost-sensitive, short-term context
TurnWindowCompactionStrategy No Turn-structured dialogues
TokenCountCompactionStrategy No Hard context-window limits
RecursiveSummarizationCompactionStrategy Yes Long-running, context-rich sessions

The first three keep a verbatim suffix of events (by message count, turn count, or token budget). All three snap the cut point to the nearest turn boundary — no partial turns are ever kept.

Recursive Summarization is the most powerful: it uses an LLM to summarize the events being archived and stores the result as a synthetic user + assistant turn. Each subsequent compaction pass builds on prior summaries — creating a rolling compressed history that never starts from scratch:

RecursiveSummarizationCompactionStrategy.builder(chatClient)
    .maxEventsToKeep(10)
    .overlapSize(2)   // feed 2 events from the active window into the summary prompt
    .build();

Note: Trigger and strategy must always be configured together — setting one without the other throws IllegalArgumentException at build time. Either set both via .compactionTrigger(...) and .compactionStrategy(...), or omit both to disable compaction entirely.


ChatClient Integration

SessionMemoryAdvisor wires session management into the ChatClient pipeline transparently. On every request it loads history, prepends it to the prompt, appends the new user and assistant messages, and runs compaction if a trigger fires — all without any manual code in the application.

@Bean
SessionMemoryAdvisor sessionMemoryAdvisor(SessionService sessionService,
        ChatClient.Builder chatClientBuilder) {

    return SessionMemoryAdvisor.builder(sessionService)
        .defaultUserId("alice")
        .compactionTrigger(new TurnCountTrigger(20))
        .compactionStrategy(
            RecursiveSummarizationCompactionStrategy.builder(chatClientBuilder.build())
                .maxEventsToKeep(10)
                .build()
        )
        .build();
}

@Bean
ChatClient chatClient(ChatClient.Builder chatClientBuilder, SessionMemoryAdvisor advisor) {
    return chatClientBuilder.defaultAdvisors(advisor).build();
}

Pass a session ID at call time via the advisor context:

String response = chatClient.prompt()
    .user("Hello!")
    .advisors(a -> a.param(SessionMemoryAdvisor.SESSION_ID_CONTEXT_KEY, "session-abc"))
    .call()
    .content();

If no session exists for the given ID, the advisor creates one automatically.


Multi-Agent Branch Isolation

When an orchestrator fans out to parallel sub-agents, all agents can share the same Session — but each must see only its own events plus its ancestors'. SessionEvent.branch is a dot-separated path that records the producing agent's position in the hierarchy:

orchestrator        branch = "orch"
├── researcher      branch = "orch.researcher"
└── writer          branch = "orch.writer"

Events with branch = null are root-level — visible to every agent. Pass EventFilter.forBranch() to apply isolation automatically inside the advisor:

// Researcher sees: null-branch + "orch" + own "orch.researcher" events
// Hidden: "orch.writer" (sibling)
SessionMemoryAdvisor researcherAdvisor = SessionMemoryAdvisor.builder(sessionService)
    .defaultSessionId(sharedSessionId)
    .eventFilter(EventFilter.forBranch("orch.researcher"))
    .build();

Synthetic summary events from RecursiveSummarizationCompactionStrategy always carry branch = null, so compaction summaries remain visible to every agent in the session.


Recall Storage

Compaction improves prompt efficiency, but older events are removed from the active context window. SessionEventTools implements the MemGPT Recall Storage pattern: the full verbatim event log is always retained and searchable by keyword, even after compaction has pruned it from the prompt.

ChatClient client = ChatClient.builder(chatModel)
    .defaultTools(SessionEventTools.builder(sessionService).build())
    .defaultAdvisors(advisor)
    .build();

The conversation_search tool is auto-discovered by Spring AI. When the model needs to recall a prior exchange it calls the tool with a keyword and an optional page index; results come back as chronologically ordered JSON. Synthetic summary events are searchable too — their text is indexed in the recall store.


JDBC Persistence

spring-ai-session-jdbc stores session data in two tables (AI_SESSION and AI_SESSION_EVENT, an append-only event log) with support for PostgreSQL, MySQL, MariaDB, and H2. The Spring Boot starter auto-configures everything:

<dependency>
    <groupId>org.springaicommunity</groupId>
    <artifactId>spring-ai-starter-session-jdbc</artifactId>
</dependency>

For PostgreSQL or MySQL, enable schema initialisation:

spring:
  ai:
    session:
      repository:
        jdbc:
          initialize-schema: always

No additional bean declarations are required.


Getting Started

Requirements: Java 17+, Spring AI 2.0.0-M4+, Spring Boot 4.0.2+

1. Import the BOM:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springaicommunity</groupId>
            <artifactId>spring-ai-session-bom</artifactId>
            <version>0.2.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

2. Add a starter — JDBC for production, or spring-ai-session-management alone for in-memory development:

<dependency>
    <groupId>org.springaicommunity</groupId>
    <artifactId>spring-ai-starter-session-jdbc</artifactId>
</dependency>

3. Wire the advisor and use it:

@Bean
SessionMemoryAdvisor sessionMemoryAdvisor(SessionService sessionService) {
    return SessionMemoryAdvisor.builder(sessionService)
        .defaultUserId("alice")
        .compactionTrigger(new TurnCountTrigger(20))
        .compactionStrategy(SlidingWindowCompactionStrategy.builder().maxEvents(10).build())
        .build();
}

@Bean
ChatClient chatClient(ChatModel chatModel, SessionMemoryAdvisor advisor) {
    return ChatClient.builder(chatModel).defaultAdvisors(advisor).build();
}
Session session = sessionService.create(
    CreateSessionRequest.builder().userId("alice").build()
);

String response = chatClient.prompt()
    .user("What is Spring AI?")
    .advisors(a -> a.param(SessionMemoryAdvisor.SESSION_ID_CONTEXT_KEY, session.id()))
    .call()
    .content();

From ChatMemory to Session API

The Session API is designed to replace ChatMemory as Spring AI's primary conversation persistence abstraction:

ChatMemory Spring AI Session
Storage unit Message (flat list) SessionEvent (immutable, timestamped, identified)
Compaction Evict oldest messages Four pluggable strategies incl. LLM summarization
Turn safety Not enforced All strategies snap to turn boundaries
Multi-agent Not supported Branch isolation with dot-separated labels
Recall search Not available conversation_search tool via SessionEventTools
Concurrency Implementation-dependent Optimistic CAS write in all implementations

The equivalent of MessageWindowChatMemory.builder().maxMessages(20).build() is:

SessionMemoryAdvisor.builder(sessionService)
    .compactionTrigger(new TurnCountTrigger(20))
    .compactionStrategy(SlidingWindowCompactionStrategy.builder().maxEvents(20).build())
    .build();

Conclusion

Spring AI Session brings a structured, event-sourced short-term memory layer to the Spring AI ecosystem — with turn-safe compaction, LLM-powered summarization, multi-agent branch isolation, and keyword-searchable recall storage. Paired with AutoMemoryTools from Part 6, you now have both halves of a complete agent memory stack: a durable long-term layer for facts that outlive the session, and a coherent short-term layer for the active conversation. The library is available from the spring-ai-community organization.


Resources

Agentic Patterns Series