Skip to content

Commit 35328b3

Browse files
ashakirinericbottard
authored andcommitted
fix: #4333 added special warning for the case of changed tools names
Signed-off-by: ashakirin <[email protected]>
1 parent d0c9e86 commit 35328b3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public final class DefaultToolCallingManager implements ToolCallingManager {
7272
private static final ToolExecutionExceptionProcessor DEFAULT_TOOL_EXECUTION_EXCEPTION_PROCESSOR
7373
= DefaultToolExecutionExceptionProcessor.builder().build();
7474

75+
private static final String POSSIBLE_LLM_TOOL_NAME_CHANGE_WARNING
76+
= "LLM may have adapted the tool name '{}', 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";
77+
78+
7579
// @formatter:on
7680

7781
private final ObservationRegistry observationRegistry;
@@ -109,6 +113,7 @@ public List<ToolDefinition> resolveToolDefinitions(ToolCallingChatOptions chatOp
109113
}
110114
ToolCallback toolCallback = this.toolCallbackResolver.resolve(toolName);
111115
if (toolCallback == null) {
116+
logger.warn(POSSIBLE_LLM_TOOL_NAME_CHANGE_WARNING, toolName);
112117
throw new IllegalStateException("No ToolCallback found for tool name: " + toolName);
113118
}
114119
toolCallbacks.add(toolCallback);
@@ -210,6 +215,7 @@ private InternalToolExecutionResult executeToolCall(Prompt prompt, AssistantMess
210215
.orElseGet(() -> this.toolCallbackResolver.resolve(toolName));
211216

212217
if (toolCallback == null) {
218+
logger.warn(POSSIBLE_LLM_TOOL_NAME_CHANGE_WARNING, toolName);
213219
throw new IllegalStateException("No ToolCallback found for tool name: " + toolName);
214220
}
215221

0 commit comments

Comments
 (0)