Skip to content

feat: allow history restore with Spring AI ChatClient (#9972) (CP: 25.3) - #9994

Merged
tomivirkki merged 1 commit into
25.3from
cherry-pick-9972-to-25.3-1788166185177
Aug 31, 2026
Merged

tomivirkki merged 1 commit into
25.3from
cherry-pick-9972-to-25.3-1788166185177

Conversation

@vaadin-bot

Copy link
Copy Markdown
Collaborator

This PR cherry-picks changes from the original PR #9972 to branch 25.3.

Original PR description

Description

The ChatClient constructor exists for applications that need more control than the ChatModel one gives — their own chat memory, advisors, or model configuration. Restoring a saved conversation was refused on exactly that path, so an application could have its own client or its conversation history, but not both.

  • SpringAILLMProvider.setHistory(List, Map) no longer throws UnsupportedOperationException when the provider was created with the ChatClient constructor. The application owns the chat memory on that path and loads it before passing the client in, so the call returns instead of aborting.
  • Previously the throw failed AIOrchestrator.Builder.withHistory(List, Map) and reconnect(LLMProvider) outright, so the message list, the attachment id mappings and the getHistory() snapshot were left unrestored as well — none of which depend on the provider.
  • Added a warning when the given ChatClient cannot hold the conversation being restored: either it carries no chat memory advisor, or its memory advisor has no default ChatMemory.CONVERSATION_ID parameter, which makes every prompt fail inside the advisor.
  • Read through ChatClient.prompt() and the public getters on DefaultChatClientRequestSpec; a client that is not Spring AI's own implementation is left alone, since it may carry the conversation its own way.
  • Corrected the withHistory, reconnect and Reconnector.apply Javadoc, which stated that conversation history is always replayed onto the new provider.
  • Added tests for the no-op restore, a preloaded ChatMemory reaching the model, both warnings, the uninspectable-client branch, and that neither warning falls through into a second log line.

Type of change

  • Feature/bugfix

## Description

The `ChatClient` constructor exists for applications that need more
control than the `ChatModel` one gives — their own chat memory,
advisors, or model configuration. Restoring a saved conversation was
refused on exactly that path, so an application could have its own
client or its conversation history, but not both.

- `SpringAILLMProvider.setHistory(List, Map)` no longer throws
`UnsupportedOperationException` when the provider was created with the
`ChatClient` constructor. The application owns the chat memory on that
path and loads it before passing the client in, so the call returns
instead of aborting.
- Previously the throw failed `AIOrchestrator.Builder.withHistory(List,
Map)` and `reconnect(LLMProvider)` outright, so the message list, the
attachment id mappings and the `getHistory()` snapshot were left
unrestored as well — none of which depend on the provider.
- Added a warning when the given `ChatClient` cannot hold the
conversation being restored: either it carries no chat memory advisor,
or its memory advisor has no default `ChatMemory.CONVERSATION_ID`
parameter, which makes every prompt fail inside the advisor.
- Read through `ChatClient.prompt()` and the public getters on
`DefaultChatClientRequestSpec`; a client that is not Spring AI's own
implementation is left alone, since it may carry the conversation its
own way.
- Corrected the `withHistory`, `reconnect` and `Reconnector.apply`
Javadoc, which stated that conversation history is always replayed onto
the new provider.
- Added tests for the no-op restore, a preloaded `ChatMemory` reaching
the model, both warnings, the uninspectable-client branch, and that
neither warning falls through into a second log line.

## Type of change

- Feature/bugfix

---------

Co-authored-by: Claude <noreply@anthropic.com>
@tomivirkki
tomivirkki merged commit 10ce6e2 into 25.3 Aug 31, 2026
15 of 16 checks passed
@tomivirkki
tomivirkki deleted the cherry-pick-9972-to-25.3-1788166185177 branch August 31, 2026 08:55
@sonarqubecloud

Copy link
Copy Markdown

@vaadin-bot

Copy link
Copy Markdown
Collaborator Author

This ticket/PR has been released with Vaadin 25.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants