Class AiOrchestrator.Reconnector
- Enclosing class:
AiOrchestrator
AiOrchestrator after deserialization. Obtain an instance via
AiOrchestrator.reconnect(LlmProvider).
The provider is specified when the reconnector is created. Optional
transient dependencies (controller and file attachments) can be restored
via chained methods before calling apply(). The apply()
call replays the existing conversation history onto the new provider but
does not modify the UI.
orchestrator.reconnect(provider).withController(controller) // optional
.withAttachments(attachmentsByMsgId) // optional
.apply();
-
Method Summary
Modifier and TypeMethodDescriptionvoidapply()Applies the reconnection, restoring the provider, tools, and conversation history on the new provider.withAttachments(Map<String, List<AiAttachment>> attachmentsByMessageId) Sets the file attachments to restore on the new provider's conversation memory.withController(AiController controller) Sets the controller to use after reconnection.Deprecated.
-
Method Details
-
withTools
Deprecated.Register the tool objects with the vendor framework when you create the new provider instead: add them to theChatClientthat you pass toSpringAiLlmProvider(ChatClient), or in the customizer ofLangChain4jLlmProvider. The description of this method shows both. There, too, the vendor framework handles their errors.Sets the objects containing vendor-specific tool-annotated methods that will be available to the LLM.The vendor framework runs these tools, so it handles an exception that a tool throws with its own defaults, not as described in
ToolException. By default, the raw message of the exception may be sent to the LLM. See the vendor documentation for how to send the LLM a message that is safe for it to see, such as LangChain4j'sToolErrorVisibleToLlmException.Instead of this method, register the tool objects with the vendor framework when you create the new provider. For Spring AI, add them to a
ChatClientand createSpringAiLlmProviderwith that client:var chatClient = ChatClient.builder(chatModel).defaultTools(tools).build(); var provider = new SpringAiLlmProvider(chatClient);
For LangChain4j, add them in the customizer of
LangChain4jLlmProvider:var provider = new LangChain4jLlmProvider(chatModel, service -> service.tools(tools));- Parameters:
tools- the objects containing tool methods- Returns:
- this reconnector
-
withController
Sets the controller to use after reconnection.- Parameters:
controller- the controller to use, notnull- Returns:
- this reconnector
- Throws:
IllegalArgumentException- if any tool name or parameters schema is invalid
-
withAttachments
public AiOrchestrator.Reconnector withAttachments(Map<String, List<AiAttachment>> attachmentsByMessageId) Sets the file attachments to restore on the new provider's conversation memory. The map is keyed byChatMessage.messageId()and contains the list ofAiAttachmentobjects for each message.Attachments are not stored in the orchestrator's conversation history. If the application persisted attachment data via
RequestListenerbefore serialization, pass it here so the new provider can reconstruct multimodal context. PassCollections.emptyMap()(the default) if there are no attachments to restore.The UI is not affected by this method; attachment thumbnails in the message list are preserved across serialization automatically.
- Parameters:
attachmentsByMessageId- a map from message ID to attachment list- Returns:
- this reconnector
-
apply
public void apply()Applies the reconnection, restoring the provider, tools, and conversation history on the new provider. The existing conversation history is replayed onto the new provider's memory so that it has full context for subsequent prompts. A provider that manages its conversation memory outside the orchestrator ignores the replay, in which case the application must restore that memory itself before passing the provider in.The UI (message list, input, file receiver) is not modified -- those components survive serialization and retain their state automatically. The exception is that submitting is enabled again on the input if the orchestrator disabled it, so call this method while the session is locked.
-
ChatClientthat you pass toSpringAiLlmProvider(ChatClient), or in the customizer ofLangChain4jLlmProvider.