You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 096f140
Browse filesBrowse the repository at this point in the historyBrowse files
Introduce a `spring.ai.tools.resolution.fallback.enabled` property
(and a matching `resolutionFallbackEnabled` builder switch on
`DefaultToolCallingManager`) that controls whether a tool absent from
a request's tool callbacks may be resolved by name through the
`ToolCallbackResolver` and executed.
The fallback is disabled by default, so the tools attached to a
request are the only ones executable for it.
Closes#6751
Signed-off-by: Dimitar Proynov <[email protected]>
Copy file name to clipboardExpand all lines: auto-configurations/models/tool/spring-ai-autoconfigure-model-tool/src/main/java/org/springframework/ai/model/tool/autoconfigure/ToolCallingAutoConfiguration.java
Copy file name to clipboardExpand all lines: auto-configurations/models/tool/spring-ai-autoconfigure-model-tool/src/main/java/org/springframework/ai/model/tool/autoconfigure/ToolCallingProperties.java
Copy file name to clipboardExpand all lines: auto-configurations/models/tool/spring-ai-autoconfigure-model-tool/src/test/java/org/springframework/ai/model/tool/autoconfigure/ToolCallingAutoConfigurationTests.java
Copy file name to clipboardExpand all lines: models/spring-ai-google-genai/src/test/java/org/springframework/ai/google/genai/schema/GoogleGenAiToolCallingManagerTests.java
The resolver is used internally by `ToolCallingManager` to support both xref:#the-tool-calling-loop[advisor-controlled execution] and xref:#user-controlled-tool-execution[user-controlled execution].
892
892
893
+
To enable the behavior — where a tool known to the resolver, but not attached to the request may be resolved by name and executed — enable the resolution fallback:
894
+
895
+
[source,properties]
896
+
----
897
+
spring.ai.tools.resolution.fallback.enabled=true
898
+
----
899
+
900
+
[cols="6,3,1", stripes=even]
901
+
|====
902
+
| Property | Description | Default
903
+
| `spring.ai.tools.resolution.fallback.enabled` | If `true`, a requested tool that is absent from the request's tool callbacks may be resolved by name through the `ToolCallbackResolver` and executed. If `false`, only the tools attached to the request can be executed. | `false`
904
+
|====
905
+
906
+
When constructing a `ToolCallingManager` directly, the same switch is available on the builder via `.resolutionFallbackEnabled(true)` (default `false`).
907
+
908
+
WARNING: Enabling the resolution fallback makes every tool reachable through the resolver executable whenever the model names it, regardless of what a request attached — including risk-tier and destructive tools. Enable it only when you fully control which tools the resolver exposes.
The fallback that resolves and executes tools registered as beans, but not attached to a request has been disabled by default.
308
+
Previously, when the model returned a tool call for a tool that was not attached to the request, `DefaultToolCallingManager` fell back to the application-wide `ToolCallbackResolver` (backed by every `ToolCallback` bean in the application context) and executed the resolved tool.
309
+
Starting with 2.0.1, the tools attached to a request — via `.tools(...)`, `.defaultTools(...)`, or `ToolCallingChatOptions.toolCallbacks(...)` — are the only tools that can be executed for that request.
310
+
311
+
To restore the previous behavior, re-enable the resolution fallback:
312
+
313
+
[source,properties]
314
+
----
315
+
spring.ai.tools.resolution.fallback.enabled=true
316
+
----
317
+
318
+
When constructing a `ToolCallingManager` directly, use the builder switch instead:
= "', especially if the name was truncated due to length limits. If this is the case, you can customize the prefixing and processing logic using McpToolNamePrefixGenerator";
@@ -111,17 +114,44 @@ public final class DefaultToolCallingManager implements ToolCallingManager {
111
114
112
115
privatefinalToolCallLimitstoolCallLimits;
113
116
117
+
/**
118
+
* Whether a call to a tool that is not part of the request's tool callbacks may still
119
+
* be executed by resolving it through the {@link ToolCallbackResolver}. When
120
+
* {@code false} (the default), the tools attached to the request are the only tools
0 commit comments