Skip to content

Improve ChatClient tools API type safety and deprecate tools(Object...) - #6275

Closed
tzolov wants to merge 1 commit into
spring-projects:mainfrom
tzolov:chat-client-tools-api-improvements
Closed

tzolov wants to merge 1 commit into
spring-projects:mainfrom
tzolov:chat-client-tools-api-improvements

Conversation

@tzolov

@tzolov tzolov commented Jun 3, 2026

Copy link
Copy Markdown
Contributor
  • Deprecate ChatClientRequestSpec.tools(Object...) and Builder.defaultTools(Object...) in favour of the Consumer form: tools(t -> t.instances(...))
  • Add assertNoToolCallbackInstances() guard in DefaultChatClient that throws IllegalArgumentException early when a ToolCallback, ToolCallbackProvider, or a Collection/array containing them is passed to tools(Object...) or ToolSpec.instances(), replacing a confusing delayed failure deep in MethodToolCallbackProvider
  • Change MethodToolCallbackProvider.assertToolAnnotatedMethodsPresent() to throw IllegalArgumentException (was IllegalStateException) and include the fully qualified class name in the message
  • Add seven unit tests in DefaultChatClientTests covering the new guard
  • Update MethodToolCallbackProviderTests to match the new exception type and message
  • Migrate all deprecated tools(Object...) call sites in integration and model tests to tools(t -> t.instances(...))
  • Update reference documentation (tools.adoc, chatclient.adoc, upgrade-notes.adoc, tools-migration.adoc, bedrock-converse.adoc, google-genai-chat.adoc, llm-as-judge.adoc) to use the non-deprecated form and document all breaking changes under the 2.0.0-RC1 upgrade notes
  • Add Javadoc to all ChatClient.ToolSpec methods

Related to #6206

- Deprecate ChatClientRequestSpec.tools(Object...) and Builder.defaultTools(Object...)
  in favour of the Consumer<ToolSpec> form: tools(t -> t.instances(...))
- Add assertNoToolCallbackInstances() guard in DefaultChatClient that throws
  IllegalArgumentException early when a ToolCallback, ToolCallbackProvider,
  or a Collection/array containing them is passed to tools(Object...) or
  ToolSpec.instances(), replacing a confusing delayed failure deep in
  MethodToolCallbackProvider
- Change MethodToolCallbackProvider.assertToolAnnotatedMethodsPresent() to throw
  IllegalArgumentException (was IllegalStateException) and include the fully
  qualified class name in the message
- Add seven unit tests in DefaultChatClientTests covering the new guard
- Update MethodToolCallbackProviderTests to match the new exception type and message
- Migrate all deprecated tools(Object...) call sites in integration and model tests
  to tools(t -> t.instances(...))
- Update reference documentation (tools.adoc, chatclient.adoc, upgrade-notes.adoc,
  tools-migration.adoc, bedrock-converse.adoc, google-genai-chat.adoc,
  llm-as-judge.adoc) to use the non-deprecated form and document all breaking changes
  under the 2.0.0-RC1 upgrade notes
- Add Javadoc to all ChatClient.ToolSpec methods

Related to spring-projects#6206

Signed-off-by: Christian Tzolov <[email protected]>
@tzolov tzolov added this to the 2.0.0-RC1 milestone Jun 3, 2026
@sdeleuze
sdeleuze self-requested a review June 3, 2026 12:20
@tzolov tzolov removed this from the 2.0.0-RC1 milestone Jun 3, 2026
@tzolov

tzolov commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

we've decided to explore a different more flexible approach.
Closing this PR

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants