Skip to content

Commit 3e17e16

Browse files
ilayaperumalgmarkpollack
authored andcommitted
fix: Handling default implementation of ToolCallback#call(String,ToolContext)
Context: Currently, the default implementation of ToolCallback#call(String,ToolContext) throws exception when an non-empty ToolContext is passed. This gives bad user experience when the application has multiple tool callbacks with one of them doesn't use toolcontext but the chat client passes non-empty toolcontext. For more information ##3389 - This fix removes the explicit exception when the toolcontext is non empty for the default implementation of call(String, ToolContext) - Instead, log info message that tool context will be ignored Auto-cherry-pick to 1.0.x Fixes #3389 Signed-off-by: Ilayaperumal Gopinathan <[email protected]>
1 parent 9442c35 commit 3e17e16

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

spring-ai-model/src/main/java/org/springframework/ai/tool/ToolCallback.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package org.springframework.ai.tool;
1818

19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
21+
1922
import org.springframework.ai.chat.model.ToolContext;
2023
import org.springframework.ai.tool.definition.ToolDefinition;
2124
import org.springframework.ai.tool.metadata.ToolMetadata;
@@ -29,6 +32,8 @@
2932
*/
3033
public interface ToolCallback {
3134

35+
Logger logger = LoggerFactory.getLogger(ToolCallback.class);
36+
3237
/**
3338
* Definition used by the AI model to determine when and how to call the tool.
3439
*/
@@ -53,7 +58,9 @@ default ToolMetadata getToolMetadata() {
5358
*/
5459
default String call(String toolInput, @Nullable ToolContext toolContext) {
5560
if (toolContext != null && !toolContext.getContext().isEmpty()) {
56-
throw new UnsupportedOperationException("Tool context is not supported!");
61+
logger.info("By default the tool context is not used, "
62+
+ "override the method 'call(String toolInput, ToolContext toolcontext)' to support the use of tool context."
63+
+ "Review the ToolCallback implementation for {}", getToolDefinition().name());
5764
}
5865
return call(toolInput);
5966
}

0 commit comments

Comments
 (0)