Add breaking changes to 1.0 M8 upgrade notes regarding chatclient too… · spring-projects/spring-ai@5b7849d (original) (raw)

`@@ -25,30 +25,80 @@ For details, refer to:

`

25

25

`- xref:upgrade-notes.adoc#common-package-changes[Common Package Changes]

`

26

26

`- xref:upgrade-notes.adoc#common-module-structure[Common Module Structure]

`

27

27

``

28

``

`-

[[automating-upgrading-using-ai]]

`

29

``

`-

=== Automating upgrading using AI

`

``

28

`+

[[upgrading-to-1-0-0-m8]]

`

``

29

`+

== Upgrading to 1.0.0-M8

`

30

30

``

31

``

`-

You can automate the upgrade process to 1.0.0-SNAPSHOT using the Claude Code CLI tool with a provided prompt. The prompt will guide the AI to perform the following tasks:

`

``

31

`+

You can automate the upgrade process to 1.0.0-M8 using an OpenRewrite recipe.

`

``

32

`+

This recipe helps apply many of the necessary code changes for this version.

`

``

33

`+

Find the recipe and usage instructions at https://github.com/arconia-io/arconia-migrations/blob/main/docs/spring-ai.md[Arconia Spring AI Migrations].

`

32

34

``

33

``

`-

  1. Update the Spring AI BOM version to 1.0.0-SNAPSHOT

`

34

``

`-

  1. Ensure all required repositories exist in your build configuration

`

35

``

`-

  1. Update Spring AI artifact IDs according to the new naming patterns

`

``

35

`+

=== Breaking Changes

`

``

36

`` +

When upgrading from Spring AI 1.0 M7 to 1.0 M8, users who previously registered tool callbacks are encountering breaking changes that cause tool calling functionality to silently fail. This is specifically impacting code that used the deprecated tools() method.

``

36

37

``

37

``

`-

To use this automation:

`

``

38

`+

==== Example

`

38

39

``

39

``

`-

  1. Download the https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview[Claude Code CLI tool]

`

40

``

`-

  1. Copy the prompt from the https://github.com/spring-projects/spring-ai/blob/main/src/prompts/update-to-snapshot.txt[update-to-snapshot.txt] file

`

41

``

`-

  1. Paste the prompt into the Claude Code CLI

`

42

``

`-

  1. The AI will analyze your project and make the necessary changes

`

``

40

`+

Here's an example of code that worked in M7 but no longer functions as expected in M8:

`

43

41

``

44

``

`-

This approach can save time and reduce the chance of errors when upgrading multiple projects or complex codebases.

`

``

42

`+

[source,java]

`

``

43

`+


`

``

44

`+

// Old code in M7 - no longer works correctly in M8

`

``

45

`+

chatClient.prompt("What day is tomorrow?")

`

``

46

`+

.tools(toolCallback)

`

``

47

`+

.call()

`

``

48

`+

.content();

`

``

49

`+


`

``

50

+

``

51

`+

==== How to Adapt Your Code

`

``

52

+

``

53

`` +

To fix this issue when upgrading to M8, you need to update your code to use the new toolCallbacks() method:

``

``

54

+

``

55

`+

[source,java]

`

``

56

`+


`

``

57

`+

// Updated code for M8

`

``

58

`+

chatClient.prompt("What day is tomorrow?")

`

``

59

`+

.toolCallbacks(toolCallback)

`

``

60

`+

.call()

`

``

61

`+

.content();

`

``

62

`+


`

``

63

+

``

64

`+

==== Why This Change Was Made

`

``

65

+

``

66

`` +

The Spring AI team renamed the overloaded tools() methods to improve clarity and prevent ambiguity in method dispatching. The previous API design led to confusion when the Java compiler needed to select between multiple overloaded methods based on parameter types.

``

``

67

+

``

68

`+

==== Method Mapping from M7 to M8

`

``

69

+

``

70

`+

Here's how the old methods map to their new counterparts:

`

``

71

+

``

72

`` +

  1. tools(String... toolNames)toolNames(String... toolNames)

``

``

73

`` +

``

``

74

+

``

75

`` +

  1. tools(ToolCallback... toolCallbacks)toolCallbacks(ToolCallback... toolCallbacks)

``

``

76

`+

`

``

77

+

``

78

`` +

  1. tools(List<ToolCallback> toolCallbacks)toolCallbacks(List<ToolCallback> toolCallbacks)

``

``

79

`+

`

``

80

+

``

81

`` +

  1. tools(ToolCallbackProvider... toolCallbackProviders)toolCallbacks(ToolCallbackProvider... toolCallbackProviders)

``

``

82

`` +

``

``

83

+

``

84

`` +

  1. tools(Object... toolObjects) remains unchanged

``

``

85

`` +

``

``

86

+

``

87

`+

==== Improved Error Handling

`

``

88

+

``

89

`` +

In the https://github.com/spring-projects/spring-ai/pull/2964[this PR now merged (spring-projects/spring-ai#2964)], the tools(Object... toolObjects) method will now throw an exception when no @Tool methods are found on the provided objects, rather than silently failing. This helps developers identify migration issues immediately.

``

``

90

+

``

91

`+

==== Migration Summary

`

``

92

+

``

93

`+

If you're upgrading from M7 to M8:

`

``

94

+

``

95

`` +

  1. Replace all calls to .tools(toolCallback) with .toolCallbacks(toolCallback)

``

``

96

`` +

  1. Replace all calls to .tools(toolCallbackProvider) with .toolCallbacks(toolCallbackProvider)

``

``

97

`` +

  1. Replace all calls to .tools("toolName") with .toolNames("toolName")

``

``

98

+

``

99

`+

These changes will ensure your tool calling functionality continues to work correctly after upgrading to Spring AI 1.0 M8.

`

45

100

``

46

``

`-

[[upgrading-to-1-0-0-m8]]

`

47

``

`-

== Upgrading to 1.0.0-M8

`

48

101

``

49

``

`-

You can automate the upgrade process to 1.0.0-M8 using an OpenRewrite recipe.

`

50

``

`-

This recipe helps apply many of the necessary code changes for this version.

`

51

``

`-

Find the recipe and usage instructions at https://github.com/arconia-io/arconia-migrations/blob/main/docs/spring-ai.md[Arconia Spring AI Migrations].

`

52

102

``

53

103

`=== Chat Client

`

54

104

``