Skip to content

Commit a45ea02

Browse files
committed
fix: #4333 added special warning for the case of changed tools names
Signed-off-by: ashakirin <[email protected]>
1 parent c2103b0 commit a45ea02

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);
@@ -207,6 +212,7 @@ private InternalToolExecutionResult executeToolCall(Prompt prompt, AssistantMess
207212
.orElseGet(() -> this.toolCallbackResolver.resolve(toolName));
208213

209214
if (toolCallback == null) {
215+
logger.warn(POSSIBLE_LLM_TOOL_NAME_CHANGE_WARNING, toolName);
210216
throw new IllegalStateException("No ToolCallback found for tool name: " + toolName);
211217
}
212218

0 commit comments

Comments
 (0)