Skip to content

Commit ab0debe

Browse files
committed
feat: add informative logging to synchronous tool execution
Improvements to synchronous executeToolCalls() method: 1. Enhanced execution log: - Changed: 'Executing tool call: {}' - To: 'Executing tool call: {} (synchronous mode)' - Purpose: Clearly indicate the execution mode 2. Added performance awareness log: - When an AsyncToolCallback is executed synchronously - Log message suggests using executeToolCallsAsync() for better performance - Helps users identify optimization opportunities Benefits: ✅ Users can easily distinguish sync vs async execution ✅ Performance optimization opportunities are visible ✅ Consistent logging between sync and async methods ✅ Helps with debugging and performance tuning Example logs: DEBUG - Executing tool call: weatherTool (synchronous mode) DEBUG - Tool 'weatherTool' implements AsyncToolCallback but executing in synchronous mode. Consider using executeToolCallsAsync() for better performance. All 18 tests in DefaultToolCallingManagerTests passed. Related: #async-tool-support Signed-off-by: shaojie <741047428@qq.com>
1 parent c69db6b commit ab0debe

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ private InternalToolExecutionResult executeToolCall(Prompt prompt, AssistantMess
226226

227227
for (AssistantMessage.ToolCall toolCall : assistantMessage.getToolCalls()) {
228228

229-
logger.debug("Executing tool call: {}", toolCall.name());
230-
231229
String toolName = toolCall.name();
230+
231+
logger.debug("Executing tool call: {} (synchronous mode)", toolName);
232232
String toolInputArguments = toolCall.arguments();
233233

234234
// Handle the possible null parameter situation in streaming mode.
@@ -252,6 +252,12 @@ private InternalToolExecutionResult executeToolCall(Prompt prompt, AssistantMess
252252
throw new IllegalStateException("No ToolCallback found for tool name: " + toolName);
253253
}
254254

255+
// Log tool type information for performance awareness
256+
if (toolCallback instanceof AsyncToolCallback) {
257+
logger.debug("Tool '{}' implements AsyncToolCallback but executing in synchronous mode. "
258+
+ "Consider using executeToolCallsAsync() for better performance.", toolName);
259+
}
260+
255261
if (returnDirect == null) {
256262
returnDirect = toolCallback.getToolMetadata().returnDirect();
257263
}

0 commit comments

Comments
 (0)