This is an automated email from the ASF dual-hosted git repository.
Croway pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new a903aeea7b48 CAMEL-27243: camel-spring-ai-chat - session memory with
the sessionService option, and deprecate chatMemory (#30449)
a903aeea7b48 is described below
commit a903aeea7b487314807c9abec262dd7059164e8f
Author: Federico Mariani <[email protected]>
AuthorDate: Thu Nov 19 21:45:41 2026 +0100
CAMEL-27243: camel-spring-ai-chat - session memory with the sessionService
option, and deprecate chatMemory (#30449)
* CAMEL-27243: camel-spring-ai-chat - session memory with the
sessionService option, and deprecate chatMemory
Spring AI 2.1 deprecates ChatMemory and MessageChatMemoryAdvisor for
removal in 3.0, in favour of session memory. The
new sessionService option (autowired) uses SessionAdvisors, and the
CamelSpringAiChatConversationId header selects the
session, created on first use. Without the header no memory is used, as
with chatMemory. sessionService wins over
chatMemory and chatMemoryVectorStore. The chatMemory option is deprecated
and keeps working.
The new sessionMessageWindow option (default 20, as
MessageWindowChatMemory; 0 sends the whole session) sends only the
newest messages of the session to the model, extended to whole turns, so a
tool call never arrives without its result.
The session keeps every message.
When the header is set, the conversation id is passed to every memory
advisor, also to those of the advisors option
or of a configured chatClient, so the session advisors of the application
(for example with compaction) get it. When
the advisors option has a memory advisor, the endpoint adds no memory
advisor of its own.
* CAMEL-27243: camel-spring-ai-chat - document the session id, the
retention of sessions and a chatClient with its own memory advisor
- Session advisors passed with the advisors option need the
CamelSpringAiChatConversationId header: without it they
fail the exchange (a MessageChatMemoryAdvisor uses a default id).
- The conversation id should come from an authenticated identity, as a
session is created for any id.
- A session keeps every event; expired sessions (60 days by default) are
only removed by
SessionService.deleteExpiredSessions, with a timer route example.
- A configured chatClient with its own memory advisor still gets the memory
advisor of the endpoint when a
SessionService or ChatMemory bean is autowired (docs and upgrade guide).
- The advisors option and the CamelSpringAiChatConversationId header
descriptions describe session memory.
---
.../camel/catalog/components/spring-ai-chat.json | 44 +--
.../catalog/docs/spring-ai-chat-component.adoc | 85 ++++-
.../camel-spring-ai/camel-spring-ai-chat/pom.xml | 10 +
.../chat/SpringAiChatEndpointConfigurer.java | 14 +-
.../chat/SpringAiChatEndpointUriFactory.java | 4 +-
.../component/springai/chat/spring-ai-chat.json | 44 +--
.../src/main/docs/spring-ai-chat-component.adoc | 85 ++++-
.../springai/chat/SpringAiChatConfiguration.java | 63 +++-
.../springai/chat/SpringAiChatConstants.java | 5 +-
.../springai/chat/SpringAiChatProducer.java | 126 +++++--
.../chat/SpringAiChatSessionMemoryTest.java | 377 +++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 27 ++
.../dsl/SpringAiChatEndpointBuilderFactory.java | 112 +++++-
13 files changed, 890 insertions(+), 106 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/spring-ai-chat.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/spring-ai-chat.json
index 8b2a68611224..baffc7aea766 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/spring-ai-chat.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/spring-ai-chat.json
@@ -53,7 +53,7 @@
"CamelSpringAiChatEntityClass": { "index": 21, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "Class<?>", "deprecated": false, "autowired": false, "secret":
false, "description": "The Java class to use for entity response conversion",
"constantName":
"org.apache.camel.component.springai.chat.SpringAiChatConstants#ENTITY_CLASS" },
"CamelSpringAiChatUserMetadata": { "index": 22, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "java.util.Map<String, Object>", "deprecated": false, "autowired":
false, "secret": false, "description": "Metadata to attach to user messages",
"constantName":
"org.apache.camel.component.springai.chat.SpringAiChatConstants#USER_METADATA"
},
"CamelSpringAiChatSystemMetadata": { "index": 23, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "java.util.Map<String, Object>", "deprecated": false, "autowired":
false, "secret": false, "description": "Metadata to attach to system messages",
"constantName":
"org.apache.camel.component.springai.chat.SpringAiChatConstants#SYSTEM_METADATA"
},
- "CamelSpringAiChatConversationId": { "index": 24, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "String", "deprecated": false, "autowired": false, "secret": false,
"description": "Conversation ID for managing separate conversation contexts in
chat memory", "constantName":
"org.apache.camel.component.springai.chat.SpringAiChatConstants#CONVERSATION_ID"
},
+ "CamelSpringAiChatConversationId": { "index": 24, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "String", "deprecated": false, "autowired": false, "secret": false,
"description": "The conversation ID. It selects the session (sessionService) or
the conversation (chatMemory, chatMemoryVectorStore), and is passed to every
memory advisor, also to those of the advisors option or of a configured
chatClient. Session advisors require it [...]
"CamelSpringAiChatMaxFileSize": { "index": 25, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "Long", "deprecated": false, "autowired": false, "secret": false,
"description": "Maximum file size in bytes for multimodal content. Overrides
endpoint configuration.", "constantName":
"org.apache.camel.component.springai.chat.SpringAiChatConstants#MAX_FILE_SIZE"
},
"CamelSpringAiChatFinishReason": { "index": 26, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "String", "deprecated": false, "autowired": false, "secret": false,
"description": "The reason why the chat response generation stopped (e.g.,
STOP, LENGTH, TOOL_CALLS)", "constantName":
"org.apache.camel.component.springai.chat.SpringAiChatConstants#FINISH_REASON"
},
"CamelSpringAiChatFinishReasonCategory": { "index": 27, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "String", "enum": [ "COMPLETED", "TRUNCATED", "TOOL_CALL",
"FILTERED", "OTHER", "UNSPECIFIED" ], "deprecated": false, "autowired": false,
"secret": false, "description": "The category of the finish reason, the same
for every provider: COMPLETED, TRUNCATED (a token or length limit), TOOL_CALL,
FILTERED (a content filter, or a ref [...]
@@ -82,9 +82,9 @@
"toolSearchStrategy": { "index": 10, "kind": "parameter", "displayName":
"Tool Search Strategy", "group": "producer", "label": "producer", "required":
false, "type": "enum", "javaType":
"org.apache.camel.component.ai.tool.AiToolSearchStrategy", "enum": [ "KEYWORD",
"VECTOR" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "KEYWORD", "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configurat [...]
"userMessage": { "index": 11, "kind": "parameter", "displayName": "User
Message", "group": "producer", "label": "", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Default user message
text for multimodal requests. Can be combined with media data in the message
[...]
"lazyStartProducer": { "index": 12, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produ [...]
- "advisors": { "index": 13, "kind": "parameter", "displayName": "Advisors",
"group": "advanced", "label": "advanced", "required": false, "type": "array",
"javaType":
"java.util.List<org.springframework.ai.chat.client.advisor.api.Advisor>",
"deprecated": false, "autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "List of custom advisors
to add to the ChatCl [...]
- "chatMemory": { "index": 14, "kind": "parameter", "displayName": "Chat
Memory", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "org.springframework.ai.chat.memory.ChatMemory",
"deprecated": false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "ChatMemory instance for
maintaining conversation history across [...]
- "chatMemoryVectorStore": { "index": 15, "kind": "parameter",
"displayName": "Chat Memory Vector Store", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"org.springframework.ai.vectorstore.VectorStore", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "VectorStore instance for
maintaining c [...]
+ "advisors": { "index": 13, "kind": "parameter", "displayName": "Advisors",
"group": "advanced", "label": "advanced", "required": false, "type": "array",
"javaType":
"java.util.List<org.springframework.ai.chat.client.advisor.api.Advisor>",
"deprecated": false, "autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "List of custom advisors
to add to the ChatCl [...]
+ "chatMemory": { "index": 14, "kind": "parameter", "displayName": "Chat
Memory", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "org.springframework.ai.chat.memory.ChatMemory",
"deprecated": true, "deprecationNote": "Spring AI 2.1 deprecates ChatMemory for
removal in Spring AI 3.0. Use sessionService.", "autowired": true, "secret":
false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurati [...]
+ "chatMemoryVectorStore": { "index": 15, "kind": "parameter",
"displayName": "Chat Memory Vector Store", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"org.springframework.ai.vectorstore.VectorStore", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "VectorStore instance for
maintaining c [...]
"entityClass": { "index": 16, "kind": "parameter", "displayName": "Entity
Class", "group": "advanced", "label": "advanced", "required": false, "type":
"string", "javaType": "java.lang.Class<java.lang.Object>", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "The Java class to use
for entity response conversion using ChatClient.ent [...]
"maxFileSize": { "index": 17, "kind": "parameter", "displayName": "Max
File Size", "group": "advanced", "label": "advanced", "required": false,
"type": "integer", "javaType": "long", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 1048576, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Maximum file size in
bytes for multimodal content (images, audio, PDFs, etc [...]
"maxTokens": { "index": 18, "kind": "parameter", "displayName": "Max
Tokens", "group": "advanced", "label": "advanced", "required": false, "type":
"integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired":
false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Maximum tokens in the
response." },
@@ -92,22 +92,24 @@
"mcpTimeout": { "index": 20, "kind": "parameter", "displayName": "Mcp
Timeout", "group": "advanced", "label": "advanced", "required": false, "type":
"integer", "javaType": "int", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 20, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Timeout in seconds for
MCP operations including tool execution and initialization" },
"outputClass": { "index": 21, "kind": "parameter", "displayName": "Output
Class", "group": "advanced", "label": "advanced", "required": false, "type":
"string", "javaType": "java.lang.Class<java.lang.Object>", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "The Java class to use
for BEAN output format conversion. Required when ou [...]
"outputFormat": { "index": 22, "kind": "parameter", "displayName": "Output
Format", "group": "advanced", "label": "advanced", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "The output format for
structured output conversion (BEAN, MAP, LIST). Used in conjunctio [...]
- "structuredOutputConverter": { "index": 23, "kind": "parameter",
"displayName": "Structured Output Converter", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"org.springframework.ai.converter.StructuredOutputConverter<java.lang.Object>",
"deprecated": false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "A [...]
- "structuredOutputValidation": { "index": 24, "kind": "parameter",
"displayName": "Structured Output Validation", "group": "advanced", "label":
"advanced", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue":
false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Enable structured output
validation with aut [...]
- "structuredOutputValidationMaxAttempts": { "index": 25, "kind":
"parameter", "displayName": "Structured Output Validation Max Attempts",
"group": "advanced", "label": "advanced", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": 3, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Maximum number of retry
atte [...]
- "systemMetadata": { "index": 26, "kind": "parameter", "displayName":
"System Metadata", "group": "advanced", "label": "advanced", "required": false,
"type": "object", "javaType": "java.util.Map<java.lang.String,
java.lang.Object>", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Metadata to attach to
system messages. This metadat [...]
- "temperature": { "index": 27, "kind": "parameter", "displayName":
"Temperature", "group": "advanced", "label": "advanced", "required": false,
"type": "number", "javaType": "java.lang.Double", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Temperature parameter
for response randomness (0.0-2.0)." },
- "toolCallbacks": { "index": 28, "kind": "parameter", "displayName": "Tool
Callbacks", "group": "advanced", "label": "advanced", "required": false,
"type": "array", "javaType":
"java.util.List<org.springframework.ai.tool.ToolCallback>", "deprecated":
false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "List of ToolCallback
instances to register along [...]
- "toolContext": { "index": 29, "kind": "parameter", "displayName": "Tool
Context", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>",
"deprecated": false, "autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Context map to pass to
tools during execution. Tool metho [...]
- "topKSampling": { "index": 30, "kind": "parameter", "displayName": "Top
KSampling", "group": "advanced", "label": "advanced", "required": false,
"type": "integer", "javaType": "java.lang.Integer", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Top K parameter for
sampling." },
- "topP": { "index": 31, "kind": "parameter", "displayName": "Top P",
"group": "advanced", "label": "advanced", "required": false, "type": "number",
"javaType": "java.lang.Double", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Top P parameter for
nucleus sampling." },
- "userMetadata": { "index": 32, "kind": "parameter", "displayName": "User
Metadata", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>",
"deprecated": false, "autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Metadata to attach to
user messages. This metadata can [...]
- "ragTemplate": { "index": 33, "kind": "parameter", "displayName": "Rag
Template", "group": "rag", "label": "rag", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "Context:\\n\\{context}\\n\\nQuestion:
\\{question}", "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Template for formatting
RAG (R [...]
- "similarityThreshold": { "index": 34, "kind": "parameter", "displayName":
"Similarity Threshold", "group": "rag", "label": "rag", "required": false,
"type": "number", "javaType": "double", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": 0.7, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Similarity threshold for
RAG retrieval (default: 0.7)." },
- "topK": { "index": 35, "kind": "parameter", "displayName": "Top K",
"group": "rag", "label": "rag", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": 5, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Number of top documents
to retrieve for RAG (default: 5)." },
- "vectorStore": { "index": 36, "kind": "parameter", "displayName": "Vector
Store", "group": "rag", "label": "rag", "required": false, "type": "object",
"javaType": "org.springframework.ai.vectorstore.VectorStore", "deprecated":
false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "VectorStore for
automatic RAG retrieval." },
- "safeguardFailureResponse": { "index": 37, "kind": "parameter",
"displayName": "Safeguard Failure Response", "group": "security", "label":
"security", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Failure response message
for SafeGuard advisor when sensitive c [...]
- "safeguardSensitiveWords": { "index": 38, "kind": "parameter",
"displayName": "Safeguard Sensitive Words", "group": "security", "label":
"security", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Comma-separated list of
sensitive words for SafeGuard advisor. Wh [...]
- "safeguardOrder": { "index": 39, "kind": "parameter", "displayName":
"Safeguard Order", "group": "security (advanced)", "label":
"security,advanced", "required": false, "type": "integer", "javaType":
"java.lang.Integer", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Order of execution for
SafeGuard advisor. Lower numbers execut [...]
+ "sessionMessageWindow": { "index": 23, "kind": "parameter", "displayName":
"Session Message Window", "group": "advanced", "label": "advanced", "required":
false, "type": "integer", "javaType": "int", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": 20, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "The number of the newest
messages of the session that sessionSe [...]
+ "sessionService": { "index": 24, "kind": "parameter", "displayName":
"Session Service", "group": "advanced", "label": "advanced", "required": false,
"type": "object", "javaType": "org.springframework.ai.session.SessionService",
"deprecated": false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Spring AI SessionService
for keeping the conversation hi [...]
+ "structuredOutputConverter": { "index": 25, "kind": "parameter",
"displayName": "Structured Output Converter", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"org.springframework.ai.converter.StructuredOutputConverter<java.lang.Object>",
"deprecated": false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "A [...]
+ "structuredOutputValidation": { "index": 26, "kind": "parameter",
"displayName": "Structured Output Validation", "group": "advanced", "label":
"advanced", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue":
false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Enable structured output
validation with aut [...]
+ "structuredOutputValidationMaxAttempts": { "index": 27, "kind":
"parameter", "displayName": "Structured Output Validation Max Attempts",
"group": "advanced", "label": "advanced", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": 3, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Maximum number of retry
atte [...]
+ "systemMetadata": { "index": 28, "kind": "parameter", "displayName":
"System Metadata", "group": "advanced", "label": "advanced", "required": false,
"type": "object", "javaType": "java.util.Map<java.lang.String,
java.lang.Object>", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Metadata to attach to
system messages. This metadat [...]
+ "temperature": { "index": 29, "kind": "parameter", "displayName":
"Temperature", "group": "advanced", "label": "advanced", "required": false,
"type": "number", "javaType": "java.lang.Double", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Temperature parameter
for response randomness (0.0-2.0)." },
+ "toolCallbacks": { "index": 30, "kind": "parameter", "displayName": "Tool
Callbacks", "group": "advanced", "label": "advanced", "required": false,
"type": "array", "javaType":
"java.util.List<org.springframework.ai.tool.ToolCallback>", "deprecated":
false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "List of ToolCallback
instances to register along [...]
+ "toolContext": { "index": 31, "kind": "parameter", "displayName": "Tool
Context", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>",
"deprecated": false, "autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Context map to pass to
tools during execution. Tool metho [...]
+ "topKSampling": { "index": 32, "kind": "parameter", "displayName": "Top
KSampling", "group": "advanced", "label": "advanced", "required": false,
"type": "integer", "javaType": "java.lang.Integer", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Top K parameter for
sampling." },
+ "topP": { "index": 33, "kind": "parameter", "displayName": "Top P",
"group": "advanced", "label": "advanced", "required": false, "type": "number",
"javaType": "java.lang.Double", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Top P parameter for
nucleus sampling." },
+ "userMetadata": { "index": 34, "kind": "parameter", "displayName": "User
Metadata", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>",
"deprecated": false, "autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Metadata to attach to
user messages. This metadata can [...]
+ "ragTemplate": { "index": 35, "kind": "parameter", "displayName": "Rag
Template", "group": "rag", "label": "rag", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "Context:\\n\\{context}\\n\\nQuestion:
\\{question}", "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Template for formatting
RAG (R [...]
+ "similarityThreshold": { "index": 36, "kind": "parameter", "displayName":
"Similarity Threshold", "group": "rag", "label": "rag", "required": false,
"type": "number", "javaType": "double", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": 0.7, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Similarity threshold for
RAG retrieval (default: 0.7)." },
+ "topK": { "index": 37, "kind": "parameter", "displayName": "Top K",
"group": "rag", "label": "rag", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": 5, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Number of top documents
to retrieve for RAG (default: 5)." },
+ "vectorStore": { "index": 38, "kind": "parameter", "displayName": "Vector
Store", "group": "rag", "label": "rag", "required": false, "type": "object",
"javaType": "org.springframework.ai.vectorstore.VectorStore", "deprecated":
false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "VectorStore for
automatic RAG retrieval." },
+ "safeguardFailureResponse": { "index": 39, "kind": "parameter",
"displayName": "Safeguard Failure Response", "group": "security", "label":
"security", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Failure response message
for SafeGuard advisor when sensitive c [...]
+ "safeguardSensitiveWords": { "index": 40, "kind": "parameter",
"displayName": "Safeguard Sensitive Words", "group": "security", "label":
"security", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Comma-separated list of
sensitive words for SafeGuard advisor. Wh [...]
+ "safeguardOrder": { "index": 41, "kind": "parameter", "displayName":
"Safeguard Order", "group": "security (advanced)", "label":
"security,advanced", "required": false, "type": "integer", "javaType":
"java.lang.Integer", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Order of execution for
SafeGuard advisor. Lower numbers execut [...]
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spring-ai-chat-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spring-ai-chat-component.adoc
index 27a508e245a5..0c4e7566e7ed 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spring-ai-chat-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spring-ai-chat-component.adoc
@@ -48,7 +48,7 @@ include::partial$component-endpoint-headers.adoc[]
The component requires a Spring AI `ChatModel` to be configured. The component
automatically creates a `ChatClient` internally and handles all the advanced
features for you, including:
-- **ChatMemory**: Automatic conversation history management via
MessageChatMemoryAdvisor or VectorStoreChatMemoryAdvisor
+- **Memory**: Automatic conversation history management via session memory
(SessionAdvisors), VectorStoreChatMemoryAdvisor, or the deprecated
MessageChatMemoryAdvisor
- **VectorStore RAG**: Automatic context retrieval from vector databases via
QuestionAnswerAdvisor
- **SafeGuard**: Content filtering based on sensitive words
- **Custom Advisors**: Any additional advisors you configure
@@ -446,16 +446,85 @@ YAML::
=== Conversation Memory
-The component provides automatic conversation memory management via Spring
AI's ChatClient and ChatMemory. Two memory strategies are supported:
+The component provides automatic conversation memory management via Spring
AI's ChatClient and its memory advisors. Three memory strategies are supported:
-* **MessageChatMemoryAdvisor** - Traditional message-based memory using
ChatMemory implementations
-* **VectorStoreChatMemoryAdvisor** - Vector-based semantic memory using
VectorStore for long-term retrieval
+* **Session memory** (`sessionService`) - The conversation is a Spring AI
session, kept by `SessionAdvisors`
+* **VectorStoreChatMemoryAdvisor** (`chatMemoryVectorStore`) - Vector-based
semantic memory using VectorStore for long-term retrieval
+* **MessageChatMemoryAdvisor** (`chatMemory`, deprecated) - Message-based
memory using ChatMemory implementations
-IMPORTANT: Do not configure both `chatMemory` and `chatMemoryVectorStore` on
the same endpoint. If both are provided, `chatMemory`
(MessageChatMemoryAdvisor) will take precedence.
+One memory is used per endpoint: `sessionService`, else `chatMemory`, else
`chatMemoryVectorStore`. When `chatMemoryVectorStore` is set with one of the
others, it is not used, and a warning is logged. When the `advisors` option has
a memory advisor of its own, none of the three is used.
-NOTE: Chat memory is only activated when the `CamelSpringAiChatConversationId`
header is set on the exchange. Without this header, the memory advisor is not
applied, even if `chatMemory` or `chatMemoryVectorStore` is configured. This
allows you to selectively enable memory on a per-request basis.
+NOTE: Memory is only activated when the `CamelSpringAiChatConversationId`
header is set on the exchange. Without this header, the memory advisor of the
endpoint is not applied, even if `sessionService`, `chatMemory` or
`chatMemoryVectorStore` is configured. This allows you to selectively enable
memory on a per-request basis. This applies to the memory of the endpoint only:
session advisors passed with the `advisors` option need the header on every
exchange (see below).
-==== Message-based Memory (ChatMemory)
+IMPORTANT: The conversation id decides whose history is read and appended to,
and a session is created for any id on first use, without an access check.
Derive it from an authenticated identity, such as the user of the request, and
not from a raw field of the request that a caller can choose.
+
+==== Session Memory (SessionService)
+
+Spring AI 2.1 replaces `ChatMemory` with session memory. A session keeps the
conversation as a log of events, and the prompt is built from it. Configure a
Spring AI `SessionService` with the `sessionService` option. The
`CamelSpringAiChatConversationId` header is the session id. A session is
created on first use.
+
+._Java-only: programmatic Spring AI `SessionService` setup and
ProducerTemplate usage_
+[source,java]
+----
+// Create the session service on an in-memory repository
+SessionService sessionService = DefaultSessionService.builder()
+ .sessionRepository(InMemorySessionRepository.builder().build())
+ .build();
+
+context.getRegistry().bind("sessionService", sessionService);
+
+// Configure endpoint with session memory
+from("direct:chat")
+
.to("spring-ai-chat:memory?chatModel=#chatModel&sessionService=#sessionService");
+
+// Conversation ID for isolation: it is the session id
+template.requestBodyAndHeader("direct:chat", "My name is Alice",
+ SpringAiChatConstants.CONVERSATION_ID, "user-123", String.class);
+
+template.requestBodyAndHeader("direct:chat", "What's my name?",
+ SpringAiChatConstants.CONVERSATION_ID, "user-123", String.class); // Will
remember: "Alice"
+----
+
+`InMemorySessionRepository` is for tests and demos. Its sessions are lost on
restart.
+
+In Spring Boot, add `spring-ai-starter-model-session-jdbc`. With a
`DataSource`, it creates a `SessionService` on a `JdbcSessionRepository`, and
the component autowires it. The `sessionService` option is then used instead of
the `ChatMemory` bean that the Spring AI model starters create.
+
+The `sessionMessageWindow` option sets how many of the newest messages of the
session go into the prompt. It is 20 by default, as for a
`MessageWindowChatMemory`. The window is extended back to the start of its
turn, so a tool result is never sent without its tool call. The session keeps
every message, only the prompt is windowed. `0` sends the whole session.
+
+A session keeps every event, while a `MessageWindowChatMemory` kept the last
20 messages of a conversation; compaction only changes what the prompt is built
from. A `DefaultSessionService` gives a session a time to live of 60 days
(`spring.ai.session.time-to-live` in Spring Boot), but expired sessions are
only removed when `SessionService.deleteExpiredSessions(Instant)` is called, so
plan for the growth of a JDBC store, for example with a route:
+
+._Java-only: remove expired sessions every hour_
+[source,java]
+----
+from("timer:expiredSessions?period=3600000")
+ .process(exchange -> sessionService.deleteExpiredSessions(Instant.now()));
+----
+
+The component does not compact the session. To compact it, build the session
advisors yourself and pass them with the `advisors` option. The component then
adds no memory advisor of its own, and `sessionService` is not used.
+
+._Java-only: session advisors with compaction_
+[source,java]
+----
+List<Advisor> sessionAdvisors = SessionAdvisors.builder(sessionService)
+ .compaction(new TurnCountTrigger(20),
WindowCompactionStrategy.builder().lastTurns(10).build())
+ .build();
+
+context.getRegistry().bind("sessionAdvisors", sessionAdvisors);
+
+from("direct:chat")
+
.to("spring-ai-chat:memory?chatModel=#chatModel&advisors=#sessionAdvisors");
+----
+
+The `CamelSpringAiChatConversationId` header is passed to every memory advisor
as the conversation id (`MemoryAdvisor.CONVERSATION_ID`, the key that
`SessionAdvisors.session` sets). This includes the advisors of the `advisors`
option and of a `chatClient` you configure.
+
+Session advisors need the header: without it they fail the exchange with
`IllegalStateException: No session ID found in advisor context`. A
`MessageChatMemoryAdvisor` instead uses a default conversation id.
+
+The component looks for a memory advisor in the `advisors` option only, not in
the default advisors of a `chatClient` you configure. When such a `chatClient`
has its own memory advisor, and a `SessionService` or `ChatMemory` bean is
autowired (in Spring Boot, the model starters create a `ChatMemory` bean), the
endpoint adds its own memory advisor as well, and the conversation is stored
twice. Pass the memory advisor with the `advisors` option instead, or turn off
autowiring with `autowir [...]
+
+See the https://docs.spring.io/spring-ai/reference/2.1/api/session.html[Spring
AI Session Memory] documentation.
+
+==== Message-based Memory (ChatMemory, deprecated)
+
+Spring AI 2.1 deprecates `ChatMemory`, `MessageWindowChatMemory` and
`MessageChatMemoryAdvisor` for removal in Spring AI 3.0. The `chatMemory`
option is deprecated, and works until then. Use `sessionService` instead. The
conversations stored in a `ChatMemory` are not moved to a session: a session
starts empty.
Configure a `ChatMemory` on the endpoint for automatic conversation tracking
using traditional message window approach. This strategy keeps a configurable
number of recent messages in memory.
@@ -954,7 +1023,7 @@ For maximum control, you can provide a pre-configured
`ChatClient` instead of a
[source,java]
----
ChatClient chatClient = ChatClient.builder(chatModel)
- .defaultAdvisors(new MessageChatMemoryAdvisor(chatMemory))
+ .defaultAdvisors(new SimpleLoggerAdvisor())
.defaultSystem("You are a helpful assistant")
.build();
diff --git
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/pom.xml
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/pom.xml
index 67fe2cf1b178..c28f830e626e 100644
---
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/pom.xml
+++
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/pom.xml
@@ -81,6 +81,16 @@
<artifactId>spring-ai-vector-store-advisor</artifactId>
</dependency>
+ <!-- Spring AI session memory (sessionService), which replaces the
deprecated ChatMemory -->
+ <dependency>
+ <groupId>org.springframework.ai</groupId>
+ <artifactId>spring-ai-session</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.ai</groupId>
+ <artifactId>spring-ai-session-advisor</artifactId>
+ </dependency>
+
<!-- Spring AI MCP integration for Model Context Protocol client
support.
The MCP SDK is included transitively via spring-ai-mcp. -->
<dependency>
diff --git
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/generated/java/org/apache/camel/component/springai/chat/SpringAiChatEndpointConfigurer.java
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/generated/java/org/apache/camel/component/springai/chat/SpringAiChatEndpointConfigurer.java
index 1de2f1fe2dbe..69efe7ea6ee5 100644
---
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/generated/java/org/apache/camel/component/springai/chat/SpringAiChatEndpointConfigurer.java
+++
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/generated/java/org/apache/camel/component/springai/chat/SpringAiChatEndpointConfigurer.java
@@ -59,6 +59,10 @@ public class SpringAiChatEndpointConfigurer extends
PropertyConfigurerSupport im
case "safeguardOrder":
target.getConfiguration().setSafeguardOrder(property(camelContext,
java.lang.Integer.class, value)); return true;
case "safeguardsensitivewords":
case "safeguardSensitiveWords":
target.getConfiguration().setSafeguardSensitiveWords(property(camelContext,
java.lang.String.class, value)); return true;
+ case "sessionmessagewindow":
+ case "sessionMessageWindow":
target.getConfiguration().setSessionMessageWindow(property(camelContext,
int.class, value)); return true;
+ case "sessionservice":
+ case "sessionService":
target.getConfiguration().setSessionService(property(camelContext,
org.springframework.ai.session.SessionService.class, value)); return true;
case "similaritythreshold":
case "similarityThreshold":
target.getConfiguration().setSimilarityThreshold(property(camelContext,
double.class, value)); return true;
case "structuredoutputconverter":
@@ -105,7 +109,7 @@ public class SpringAiChatEndpointConfigurer extends
PropertyConfigurerSupport im
@Override
public String[] getAutowiredNames() {
- return new String[]{"chatClient", "chatMemory", "chatModel",
"structuredOutputConverter", "toolCallbacks", "toolSearchEmbeddingModel",
"vectorStore"};
+ return new String[]{"chatClient", "chatMemory", "chatModel",
"sessionService", "structuredOutputConverter", "toolCallbacks",
"toolSearchEmbeddingModel", "vectorStore"};
}
@Override
@@ -146,6 +150,10 @@ public class SpringAiChatEndpointConfigurer extends
PropertyConfigurerSupport im
case "safeguardOrder": return java.lang.Integer.class;
case "safeguardsensitivewords":
case "safeguardSensitiveWords": return java.lang.String.class;
+ case "sessionmessagewindow":
+ case "sessionMessageWindow": return int.class;
+ case "sessionservice":
+ case "sessionService": return
org.springframework.ai.session.SessionService.class;
case "similaritythreshold":
case "similarityThreshold": return double.class;
case "structuredoutputconverter":
@@ -229,6 +237,10 @@ public class SpringAiChatEndpointConfigurer extends
PropertyConfigurerSupport im
case "safeguardOrder": return
target.getConfiguration().getSafeguardOrder();
case "safeguardsensitivewords":
case "safeguardSensitiveWords": return
target.getConfiguration().getSafeguardSensitiveWords();
+ case "sessionmessagewindow":
+ case "sessionMessageWindow": return
target.getConfiguration().getSessionMessageWindow();
+ case "sessionservice":
+ case "sessionService": return
target.getConfiguration().getSessionService();
case "similaritythreshold":
case "similarityThreshold": return
target.getConfiguration().getSimilarityThreshold();
case "structuredoutputconverter":
diff --git
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/generated/java/org/apache/camel/component/springai/chat/SpringAiChatEndpointUriFactory.java
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/generated/java/org/apache/camel/component/springai/chat/SpringAiChatEndpointUriFactory.java
index 89ea04b5bfa8..9c3207af2abb 100644
---
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/generated/java/org/apache/camel/component/springai/chat/SpringAiChatEndpointUriFactory.java
+++
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/generated/java/org/apache/camel/component/springai/chat/SpringAiChatEndpointUriFactory.java
@@ -24,7 +24,7 @@ public class SpringAiChatEndpointUriFactory extends
org.apache.camel.support.com
private static final Set<String> ENDPOINT_IDENTITY_PROPERTY_NAMES;
private static final Map<String, String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(40);
+ Set<String> props = new HashSet<>(42);
props.add("advisors");
props.add("chatClient");
props.add("chatId");
@@ -44,6 +44,8 @@ public class SpringAiChatEndpointUriFactory extends
org.apache.camel.support.com
props.add("safeguardFailureResponse");
props.add("safeguardOrder");
props.add("safeguardSensitiveWords");
+ props.add("sessionMessageWindow");
+ props.add("sessionService");
props.add("similarityThreshold");
props.add("structuredOutputConverter");
props.add("structuredOutputValidation");
diff --git
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/generated/resources/META-INF/org/apache/camel/component/springai/chat/spring-ai-chat.json
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/generated/resources/META-INF/org/apache/camel/component/springai/chat/spring-ai-chat.json
index 8b2a68611224..baffc7aea766 100644
---
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/generated/resources/META-INF/org/apache/camel/component/springai/chat/spring-ai-chat.json
+++
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/generated/resources/META-INF/org/apache/camel/component/springai/chat/spring-ai-chat.json
@@ -53,7 +53,7 @@
"CamelSpringAiChatEntityClass": { "index": 21, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "Class<?>", "deprecated": false, "autowired": false, "secret":
false, "description": "The Java class to use for entity response conversion",
"constantName":
"org.apache.camel.component.springai.chat.SpringAiChatConstants#ENTITY_CLASS" },
"CamelSpringAiChatUserMetadata": { "index": 22, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "java.util.Map<String, Object>", "deprecated": false, "autowired":
false, "secret": false, "description": "Metadata to attach to user messages",
"constantName":
"org.apache.camel.component.springai.chat.SpringAiChatConstants#USER_METADATA"
},
"CamelSpringAiChatSystemMetadata": { "index": 23, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "java.util.Map<String, Object>", "deprecated": false, "autowired":
false, "secret": false, "description": "Metadata to attach to system messages",
"constantName":
"org.apache.camel.component.springai.chat.SpringAiChatConstants#SYSTEM_METADATA"
},
- "CamelSpringAiChatConversationId": { "index": 24, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "String", "deprecated": false, "autowired": false, "secret": false,
"description": "Conversation ID for managing separate conversation contexts in
chat memory", "constantName":
"org.apache.camel.component.springai.chat.SpringAiChatConstants#CONVERSATION_ID"
},
+ "CamelSpringAiChatConversationId": { "index": 24, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "String", "deprecated": false, "autowired": false, "secret": false,
"description": "The conversation ID. It selects the session (sessionService) or
the conversation (chatMemory, chatMemoryVectorStore), and is passed to every
memory advisor, also to those of the advisors option or of a configured
chatClient. Session advisors require it [...]
"CamelSpringAiChatMaxFileSize": { "index": 25, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "Long", "deprecated": false, "autowired": false, "secret": false,
"description": "Maximum file size in bytes for multimodal content. Overrides
endpoint configuration.", "constantName":
"org.apache.camel.component.springai.chat.SpringAiChatConstants#MAX_FILE_SIZE"
},
"CamelSpringAiChatFinishReason": { "index": 26, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "String", "deprecated": false, "autowired": false, "secret": false,
"description": "The reason why the chat response generation stopped (e.g.,
STOP, LENGTH, TOOL_CALLS)", "constantName":
"org.apache.camel.component.springai.chat.SpringAiChatConstants#FINISH_REASON"
},
"CamelSpringAiChatFinishReasonCategory": { "index": 27, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "String", "enum": [ "COMPLETED", "TRUNCATED", "TOOL_CALL",
"FILTERED", "OTHER", "UNSPECIFIED" ], "deprecated": false, "autowired": false,
"secret": false, "description": "The category of the finish reason, the same
for every provider: COMPLETED, TRUNCATED (a token or length limit), TOOL_CALL,
FILTERED (a content filter, or a ref [...]
@@ -82,9 +82,9 @@
"toolSearchStrategy": { "index": 10, "kind": "parameter", "displayName":
"Tool Search Strategy", "group": "producer", "label": "producer", "required":
false, "type": "enum", "javaType":
"org.apache.camel.component.ai.tool.AiToolSearchStrategy", "enum": [ "KEYWORD",
"VECTOR" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "KEYWORD", "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configurat [...]
"userMessage": { "index": 11, "kind": "parameter", "displayName": "User
Message", "group": "producer", "label": "", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Default user message
text for multimodal requests. Can be combined with media data in the message
[...]
"lazyStartProducer": { "index": 12, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produ [...]
- "advisors": { "index": 13, "kind": "parameter", "displayName": "Advisors",
"group": "advanced", "label": "advanced", "required": false, "type": "array",
"javaType":
"java.util.List<org.springframework.ai.chat.client.advisor.api.Advisor>",
"deprecated": false, "autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "List of custom advisors
to add to the ChatCl [...]
- "chatMemory": { "index": 14, "kind": "parameter", "displayName": "Chat
Memory", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "org.springframework.ai.chat.memory.ChatMemory",
"deprecated": false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "ChatMemory instance for
maintaining conversation history across [...]
- "chatMemoryVectorStore": { "index": 15, "kind": "parameter",
"displayName": "Chat Memory Vector Store", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"org.springframework.ai.vectorstore.VectorStore", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "VectorStore instance for
maintaining c [...]
+ "advisors": { "index": 13, "kind": "parameter", "displayName": "Advisors",
"group": "advanced", "label": "advanced", "required": false, "type": "array",
"javaType":
"java.util.List<org.springframework.ai.chat.client.advisor.api.Advisor>",
"deprecated": false, "autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "List of custom advisors
to add to the ChatCl [...]
+ "chatMemory": { "index": 14, "kind": "parameter", "displayName": "Chat
Memory", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "org.springframework.ai.chat.memory.ChatMemory",
"deprecated": true, "deprecationNote": "Spring AI 2.1 deprecates ChatMemory for
removal in Spring AI 3.0. Use sessionService.", "autowired": true, "secret":
false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurati [...]
+ "chatMemoryVectorStore": { "index": 15, "kind": "parameter",
"displayName": "Chat Memory Vector Store", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"org.springframework.ai.vectorstore.VectorStore", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "VectorStore instance for
maintaining c [...]
"entityClass": { "index": 16, "kind": "parameter", "displayName": "Entity
Class", "group": "advanced", "label": "advanced", "required": false, "type":
"string", "javaType": "java.lang.Class<java.lang.Object>", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "The Java class to use
for entity response conversion using ChatClient.ent [...]
"maxFileSize": { "index": 17, "kind": "parameter", "displayName": "Max
File Size", "group": "advanced", "label": "advanced", "required": false,
"type": "integer", "javaType": "long", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 1048576, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Maximum file size in
bytes for multimodal content (images, audio, PDFs, etc [...]
"maxTokens": { "index": 18, "kind": "parameter", "displayName": "Max
Tokens", "group": "advanced", "label": "advanced", "required": false, "type":
"integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired":
false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Maximum tokens in the
response." },
@@ -92,22 +92,24 @@
"mcpTimeout": { "index": 20, "kind": "parameter", "displayName": "Mcp
Timeout", "group": "advanced", "label": "advanced", "required": false, "type":
"integer", "javaType": "int", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 20, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Timeout in seconds for
MCP operations including tool execution and initialization" },
"outputClass": { "index": 21, "kind": "parameter", "displayName": "Output
Class", "group": "advanced", "label": "advanced", "required": false, "type":
"string", "javaType": "java.lang.Class<java.lang.Object>", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "The Java class to use
for BEAN output format conversion. Required when ou [...]
"outputFormat": { "index": 22, "kind": "parameter", "displayName": "Output
Format", "group": "advanced", "label": "advanced", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "The output format for
structured output conversion (BEAN, MAP, LIST). Used in conjunctio [...]
- "structuredOutputConverter": { "index": 23, "kind": "parameter",
"displayName": "Structured Output Converter", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"org.springframework.ai.converter.StructuredOutputConverter<java.lang.Object>",
"deprecated": false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "A [...]
- "structuredOutputValidation": { "index": 24, "kind": "parameter",
"displayName": "Structured Output Validation", "group": "advanced", "label":
"advanced", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue":
false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Enable structured output
validation with aut [...]
- "structuredOutputValidationMaxAttempts": { "index": 25, "kind":
"parameter", "displayName": "Structured Output Validation Max Attempts",
"group": "advanced", "label": "advanced", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": 3, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Maximum number of retry
atte [...]
- "systemMetadata": { "index": 26, "kind": "parameter", "displayName":
"System Metadata", "group": "advanced", "label": "advanced", "required": false,
"type": "object", "javaType": "java.util.Map<java.lang.String,
java.lang.Object>", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Metadata to attach to
system messages. This metadat [...]
- "temperature": { "index": 27, "kind": "parameter", "displayName":
"Temperature", "group": "advanced", "label": "advanced", "required": false,
"type": "number", "javaType": "java.lang.Double", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Temperature parameter
for response randomness (0.0-2.0)." },
- "toolCallbacks": { "index": 28, "kind": "parameter", "displayName": "Tool
Callbacks", "group": "advanced", "label": "advanced", "required": false,
"type": "array", "javaType":
"java.util.List<org.springframework.ai.tool.ToolCallback>", "deprecated":
false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "List of ToolCallback
instances to register along [...]
- "toolContext": { "index": 29, "kind": "parameter", "displayName": "Tool
Context", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>",
"deprecated": false, "autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Context map to pass to
tools during execution. Tool metho [...]
- "topKSampling": { "index": 30, "kind": "parameter", "displayName": "Top
KSampling", "group": "advanced", "label": "advanced", "required": false,
"type": "integer", "javaType": "java.lang.Integer", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Top K parameter for
sampling." },
- "topP": { "index": 31, "kind": "parameter", "displayName": "Top P",
"group": "advanced", "label": "advanced", "required": false, "type": "number",
"javaType": "java.lang.Double", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Top P parameter for
nucleus sampling." },
- "userMetadata": { "index": 32, "kind": "parameter", "displayName": "User
Metadata", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>",
"deprecated": false, "autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Metadata to attach to
user messages. This metadata can [...]
- "ragTemplate": { "index": 33, "kind": "parameter", "displayName": "Rag
Template", "group": "rag", "label": "rag", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "Context:\\n\\{context}\\n\\nQuestion:
\\{question}", "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Template for formatting
RAG (R [...]
- "similarityThreshold": { "index": 34, "kind": "parameter", "displayName":
"Similarity Threshold", "group": "rag", "label": "rag", "required": false,
"type": "number", "javaType": "double", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": 0.7, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Similarity threshold for
RAG retrieval (default: 0.7)." },
- "topK": { "index": 35, "kind": "parameter", "displayName": "Top K",
"group": "rag", "label": "rag", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": 5, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Number of top documents
to retrieve for RAG (default: 5)." },
- "vectorStore": { "index": 36, "kind": "parameter", "displayName": "Vector
Store", "group": "rag", "label": "rag", "required": false, "type": "object",
"javaType": "org.springframework.ai.vectorstore.VectorStore", "deprecated":
false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "VectorStore for
automatic RAG retrieval." },
- "safeguardFailureResponse": { "index": 37, "kind": "parameter",
"displayName": "Safeguard Failure Response", "group": "security", "label":
"security", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Failure response message
for SafeGuard advisor when sensitive c [...]
- "safeguardSensitiveWords": { "index": 38, "kind": "parameter",
"displayName": "Safeguard Sensitive Words", "group": "security", "label":
"security", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Comma-separated list of
sensitive words for SafeGuard advisor. Wh [...]
- "safeguardOrder": { "index": 39, "kind": "parameter", "displayName":
"Safeguard Order", "group": "security (advanced)", "label":
"security,advanced", "required": false, "type": "integer", "javaType":
"java.lang.Integer", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Order of execution for
SafeGuard advisor. Lower numbers execut [...]
+ "sessionMessageWindow": { "index": 23, "kind": "parameter", "displayName":
"Session Message Window", "group": "advanced", "label": "advanced", "required":
false, "type": "integer", "javaType": "int", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": 20, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "The number of the newest
messages of the session that sessionSe [...]
+ "sessionService": { "index": 24, "kind": "parameter", "displayName":
"Session Service", "group": "advanced", "label": "advanced", "required": false,
"type": "object", "javaType": "org.springframework.ai.session.SessionService",
"deprecated": false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Spring AI SessionService
for keeping the conversation hi [...]
+ "structuredOutputConverter": { "index": 25, "kind": "parameter",
"displayName": "Structured Output Converter", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"org.springframework.ai.converter.StructuredOutputConverter<java.lang.Object>",
"deprecated": false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "A [...]
+ "structuredOutputValidation": { "index": 26, "kind": "parameter",
"displayName": "Structured Output Validation", "group": "advanced", "label":
"advanced", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue":
false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Enable structured output
validation with aut [...]
+ "structuredOutputValidationMaxAttempts": { "index": 27, "kind":
"parameter", "displayName": "Structured Output Validation Max Attempts",
"group": "advanced", "label": "advanced", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": 3, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Maximum number of retry
atte [...]
+ "systemMetadata": { "index": 28, "kind": "parameter", "displayName":
"System Metadata", "group": "advanced", "label": "advanced", "required": false,
"type": "object", "javaType": "java.util.Map<java.lang.String,
java.lang.Object>", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Metadata to attach to
system messages. This metadat [...]
+ "temperature": { "index": 29, "kind": "parameter", "displayName":
"Temperature", "group": "advanced", "label": "advanced", "required": false,
"type": "number", "javaType": "java.lang.Double", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Temperature parameter
for response randomness (0.0-2.0)." },
+ "toolCallbacks": { "index": 30, "kind": "parameter", "displayName": "Tool
Callbacks", "group": "advanced", "label": "advanced", "required": false,
"type": "array", "javaType":
"java.util.List<org.springframework.ai.tool.ToolCallback>", "deprecated":
false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "List of ToolCallback
instances to register along [...]
+ "toolContext": { "index": 31, "kind": "parameter", "displayName": "Tool
Context", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>",
"deprecated": false, "autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Context map to pass to
tools during execution. Tool metho [...]
+ "topKSampling": { "index": 32, "kind": "parameter", "displayName": "Top
KSampling", "group": "advanced", "label": "advanced", "required": false,
"type": "integer", "javaType": "java.lang.Integer", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Top K parameter for
sampling." },
+ "topP": { "index": 33, "kind": "parameter", "displayName": "Top P",
"group": "advanced", "label": "advanced", "required": false, "type": "number",
"javaType": "java.lang.Double", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Top P parameter for
nucleus sampling." },
+ "userMetadata": { "index": 34, "kind": "parameter", "displayName": "User
Metadata", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>",
"deprecated": false, "autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Metadata to attach to
user messages. This metadata can [...]
+ "ragTemplate": { "index": 35, "kind": "parameter", "displayName": "Rag
Template", "group": "rag", "label": "rag", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "Context:\\n\\{context}\\n\\nQuestion:
\\{question}", "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Template for formatting
RAG (R [...]
+ "similarityThreshold": { "index": 36, "kind": "parameter", "displayName":
"Similarity Threshold", "group": "rag", "label": "rag", "required": false,
"type": "number", "javaType": "double", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": 0.7, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Similarity threshold for
RAG retrieval (default: 0.7)." },
+ "topK": { "index": 37, "kind": "parameter", "displayName": "Top K",
"group": "rag", "label": "rag", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": 5, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Number of top documents
to retrieve for RAG (default: 5)." },
+ "vectorStore": { "index": 38, "kind": "parameter", "displayName": "Vector
Store", "group": "rag", "label": "rag", "required": false, "type": "object",
"javaType": "org.springframework.ai.vectorstore.VectorStore", "deprecated":
false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "VectorStore for
automatic RAG retrieval." },
+ "safeguardFailureResponse": { "index": 39, "kind": "parameter",
"displayName": "Safeguard Failure Response", "group": "security", "label":
"security", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Failure response message
for SafeGuard advisor when sensitive c [...]
+ "safeguardSensitiveWords": { "index": 40, "kind": "parameter",
"displayName": "Safeguard Sensitive Words", "group": "security", "label":
"security", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Comma-separated list of
sensitive words for SafeGuard advisor. Wh [...]
+ "safeguardOrder": { "index": 41, "kind": "parameter", "displayName":
"Safeguard Order", "group": "security (advanced)", "label":
"security,advanced", "required": false, "type": "integer", "javaType":
"java.lang.Integer", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.springai.chat.SpringAiChatConfiguration",
"configurationField": "configuration", "description": "Order of execution for
SafeGuard advisor. Lower numbers execut [...]
}
}
diff --git
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/docs/spring-ai-chat-component.adoc
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/docs/spring-ai-chat-component.adoc
index 27a508e245a5..0c4e7566e7ed 100644
---
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/docs/spring-ai-chat-component.adoc
+++
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/docs/spring-ai-chat-component.adoc
@@ -48,7 +48,7 @@ include::partial$component-endpoint-headers.adoc[]
The component requires a Spring AI `ChatModel` to be configured. The component
automatically creates a `ChatClient` internally and handles all the advanced
features for you, including:
-- **ChatMemory**: Automatic conversation history management via
MessageChatMemoryAdvisor or VectorStoreChatMemoryAdvisor
+- **Memory**: Automatic conversation history management via session memory
(SessionAdvisors), VectorStoreChatMemoryAdvisor, or the deprecated
MessageChatMemoryAdvisor
- **VectorStore RAG**: Automatic context retrieval from vector databases via
QuestionAnswerAdvisor
- **SafeGuard**: Content filtering based on sensitive words
- **Custom Advisors**: Any additional advisors you configure
@@ -446,16 +446,85 @@ YAML::
=== Conversation Memory
-The component provides automatic conversation memory management via Spring
AI's ChatClient and ChatMemory. Two memory strategies are supported:
+The component provides automatic conversation memory management via Spring
AI's ChatClient and its memory advisors. Three memory strategies are supported:
-* **MessageChatMemoryAdvisor** - Traditional message-based memory using
ChatMemory implementations
-* **VectorStoreChatMemoryAdvisor** - Vector-based semantic memory using
VectorStore for long-term retrieval
+* **Session memory** (`sessionService`) - The conversation is a Spring AI
session, kept by `SessionAdvisors`
+* **VectorStoreChatMemoryAdvisor** (`chatMemoryVectorStore`) - Vector-based
semantic memory using VectorStore for long-term retrieval
+* **MessageChatMemoryAdvisor** (`chatMemory`, deprecated) - Message-based
memory using ChatMemory implementations
-IMPORTANT: Do not configure both `chatMemory` and `chatMemoryVectorStore` on
the same endpoint. If both are provided, `chatMemory`
(MessageChatMemoryAdvisor) will take precedence.
+One memory is used per endpoint: `sessionService`, else `chatMemory`, else
`chatMemoryVectorStore`. When `chatMemoryVectorStore` is set with one of the
others, it is not used, and a warning is logged. When the `advisors` option has
a memory advisor of its own, none of the three is used.
-NOTE: Chat memory is only activated when the `CamelSpringAiChatConversationId`
header is set on the exchange. Without this header, the memory advisor is not
applied, even if `chatMemory` or `chatMemoryVectorStore` is configured. This
allows you to selectively enable memory on a per-request basis.
+NOTE: Memory is only activated when the `CamelSpringAiChatConversationId`
header is set on the exchange. Without this header, the memory advisor of the
endpoint is not applied, even if `sessionService`, `chatMemory` or
`chatMemoryVectorStore` is configured. This allows you to selectively enable
memory on a per-request basis. This applies to the memory of the endpoint only:
session advisors passed with the `advisors` option need the header on every
exchange (see below).
-==== Message-based Memory (ChatMemory)
+IMPORTANT: The conversation id decides whose history is read and appended to,
and a session is created for any id on first use, without an access check.
Derive it from an authenticated identity, such as the user of the request, and
not from a raw field of the request that a caller can choose.
+
+==== Session Memory (SessionService)
+
+Spring AI 2.1 replaces `ChatMemory` with session memory. A session keeps the
conversation as a log of events, and the prompt is built from it. Configure a
Spring AI `SessionService` with the `sessionService` option. The
`CamelSpringAiChatConversationId` header is the session id. A session is
created on first use.
+
+._Java-only: programmatic Spring AI `SessionService` setup and
ProducerTemplate usage_
+[source,java]
+----
+// Create the session service on an in-memory repository
+SessionService sessionService = DefaultSessionService.builder()
+ .sessionRepository(InMemorySessionRepository.builder().build())
+ .build();
+
+context.getRegistry().bind("sessionService", sessionService);
+
+// Configure endpoint with session memory
+from("direct:chat")
+
.to("spring-ai-chat:memory?chatModel=#chatModel&sessionService=#sessionService");
+
+// Conversation ID for isolation: it is the session id
+template.requestBodyAndHeader("direct:chat", "My name is Alice",
+ SpringAiChatConstants.CONVERSATION_ID, "user-123", String.class);
+
+template.requestBodyAndHeader("direct:chat", "What's my name?",
+ SpringAiChatConstants.CONVERSATION_ID, "user-123", String.class); // Will
remember: "Alice"
+----
+
+`InMemorySessionRepository` is for tests and demos. Its sessions are lost on
restart.
+
+In Spring Boot, add `spring-ai-starter-model-session-jdbc`. With a
`DataSource`, it creates a `SessionService` on a `JdbcSessionRepository`, and
the component autowires it. The `sessionService` option is then used instead of
the `ChatMemory` bean that the Spring AI model starters create.
+
+The `sessionMessageWindow` option sets how many of the newest messages of the
session go into the prompt. It is 20 by default, as for a
`MessageWindowChatMemory`. The window is extended back to the start of its
turn, so a tool result is never sent without its tool call. The session keeps
every message, only the prompt is windowed. `0` sends the whole session.
+
+A session keeps every event, while a `MessageWindowChatMemory` kept the last
20 messages of a conversation; compaction only changes what the prompt is built
from. A `DefaultSessionService` gives a session a time to live of 60 days
(`spring.ai.session.time-to-live` in Spring Boot), but expired sessions are
only removed when `SessionService.deleteExpiredSessions(Instant)` is called, so
plan for the growth of a JDBC store, for example with a route:
+
+._Java-only: remove expired sessions every hour_
+[source,java]
+----
+from("timer:expiredSessions?period=3600000")
+ .process(exchange -> sessionService.deleteExpiredSessions(Instant.now()));
+----
+
+The component does not compact the session. To compact it, build the session
advisors yourself and pass them with the `advisors` option. The component then
adds no memory advisor of its own, and `sessionService` is not used.
+
+._Java-only: session advisors with compaction_
+[source,java]
+----
+List<Advisor> sessionAdvisors = SessionAdvisors.builder(sessionService)
+ .compaction(new TurnCountTrigger(20),
WindowCompactionStrategy.builder().lastTurns(10).build())
+ .build();
+
+context.getRegistry().bind("sessionAdvisors", sessionAdvisors);
+
+from("direct:chat")
+
.to("spring-ai-chat:memory?chatModel=#chatModel&advisors=#sessionAdvisors");
+----
+
+The `CamelSpringAiChatConversationId` header is passed to every memory advisor
as the conversation id (`MemoryAdvisor.CONVERSATION_ID`, the key that
`SessionAdvisors.session` sets). This includes the advisors of the `advisors`
option and of a `chatClient` you configure.
+
+Session advisors need the header: without it they fail the exchange with
`IllegalStateException: No session ID found in advisor context`. A
`MessageChatMemoryAdvisor` instead uses a default conversation id.
+
+The component looks for a memory advisor in the `advisors` option only, not in
the default advisors of a `chatClient` you configure. When such a `chatClient`
has its own memory advisor, and a `SessionService` or `ChatMemory` bean is
autowired (in Spring Boot, the model starters create a `ChatMemory` bean), the
endpoint adds its own memory advisor as well, and the conversation is stored
twice. Pass the memory advisor with the `advisors` option instead, or turn off
autowiring with `autowir [...]
+
+See the https://docs.spring.io/spring-ai/reference/2.1/api/session.html[Spring
AI Session Memory] documentation.
+
+==== Message-based Memory (ChatMemory, deprecated)
+
+Spring AI 2.1 deprecates `ChatMemory`, `MessageWindowChatMemory` and
`MessageChatMemoryAdvisor` for removal in Spring AI 3.0. The `chatMemory`
option is deprecated, and works until then. Use `sessionService` instead. The
conversations stored in a `ChatMemory` are not moved to a session: a session
starts empty.
Configure a `ChatMemory` on the endpoint for automatic conversation tracking
using traditional message window approach. This strategy keeps a configurable
number of recent messages in memory.
@@ -954,7 +1023,7 @@ For maximum control, you can provide a pre-configured
`ChatClient` instead of a
[source,java]
----
ChatClient chatClient = ChatClient.builder(chatModel)
- .defaultAdvisors(new MessageChatMemoryAdvisor(chatMemory))
+ .defaultAdvisors(new SimpleLoggerAdvisor())
.defaultSystem("You are a helpful assistant")
.build();
diff --git
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/java/org/apache/camel/component/springai/chat/SpringAiChatConfiguration.java
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/java/org/apache/camel/component/springai/chat/SpringAiChatConfiguration.java
index 33818ae44254..0e0c823d2d52 100644
---
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/java/org/apache/camel/component/springai/chat/SpringAiChatConfiguration.java
+++
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/java/org/apache/camel/component/springai/chat/SpringAiChatConfiguration.java
@@ -30,6 +30,7 @@ import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.converter.StructuredOutputConverter;
import org.springframework.ai.embedding.EmbeddingModel;
+import org.springframework.ai.session.SessionService;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.vectorstore.VectorStore;
@@ -45,9 +46,25 @@ public class SpringAiChatConfiguration implements Cloneable {
private ChatModel chatModel;
@UriParam(label = "advanced")
- @Metadata(autowired = true)
+ @Metadata(autowired = true,
+ deprecationNote = "Spring AI 2.1 deprecates ChatMemory for
removal in Spring AI 3.0. Use sessionService.")
+ @Deprecated
private ChatMemory chatMemory;
+ @UriParam(label = "advanced",
+ description = "Spring AI SessionService for keeping the
conversation history across requests, in a session."
+ + " The CamelSpringAiChatConversationId header
selects the session, which is created on"
+ + " first use. Without the header, no memory is
used. When it is set, sessionService is"
+ + " used instead of chatMemory and
chatMemoryVectorStore.")
+ @Metadata(autowired = true)
+ private SessionService sessionService;
+
+ @UriParam(label = "advanced", defaultValue = "20",
+ description = "The number of the newest messages of the session
that sessionService sends to the model,"
+ + " extended back to the start of their turn, so
that a tool call is never sent without its"
+ + " result. The session keeps every message. 0
sends the whole session.")
+ private int sessionMessageWindow = 20;
+
@UriParam(label = "advanced")
private VectorStore chatMemoryVectorStore;
@@ -213,6 +230,11 @@ public class SpringAiChatConfiguration implements
Cloneable {
this.chatModel = chatModel;
}
+ /**
+ * @deprecated Spring AI 2.1 deprecates {@link ChatMemory} for removal in
Spring AI 3.0. Use
+ * {@link #getSessionService()}.
+ */
+ @Deprecated
public ChatMemory getChatMemory() {
return chatMemory;
}
@@ -220,19 +242,50 @@ public class SpringAiChatConfiguration implements
Cloneable {
/**
* ChatMemory instance for maintaining conversation history across
requests. When provided, conversation context
* will be automatically managed using MessageChatMemoryAdvisor.
+ *
+ * @deprecated Spring AI 2.1 deprecates {@link ChatMemory} for removal in
Spring AI 3.0. Use
+ * {@link #setSessionService(SessionService)}.
*/
+ @Deprecated
public void setChatMemory(ChatMemory chatMemory) {
this.chatMemory = chatMemory;
}
+ public SessionService getSessionService() {
+ return sessionService;
+ }
+
+ /**
+ * Spring AI SessionService for keeping the conversation history across
requests, in a session. The
+ * CamelSpringAiChatConversationId header selects the session, which is
created on first use. Without the header, no
+ * memory is used. When it is set, sessionService is used instead of
chatMemory and chatMemoryVectorStore.
+ */
+ public void setSessionService(SessionService sessionService) {
+ this.sessionService = sessionService;
+ }
+
+ public int getSessionMessageWindow() {
+ return sessionMessageWindow;
+ }
+
+ /**
+ * The number of the newest messages of the session that sessionService
sends to the model, extended back to the
+ * start of their turn, so that a tool call is never sent without its
result. The session keeps every message. 0
+ * sends the whole session.
+ */
+ public void setSessionMessageWindow(int sessionMessageWindow) {
+ this.sessionMessageWindow = sessionMessageWindow;
+ }
+
public VectorStore getChatMemoryVectorStore() {
return chatMemoryVectorStore;
}
/**
* VectorStore instance for maintaining conversation history using
semantic search. When provided, conversation
- * context will be automatically managed using
VectorStoreChatMemoryAdvisor. This is an alternative to chatMemory
- * that uses vector embeddings for long-term memory with semantic
retrieval.
+ * context will be automatically managed using
VectorStoreChatMemoryAdvisor. This is an alternative to
+ * sessionService and chatMemory that uses vector embeddings for long-term
memory with semantic retrieval. When
+ * sessionService or chatMemory is set, it is used instead.
*/
public void setChatMemoryVectorStore(VectorStore chatMemoryVectorStore) {
this.chatMemoryVectorStore = chatMemoryVectorStore;
@@ -438,7 +491,9 @@ public class SpringAiChatConfiguration implements Cloneable
{
/**
* List of custom advisors to add to the ChatClient. These advisors will
be added after the built-in advisors
- * (SimpleLogger, SafeGuard, ChatMemory, QuestionAnswer) in the order they
are provided in the list.
+ * (SimpleLogger, SafeGuard, QuestionAnswer) in the order they are
provided in the list. When the list has a memory
+ * advisor, such as the session advisors, the endpoint adds no memory
advisor of its own (sessionService, chatMemory
+ * or chatMemoryVectorStore).
*/
public void setAdvisors(List<Advisor> advisors) {
this.advisors = advisors;
diff --git
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/java/org/apache/camel/component/springai/chat/SpringAiChatConstants.java
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/java/org/apache/camel/component/springai/chat/SpringAiChatConstants.java
index 8bc3f37414ae..26fa3cd7e97c 100644
---
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/java/org/apache/camel/component/springai/chat/SpringAiChatConstants.java
+++
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/java/org/apache/camel/component/springai/chat/SpringAiChatConstants.java
@@ -98,7 +98,10 @@ public final class SpringAiChatConstants {
@Metadata(description = "Metadata to attach to system messages", javaType
= "java.util.Map<String, Object>")
public static final String SYSTEM_METADATA =
"CamelSpringAiChatSystemMetadata";
- @Metadata(description = "Conversation ID for managing separate
conversation contexts in chat memory", javaType = "String")
+ @Metadata(description = "The conversation ID. It selects the session
(sessionService) or the conversation "
+ + "(chatMemory, chatMemoryVectorStore), and is
passed to every memory advisor, also to those "
+ + "of the advisors option or of a configured
chatClient. Session advisors require it.",
+ javaType = "String")
public static final String CONVERSATION_ID =
"CamelSpringAiChatConversationId";
@Metadata(description = "Maximum file size in bytes for multimodal
content. Overrides endpoint configuration.",
diff --git
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/java/org/apache/camel/component/springai/chat/SpringAiChatProducer.java
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/java/org/apache/camel/component/springai/chat/SpringAiChatProducer.java
index f285a83de460..056b4d24c42f 100644
---
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/java/org/apache/camel/component/springai/chat/SpringAiChatProducer.java
+++
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/main/java/org/apache/camel/component/springai/chat/SpringAiChatProducer.java
@@ -30,6 +30,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import java.util.function.Consumer;
import java.util.stream.Collectors;
import io.micrometer.observation.ObservationRegistry;
@@ -60,6 +61,7 @@ import
org.springframework.ai.chat.client.advisor.SafeGuardAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import
org.springframework.ai.chat.client.advisor.StructuredOutputValidationAdvisor;
import org.springframework.ai.chat.client.advisor.api.Advisor;
+import org.springframework.ai.chat.client.advisor.api.MemoryAdvisor;
import
org.springframework.ai.chat.client.advisor.vectorstore.QuestionAnswerAdvisor;
import
org.springframework.ai.chat.client.advisor.vectorstore.VectorStoreChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
@@ -78,6 +80,9 @@ import org.springframework.ai.converter.MapOutputConverter;
import org.springframework.ai.converter.StructuredOutputConverter;
import org.springframework.ai.document.Document;
import org.springframework.ai.model.tool.ToolCallingChatOptions;
+import org.springframework.ai.session.EventFilter;
+import org.springframework.ai.session.SessionService;
+import org.springframework.ai.session.advisor.SessionAdvisors;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.resolution.ToolCallbackResolver;
@@ -99,7 +104,8 @@ public class SpringAiChatProducer extends DefaultProducer {
private volatile Boolean observedBySpringAi;
private volatile Boolean toolCallsObservedBySpringAi;
private SpringAiChatMcpManager mcpManager;
- private Advisor chatMemoryAdvisor;
+ private List<Advisor> memoryAdvisors;
+ private boolean sessionMemory;
public SpringAiChatProducer(SpringAiChatEndpoint endpoint) {
super(endpoint);
@@ -158,22 +164,9 @@ public class SpringAiChatProducer extends DefaultProducer {
this.chatClient = builder.build();
}
- // Build chat memory advisor (added per-request only when
conversationId is set)
- ChatMemory chatMemory =
getEndpoint().getConfiguration().getChatMemory();
- VectorStore chatMemoryVectorStore =
getEndpoint().getConfiguration().getChatMemoryVectorStore();
- if (chatMemory != null && chatMemoryVectorStore != null) {
- LOG.warn("Both chatMemory and chatMemoryVectorStore are
configured. Using MessageChatMemoryAdvisor (chatMemory). "
- + "Configure only one memory type.");
- }
- if (chatMemory != null) {
- this.chatMemoryAdvisor =
MessageChatMemoryAdvisor.builder(chatMemory).build();
- LOG.debug("MessageChatMemoryAdvisor available (activated
per-request via conversationId header)");
- } else if (chatMemoryVectorStore != null) {
- this.chatMemoryAdvisor =
VectorStoreChatMemoryAdvisor.builder(chatMemoryVectorStore)
- .defaultTopK(getEndpoint().getConfiguration().getTopK())
- .build();
- LOG.debug("VectorStoreChatMemoryAdvisor available with topK={}",
getEndpoint().getConfiguration().getTopK());
- }
+ // Build the memory advisors (added per-request only when
conversationId is set)
+ this.memoryAdvisors = buildMemoryAdvisors();
+ this.sessionMemory = memoryAdvisors != null &&
getEndpoint().getConfiguration().getSessionService() != null;
// Initialize MCP clients if configured
Map<String, Object> mcpConfig =
getEndpoint().getConfiguration().getMcpServer();
@@ -805,12 +798,19 @@ public class SpringAiChatProducer extends DefaultProducer
{
LOG.debug("Added tool context with {} entries",
toolContext.size());
}
- // Add chat memory advisor per-request only when conversationId header
is set
+ // The conversation id goes to every memory advisor, also those of the
advisors option or of a configured
+ // chatClient. The memory advisors of the endpoint are added
per-request only when it is set.
String conversationId =
exchange.getIn().getHeader(SpringAiChatConstants.CONVERSATION_ID, String.class);
- if (conversationId != null && chatMemoryAdvisor != null) {
- final String convId = conversationId;
- request.advisors(chatMemoryAdvisor);
- request.advisors(a -> a.param(ChatMemory.CONVERSATION_ID, convId));
+ if (conversationId != null) {
+ // SessionAdvisors.session sets the same key,
MemoryAdvisor.CONVERSATION_ID, and rejects a blank id. The
+ // session advisors create the session on first use.
+ Consumer<ChatClient.AdvisorSpec> conversation = sessionMemory
+ ? SessionAdvisors.session(conversationId)
+ : a -> a.param(MemoryAdvisor.CONVERSATION_ID,
conversationId);
+ if (memoryAdvisors != null) {
+ request.advisors(memoryAdvisors);
+ }
+ request.advisors(conversation);
}
// Apply SafeGuard advisor overrides if provided via headers
@@ -1552,6 +1552,79 @@ public class SpringAiChatProducer extends
DefaultProducer {
}
}
+ /**
+ * Builds the memory advisors, which are added to a request only when it
has a conversation id. One memory is used:
+ * sessionService, else chatMemory, else chatMemoryVectorStore. None is
used when the advisors option has a memory
+ * advisor of its own.
+ *
+ * @return the memory advisors, or {@code null} when no memory is
configured
+ */
+ @SuppressWarnings({ "deprecation", "removal" })
+ private List<Advisor> buildMemoryAdvisors() {
+ SessionService sessionService =
getEndpoint().getConfiguration().getSessionService();
+ ChatMemory chatMemory =
getEndpoint().getConfiguration().getChatMemory();
+ VectorStore chatMemoryVectorStore =
getEndpoint().getConfiguration().getChatMemoryVectorStore();
+ int sessionMessageWindow =
getEndpoint().getConfiguration().getSessionMessageWindow();
+ if (sessionMessageWindow < 0) {
+ throw new IllegalArgumentException(
+ "sessionMessageWindow must be 0 (the whole session) or
more, but was " + sessionMessageWindow);
+ }
+ if (hasMemoryAdvisorInAdvisorsOption()) {
+ // the advisors option is set explicitly, while sessionService and
chatMemory are autowired in Spring Boot
+ if (sessionService != null || chatMemory != null ||
chatMemoryVectorStore != null) {
+ LOG.info("The advisors option has a memory advisor. Using it
instead of sessionService, chatMemory "
+ + "and chatMemoryVectorStore.");
+ }
+ return null;
+ }
+ if (sessionService != null) {
+ if (chatMemory != null) {
+ // a ChatMemory bean is autowired in Spring Boot, so this is
the common case once a SessionService exists
+ LOG.info("Both sessionService and chatMemory are configured.
Using session memory (sessionService).");
+ }
+ if (chatMemoryVectorStore != null) {
+ LOG.warn("Both sessionService and chatMemoryVectorStore are
configured. Using session memory "
+ + "(sessionService). Configure only one memory
type.");
+ }
+ LOG.debug("Session memory available with sessionMessageWindow={}
(activated per-request via conversationId "
+ + "header)",
+ sessionMessageWindow);
+ SessionAdvisors.Builder builder =
SessionAdvisors.builder(sessionService);
+ if (sessionMessageWindow > 0) {
+ // the default filter of the memory advisor,
EventFilter.all(), with a window that keeps turns whole.
+ // The advisor reads the active view with it, so a compacted
session stays compacted
+ EventFilter eventFilter =
EventFilter.all().toBuilder().lastN(sessionMessageWindow).build();
+ builder.memory(memory -> memory.eventFilter(eventFilter));
+ }
+ return builder.build();
+ }
+ if (chatMemory != null) {
+ if (chatMemoryVectorStore != null) {
+ LOG.warn("Both chatMemory and chatMemoryVectorStore are
configured. Using MessageChatMemoryAdvisor "
+ + "(chatMemory). Configure only one memory type.");
+ }
+ LOG.debug("MessageChatMemoryAdvisor available (activated
per-request via conversationId header)");
+ return
List.of(MessageChatMemoryAdvisor.builder(chatMemory).build());
+ }
+ if (chatMemoryVectorStore != null) {
+ LOG.debug("VectorStoreChatMemoryAdvisor available with topK={}",
getEndpoint().getConfiguration().getTopK());
+ return
List.of(VectorStoreChatMemoryAdvisor.builder(chatMemoryVectorStore)
+ .defaultTopK(getEndpoint().getConfiguration().getTopK())
+ .build());
+ }
+ return null;
+ }
+
+ /**
+ * Whether the advisors option has a memory advisor, such as the session
advisors with compaction. The advisors
+ * option is used only when the component builds the ChatClient.
+ */
+ private boolean hasMemoryAdvisorInAdvisorsOption() {
+ List<Advisor> advisors =
getEndpoint().getConfiguration().getAdvisors();
+ return getEndpoint().getConfiguration().getChatClient() == null
+ && advisors != null &&
advisors.stream().anyMatch(MemoryAdvisor.class::isInstance);
+ }
+
/**
* Build the list of default advisors based on endpoint configuration.
* <p>
@@ -1567,19 +1640,14 @@ public class SpringAiChatProducer extends
DefaultProducer {
* monitoring purposes.</li>
* <li><strong>SafeGuardAdvisor</strong> - Added if sensitive words are
configured. Blocks requests or responses
* containing configured sensitive words and returns a custom failure
response.</li>
- * <li><strong>MessageChatMemoryAdvisor</strong> - Added if ChatMemory is
configured. Maintains conversation history
- * using an in-memory or persistent chat memory store, enabling contextual
multi-turn conversations.</li>
- * <li><strong>VectorStoreChatMemoryAdvisor</strong> - Added if
chatMemoryVectorStore is configured (alternative to
- * MessageChatMemoryAdvisor). Stores conversation history in a vector
store with automatic conversation isolation by
- * ID.</li>
* <li><strong>QuestionAnswerAdvisor</strong> - Added if VectorStore is
configured. Implements RAG by automatically
* retrieving relevant context from the vector store and augmenting the
user's question with it.</li>
* <li><strong>Custom Advisors</strong> - Any user-provided advisors from
the endpoint configuration are added
* last.</li>
* </ol>
* <p>
- * <strong>Note:</strong> If both ChatMemory and chatMemoryVectorStore are
configured, only ChatMemory will be used
- * and a warning will be logged.
+ * The memory advisors are not default advisors: {@link
#buildMemoryAdvisors()} builds them, and they are added to a
+ * request only when it has a conversation id.
* </p>
*
* @return the list of configured advisors to be applied to the ChatClient
diff --git
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/SpringAiChatSessionMemoryTest.java
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/SpringAiChatSessionMemoryTest.java
new file mode 100644
index 000000000000..38ab769767ae
--- /dev/null
+++
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/SpringAiChatSessionMemoryTest.java
@@ -0,0 +1,377 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.springai.chat;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+import org.springframework.ai.chat.client.advisor.api.Advisor;
+import org.springframework.ai.chat.memory.ChatMemory;
+import org.springframework.ai.chat.memory.InMemoryChatMemoryRepository;
+import org.springframework.ai.chat.memory.MessageWindowChatMemory;
+import org.springframework.ai.chat.messages.AssistantMessage;
+import org.springframework.ai.chat.messages.Message;
+import org.springframework.ai.chat.messages.MessageType;
+import org.springframework.ai.chat.messages.ToolResponseMessage;
+import org.springframework.ai.chat.messages.UserMessage;
+import org.springframework.ai.chat.model.ChatModel;
+import org.springframework.ai.chat.model.ChatResponse;
+import org.springframework.ai.chat.model.Generation;
+import org.springframework.ai.chat.prompt.Prompt;
+import org.springframework.ai.model.tool.ToolCallingChatOptions;
+import org.springframework.ai.session.DefaultSessionService;
+import org.springframework.ai.session.InMemorySessionRepository;
+import org.springframework.ai.session.SessionService;
+import org.springframework.ai.session.advisor.SessionAdvisors;
+import org.springframework.ai.tool.annotation.Tool;
+import org.springframework.ai.tool.method.MethodToolCallbackProvider;
+import org.springframework.ai.vectorstore.VectorStore;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
+/**
+ * Session memory through the {@code sessionService} option: the {@link
SpringAiChatConstants#CONVERSATION_ID} header
+ * selects the session, and {@code sessionService} is used instead of {@code
chatMemory} and
+ * {@code chatMemoryVectorStore}. The tests capture the {@link Prompt} handed
to the {@link ChatModel}.
+ */
+@SuppressWarnings("removal")
+class SpringAiChatSessionMemoryTest extends CamelTestSupport {
+
+ private static final String TOOL_PREFIX = "Use the tool: ";
+
+ private ChatModel mockChatModel;
+ private SessionService sessionService;
+ private SessionService customSessionService;
+ private ChatMemory chatMemory;
+ private VectorStore memoryVectorStore;
+
+ @Override
+ protected void doPreSetup() throws Exception {
+ super.doPreSetup();
+
+ mockChatModel = mock(ChatModel.class);
+
when(mockChatModel.getOptions()).thenReturn(ToolCallingChatOptions.builder().build());
+ when(mockChatModel.call(any(Prompt.class))).thenAnswer(invocation -> {
+ Prompt prompt = invocation.getArgument(0);
+ Message last =
prompt.getInstructions().get(prompt.getInstructions().size() - 1);
+ if (last instanceof UserMessage user &&
user.getText().startsWith(TOOL_PREFIX)) {
+ AssistantMessage toolCall = AssistantMessage.builder()
+ .content("")
+ .toolCalls(List.of(new AssistantMessage.ToolCall(
+ "call-1", "function", "getCapital",
"{\"country\":\"France\"}")))
+ .build();
+ return new ChatResponse(List.of(new Generation(toolCall)));
+ }
+ AssistantMessage answer = new AssistantMessage("Answer to: " +
prompt.getUserMessage().getText());
+ return new ChatResponse(List.of(new Generation(answer)));
+ });
+
+ sessionService = DefaultSessionService.builder()
+ .sessionRepository(InMemorySessionRepository.builder().build())
+ .build();
+ customSessionService = DefaultSessionService.builder()
+ .sessionRepository(InMemorySessionRepository.builder().build())
+ .build();
+ chatMemory = MessageWindowChatMemory.builder()
+ .chatMemoryRepository(new InMemoryChatMemoryRepository())
+ .build();
+ memoryVectorStore = mock(VectorStore.class);
+ }
+
+ @Test
+ void sameConversationIdSendsTheFirstExchangeWithTheSecondRequest() {
+ chat("direct:session", "My name is Alice", "user-1");
+ chat("direct:session", "What is my name?", "user-1");
+
+ assertThat(prompts()).hasSize(2);
+ assertThat(prompts().get(1).getInstructions())
+ .extracting(Message::getMessageType, Message::getText)
+ .containsExactly(
+ tuple(MessageType.USER, "My name is Alice"),
+ tuple(MessageType.ASSISTANT, "Answer to: My name is
Alice"),
+ tuple(MessageType.USER, "What is my name?"));
+ assertThat(sessionService.getMessages("user-1")).hasSize(4);
+ }
+
+ @Test
+ void differentConversationIdDoesNotSeeTheOtherSession() {
+ chat("direct:session", "My name is Alice", "user-1");
+ chat("direct:session", "What is my name?", "user-2");
+
+ assertThat(prompts().get(1).getInstructions())
+ .extracting(Message::getMessageType, Message::getText)
+ .containsExactly(tuple(MessageType.USER, "What is my name?"));
+ assertThat(sessionService.getMessages("user-1")).hasSize(2);
+ assertThat(sessionService.getMessages("user-2")).hasSize(2);
+ }
+
+ @Test
+ void noConversationIdUsesNoMemory() {
+ chat("direct:session", "My name is Alice", null);
+ chat("direct:session", "What is my name?", null);
+
+ assertThat(prompts().get(1).getInstructions())
+ .extracting(Message::getMessageType, Message::getText)
+ .containsExactly(tuple(MessageType.USER, "What is my name?"));
+ }
+
+ @Test
+ void blankConversationIdFailsTheExchange() {
+ Exchange exchange = template().request("direct:session", e -> {
+ e.getIn().setBody("My name is Alice");
+ e.getIn().setHeader(SpringAiChatConstants.CONVERSATION_ID, " ");
+ });
+
+
assertThat(exchange.getException()).isInstanceOf(IllegalArgumentException.class);
+ verifyNoInteractions(mockChatModel);
+ }
+
+ @Test
+ void sessionServiceIsUsedInsteadOfChatMemory() {
+ chat("direct:sessionAndChatMemory", "My name is Alice", "user-1");
+ chat("direct:sessionAndChatMemory", "What is my name?", "user-1");
+
+ assertThat(prompts().get(1).getInstructions()).hasSize(3);
+ assertThat(sessionService.getMessages("user-1")).hasSize(4);
+ assertThat(chatMemory.get("user-1")).isEmpty();
+ }
+
+ /**
+ * As in Spring Boot with the session starter: a {@link SessionService}
and a {@link ChatMemory} bean are both
+ * autowired.
+ */
+ @Test
+ void autowiredSessionServiceIsUsedInsteadOfAutowiredChatMemory() {
+ chat("direct:autowired", "My name is Alice", "user-1");
+ chat("direct:autowired", "What is my name?", "user-1");
+
+ assertThat(prompts().get(1).getInstructions()).hasSize(3);
+ assertThat(sessionService.getMessages("user-1")).hasSize(4);
+ assertThat(chatMemory.get("user-1")).isEmpty();
+ }
+
+ @Test
+ void sessionServiceIsUsedInsteadOfChatMemoryVectorStore() {
+ chat("direct:sessionAndVectorStore", "My name is Alice", "user-1");
+ chat("direct:sessionAndVectorStore", "What is my name?", "user-1");
+
+ assertThat(prompts().get(1).getInstructions()).hasSize(3);
+ assertThat(sessionService.getMessages("user-1")).hasSize(4);
+ verifyNoInteractions(memoryVectorStore);
+ }
+
+ /**
+ * The tool-calling loop runs inside the turn: the tool round is sent
once, and the session keeps the tool call and
+ * its result.
+ */
+ @Test
+ void toolCallRoundIsKeptInTheSession() {
+ chat("direct:sessionWithTools", TOOL_PREFIX + "what is the capital of
France?", "user-1");
+
+ assertThat(prompts()).hasSize(2);
+ assertThat(prompts().get(1).getInstructions())
+ .extracting(Message::getMessageType)
+ .containsExactly(MessageType.USER, MessageType.ASSISTANT,
MessageType.TOOL);
+ assertThat(((ToolResponseMessage)
prompts().get(1).getInstructions().get(2)).getResponses().get(0).responseData())
+ .contains("Paris");
+ assertThat(sessionService.getMessages("user-1"))
+ .extracting(Message::getMessageType)
+ .containsExactly(MessageType.USER, MessageType.ASSISTANT,
MessageType.TOOL, MessageType.ASSISTANT);
+ }
+
+ @Test
+ void sessionMessageWindowSendsTheNewestTurnsAndTheSessionKeepsEverything()
{
+ chat("direct:window", "one", "user-1");
+ chat("direct:window", "two", "user-1");
+ chat("direct:window", "three", "user-1");
+
+ assertThat(prompts().get(2).getInstructions())
+ .extracting(Message::getMessageType, Message::getText)
+ .containsExactly(
+ tuple(MessageType.USER, "two"),
+ tuple(MessageType.ASSISTANT, "Answer to: two"),
+ tuple(MessageType.USER, "three"));
+ assertThat(sessionService.getMessages("user-1")).hasSize(6);
+ }
+
+ /**
+ * The newest two messages are a tool result and the reply: the window is
extended back to the user message of their
+ * turn, so the tool result is never sent without its tool call.
+ */
+ @Test
+ void sessionMessageWindowKeepsAToolRoundWhole() {
+ chat("direct:windowWithTools", TOOL_PREFIX + "what is the capital of
France?", "user-1");
+ chat("direct:windowWithTools", "And of Germany?", "user-1");
+
+ assertThat(prompts()).hasSize(3);
+ assertThat(prompts().get(2).getInstructions())
+ .extracting(Message::getMessageType)
+ .containsExactly(MessageType.USER, MessageType.ASSISTANT,
MessageType.TOOL, MessageType.ASSISTANT,
+ MessageType.USER);
+ }
+
+ @Test
+ void defaultSessionMessageWindowSendsTheNewest20Messages() {
+ for (int i = 1; i <= 12; i++) {
+ chat("direct:session", "message " + i, "user-1");
+ }
+
+ List<Message> last = prompts().get(11).getInstructions();
+ assertThat(last).hasSize(21);
+ assertThat(last.get(0).getText()).isEqualTo("message 2");
+ assertThat(sessionService.getMessages("user-1")).hasSize(24);
+ }
+
+ @Test
+ void sessionMessageWindowZeroSendsTheWholeSession() {
+ for (int i = 1; i <= 12; i++) {
+ chat("direct:wholeSession", "message " + i, "user-1");
+ }
+
+ List<Message> last = prompts().get(11).getInstructions();
+ assertThat(last).hasSize(23);
+ assertThat(last.get(0).getText()).isEqualTo("message 1");
+ }
+
+ /**
+ * Session advisors of your own, with compaction for example, passed with
the advisors option: they get the
+ * conversation id, and the autowired sessionService and chatMemory are
not used, so nothing is stored twice.
+ */
+ @Test
+ void memoryAdvisorsOfTheAdvisorsOptionGetTheConversationId() {
+ chat("direct:customAdvisors", "My name is Alice", "user-1");
+ chat("direct:customAdvisors", "What is my name?", "user-1");
+
+ assertThat(prompts().get(1).getInstructions())
+ .extracting(Message::getMessageType, Message::getText)
+ .containsExactly(
+ tuple(MessageType.USER, "My name is Alice"),
+ tuple(MessageType.ASSISTANT, "Answer to: My name is
Alice"),
+ tuple(MessageType.USER, "What is my name?"));
+ assertThat(customSessionService.getMessages("user-1")).hasSize(4);
+ assertThat(sessionService.findById("user-1")).isNull();
+ assertThat(chatMemory.get("user-1")).isEmpty();
+ }
+
+ @Test
+ void chatMemoryAloneStillKeepsTheConversation() {
+ chat("direct:chatMemory", "My name is Alice", "user-1");
+ chat("direct:chatMemory", "What is my name?", "user-1");
+
+ assertThat(prompts().get(1).getInstructions())
+ .extracting(Message::getMessageType, Message::getText)
+ .containsExactly(
+ tuple(MessageType.USER, "My name is Alice"),
+ tuple(MessageType.ASSISTANT, "Answer to: My name is
Alice"),
+ tuple(MessageType.USER, "What is my name?"));
+ assertThat(chatMemory.get("user-1")).hasSize(4);
+ assertThat(sessionService.findById("user-1")).isNull();
+ }
+
+ private void chat(String uri, String text, String conversationId) {
+ String answer = template().requestBodyAndHeader(uri, text,
SpringAiChatConstants.CONVERSATION_ID, conversationId,
+ String.class);
+ assertThat(answer).isEqualTo("Answer to: " + text);
+ }
+
+ private List<Prompt> prompts() {
+ ArgumentCaptor<Prompt> captor = ArgumentCaptor.forClass(Prompt.class);
+ verify(mockChatModel, atLeastOnce()).call(captor.capture());
+ return captor.getAllValues();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // one bean of each type, so the endpoints that keep
autowiring get them all
+ context.getRegistry().bind("chatModel", mockChatModel);
+ context.getRegistry().bind("sessionService", sessionService);
+ context.getRegistry().bind("chatMemory", chatMemory);
+
+ from("direct:session")
+
.to("spring-ai-chat:session?autowiredEnabled=false&chatModel=#chatModel"
+ + "&sessionService=#sessionService");
+
+ from("direct:sessionAndChatMemory")
+
.to("spring-ai-chat:both?autowiredEnabled=false&chatModel=#chatModel"
+ +
"&sessionService=#sessionService&chatMemory=#chatMemory");
+
+ from("direct:autowired")
+ .to("spring-ai-chat:autowired");
+
+ context.getRegistry().bind("tools",
Arrays.asList(MethodToolCallbackProvider.builder()
+ .toolObjects(new CapitalTools())
+ .build()
+ .getToolCallbacks()));
+ from("direct:sessionWithTools")
+
.to("spring-ai-chat:tools?autowiredEnabled=false&chatModel=#chatModel"
+ +
"&sessionService=#sessionService&toolCallbacks=#tools");
+
+ from("direct:windowWithTools")
+
.to("spring-ai-chat:windowTools?autowiredEnabled=false&chatModel=#chatModel"
+ +
"&sessionService=#sessionService&toolCallbacks=#tools&sessionMessageWindow=2");
+
+ from("direct:window")
+
.to("spring-ai-chat:window?autowiredEnabled=false&chatModel=#chatModel"
+ +
"&sessionService=#sessionService&sessionMessageWindow=2");
+
+ from("direct:wholeSession")
+
.to("spring-ai-chat:whole?autowiredEnabled=false&chatModel=#chatModel"
+ +
"&sessionService=#sessionService&sessionMessageWindow=0");
+
+ // autowired: the sessionService and chatMemory beans are set
too, and must not be used
+ List<Advisor> customSessionAdvisors =
SessionAdvisors.builder(customSessionService).build();
+ context.getRegistry().bind("customSessionAdvisors",
customSessionAdvisors);
+ from("direct:customAdvisors")
+
.to("spring-ai-chat:custom?advisors=#customSessionAdvisors");
+
+ from("direct:chatMemory")
+
.to("spring-ai-chat:memory?autowiredEnabled=false&chatModel=#chatModel&chatMemory=#chatMemory");
+
+ // not bound in the registry, where it would be autowired as
the RAG vectorStore
+ SpringAiChatEndpoint vectorStoreEndpoint =
getContext().getEndpoint(
+
"spring-ai-chat:vector?autowiredEnabled=false&chatModel=#chatModel&sessionService=#sessionService",
+ SpringAiChatEndpoint.class);
+
vectorStoreEndpoint.getConfiguration().setChatMemoryVectorStore(memoryVectorStore);
+ from("direct:sessionAndVectorStore")
+ .to(vectorStoreEndpoint);
+ }
+ };
+ }
+
+ public static class CapitalTools {
+
+ @Tool(description = "Get the capital city of a country")
+ public String getCapital(String country) {
+ return "The capital of " + country + " is Paris";
+ }
+ }
+}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index b31624e9d8eb..e5136556deaf 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -2891,6 +2891,33 @@ is now `null` and the `CamelSpringAiChatFinishReason`
header is `guardrailRefusa
filtered and that cannot be converted gives a `null` body too. Check the
finish reason header where the route handled
the exception.
+=== camel-spring-ai-chat - the chatMemory option is deprecated, use
sessionService
+
+Spring AI 2.1 deprecates `ChatMemory`, `MessageWindowChatMemory` and
`MessageChatMemoryAdvisor` for removal in Spring AI
+3.0, in favour of session memory. The `chatMemory` option of `spring-ai-chat`
is deprecated, and works as before. Use
+the new `sessionService` option, which takes a Spring AI `SessionService`. The
`CamelSpringAiChatConversationId` header
+selects the session, as it selected the chat memory conversation.
+
+Nothing changes at runtime unless the application has a `SessionService` bean.
The new option is autowired, and when
+both options are set, `sessionService` is used. In Spring Boot, the Spring AI
model starters create a `ChatMemory` bean,
+and `spring-ai-starter-model-session-jdbc` creates a `SessionService` bean, so
with that starter the endpoints use
+session memory. The conversations stored in a `ChatMemory` are not moved to a
session. The new `sessionMessageWindow`
+option sends the newest 20 messages of the session to the model by default, as
a `MessageWindowChatMemory` keeps the last
+20 messages by default. `0` sends the whole session.
+
+The `CamelSpringAiChatConversationId` header is now passed as the conversation
id (`MemoryAdvisor.CONVERSATION_ID`) also
+when the endpoint has no memory, so the memory advisors of the `advisors`
option and of a configured `chatClient` get it,
+and the Spring AI `ChatClient` observation records it. When the `advisors`
option has a memory advisor, such as session
+advisors with compaction, the endpoint adds no memory advisor of its own.
Before, an autowired `chatMemory` added a second
+memory advisor to the request. This check covers the `advisors` option only: a
configured `chatClient` whose default
+advisors include a memory advisor still gets the memory advisor of the
endpoint on top, as with an autowired
+`chatMemory` before, and now also when a `SessionService` bean appears, for
example with
+`spring-ai-starter-model-session-jdbc`. Pass the memory advisor with the
`advisors` option instead, or set
+`autowiredEnabled=false` on the component.
+
+A session keeps every event of the conversation, while a
`MessageWindowChatMemory` kept the last 20 messages. Expired
+sessions (60 days by default) are only removed when
`SessionService.deleteExpiredSessions` is called.
+
=== camel-spring-ai-embeddings - a List body always gives a List of vectors,
and a Map or POJO body fails
A `List` body with one text now gives a `List<float[]>` with one vector, as a
`List` of more texts does, and sets the
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SpringAiChatEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SpringAiChatEndpointBuilderFactory.java
index 0707fffe80d4..2d0f01672740 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SpringAiChatEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SpringAiChatEndpointBuilderFactory.java
@@ -552,8 +552,10 @@ public interface SpringAiChatEndpointBuilderFactory {
/**
* List of custom advisors to add to the ChatClient. These advisors
will
* be added after the built-in advisors (SimpleLogger, SafeGuard,
- * ChatMemory, QuestionAnswer) in the order they are provided in the
- * list.
+ * QuestionAnswer) in the order they are provided in the list. When the
+ * list has a memory advisor, such as the session advisors, the
endpoint
+ * adds no memory advisor of its own (sessionService, chatMemory or
+ * chatMemoryVectorStore).
*
* The option is a:
*
<code>java.util.List<org.springframework.ai.chat.client.advisor.api.Advisor></code>
type.
@@ -570,8 +572,10 @@ public interface SpringAiChatEndpointBuilderFactory {
/**
* List of custom advisors to add to the ChatClient. These advisors
will
* be added after the built-in advisors (SimpleLogger, SafeGuard,
- * ChatMemory, QuestionAnswer) in the order they are provided in the
- * list.
+ * QuestionAnswer) in the order they are provided in the list. When the
+ * list has a memory advisor, such as the session advisors, the
endpoint
+ * adds no memory advisor of its own (sessionService, chatMemory or
+ * chatMemoryVectorStore).
*
* The option will be converted to a
*
<code>java.util.List<org.springframework.ai.chat.client.advisor.api.Advisor></code>
type.
@@ -588,7 +592,9 @@ public interface SpringAiChatEndpointBuilderFactory {
/**
* ChatMemory instance for maintaining conversation history across
* requests. When provided, conversation context will be automatically
- * managed using MessageChatMemoryAdvisor.
+ * managed using MessageChatMemoryAdvisor. Deprecation note: Spring AI
+ * 2.1 deprecates ChatMemory for removal in Spring AI 3.0. Use
+ * sessionService.
*
* The option is a:
* <code>org.springframework.ai.chat.memory.ChatMemory</code> type.
@@ -598,6 +604,7 @@ public interface SpringAiChatEndpointBuilderFactory {
* @param chatMemory the value to set
* @return the dsl builder
*/
+ @Deprecated
default AdvancedSpringAiChatEndpointBuilder
chatMemory(org.springframework.ai.chat.memory.ChatMemory chatMemory) {
doSetProperty("chatMemory", chatMemory);
return this;
@@ -605,7 +612,9 @@ public interface SpringAiChatEndpointBuilderFactory {
/**
* ChatMemory instance for maintaining conversation history across
* requests. When provided, conversation context will be automatically
- * managed using MessageChatMemoryAdvisor.
+ * managed using MessageChatMemoryAdvisor. Deprecation note: Spring AI
+ * 2.1 deprecates ChatMemory for removal in Spring AI 3.0. Use
+ * sessionService.
*
* The option will be converted to a
* <code>org.springframework.ai.chat.memory.ChatMemory</code> type.
@@ -615,6 +624,7 @@ public interface SpringAiChatEndpointBuilderFactory {
* @param chatMemory the value to set
* @return the dsl builder
*/
+ @Deprecated
default AdvancedSpringAiChatEndpointBuilder chatMemory(String
chatMemory) {
doSetProperty("chatMemory", chatMemory);
return this;
@@ -623,8 +633,9 @@ public interface SpringAiChatEndpointBuilderFactory {
* VectorStore instance for maintaining conversation history using
* semantic search. When provided, conversation context will be
* automatically managed using VectorStoreChatMemoryAdvisor. This is an
- * alternative to chatMemory that uses vector embeddings for long-term
- * memory with semantic retrieval.
+ * alternative to sessionService and chatMemory that uses vector
+ * embeddings for long-term memory with semantic retrieval. When
+ * sessionService or chatMemory is set, it is used instead.
*
* The option is a:
* <code>org.springframework.ai.vectorstore.VectorStore</code> type.
@@ -642,8 +653,9 @@ public interface SpringAiChatEndpointBuilderFactory {
* VectorStore instance for maintaining conversation history using
* semantic search. When provided, conversation context will be
* automatically managed using VectorStoreChatMemoryAdvisor. This is an
- * alternative to chatMemory that uses vector embeddings for long-term
- * memory with semantic retrieval.
+ * alternative to sessionService and chatMemory that uses vector
+ * embeddings for long-term memory with semantic retrieval. When
+ * sessionService or chatMemory is set, it is used instead.
*
* The option will be converted to a
* <code>org.springframework.ai.vectorstore.VectorStore</code> type.
@@ -882,6 +894,80 @@ public interface SpringAiChatEndpointBuilderFactory {
doSetProperty("outputFormat", outputFormat);
return this;
}
+ /**
+ * The number of the newest messages of the session that sessionService
+ * sends to the model, extended back to the start of their turn, so
that
+ * a tool call is never sent without its result. The session keeps
every
+ * message. 0 sends the whole session.
+ *
+ * The option is a: <code>int</code> type.
+ *
+ * Default: 20
+ * Group: advanced
+ *
+ * @param sessionMessageWindow the value to set
+ * @return the dsl builder
+ */
+ default AdvancedSpringAiChatEndpointBuilder sessionMessageWindow(int
sessionMessageWindow) {
+ doSetProperty("sessionMessageWindow", sessionMessageWindow);
+ return this;
+ }
+ /**
+ * The number of the newest messages of the session that sessionService
+ * sends to the model, extended back to the start of their turn, so
that
+ * a tool call is never sent without its result. The session keeps
every
+ * message. 0 sends the whole session.
+ *
+ * The option will be converted to a <code>int</code> type.
+ *
+ * Default: 20
+ * Group: advanced
+ *
+ * @param sessionMessageWindow the value to set
+ * @return the dsl builder
+ */
+ default AdvancedSpringAiChatEndpointBuilder
sessionMessageWindow(String sessionMessageWindow) {
+ doSetProperty("sessionMessageWindow", sessionMessageWindow);
+ return this;
+ }
+ /**
+ * Spring AI SessionService for keeping the conversation history across
+ * requests, in a session. The CamelSpringAiChatConversationId header
+ * selects the session, which is created on first use. Without the
+ * header, no memory is used. When it is set, sessionService is used
+ * instead of chatMemory and chatMemoryVectorStore.
+ *
+ * The option is a:
+ * <code>org.springframework.ai.session.SessionService</code> type.
+ *
+ * Group: advanced
+ *
+ * @param sessionService the value to set
+ * @return the dsl builder
+ */
+ default AdvancedSpringAiChatEndpointBuilder
sessionService(org.springframework.ai.session.SessionService sessionService) {
+ doSetProperty("sessionService", sessionService);
+ return this;
+ }
+ /**
+ * Spring AI SessionService for keeping the conversation history across
+ * requests, in a session. The CamelSpringAiChatConversationId header
+ * selects the session, which is created on first use. Without the
+ * header, no memory is used. When it is set, sessionService is used
+ * instead of chatMemory and chatMemoryVectorStore.
+ *
+ * The option will be converted to a
+ * <code>org.springframework.ai.session.SessionService</code> type.
+ *
+ * Group: advanced
+ *
+ * @param sessionService the value to set
+ * @return the dsl builder
+ */
+ default AdvancedSpringAiChatEndpointBuilder sessionService(String
sessionService) {
+ doSetProperty("sessionService", sessionService);
+ return this;
+ }
/**
* A StructuredOutputConverter for converting the chat response to
* structured output (e.g., BeanOutputConverter, MapOutputConverter,
@@ -1603,8 +1689,10 @@ public interface SpringAiChatEndpointBuilderFactory {
return "CamelSpringAiChatSystemMetadata";
}
/**
- * Conversation ID for managing separate conversation contexts in chat
- * memory.
+ * The conversation ID. It selects the session (sessionService) or the
+ * conversation (chatMemory, chatMemoryVectorStore), and is passed to
+ * every memory advisor, also to those of the advisors option or of a
+ * configured chatClient. Session advisors require it.
*
* The option is a: {@code String} type.
*