executeTool static method
Execute a tool call manually.
toolCall The tool call to execute
Returns ToolResult with success/failure and result data
Implementation
static Future<ToolResult> executeTool(ToolCall toolCall) async {
final executor = _toolExecutors[toolCall.toolName];
if (executor == null) {
return ToolResult(
toolName: toolCall.toolName,
success: false,
error: 'Tool not found: ${toolCall.toolName}',
callId: toolCall.callId,
);
}
try {
_logger.debug('Executing tool: ${toolCall.toolName}');
final result = await executor(toolCall.arguments);
_logger.debug('Tool ${toolCall.toolName} completed successfully');
return ToolResult(
toolName: toolCall.toolName,
success: true,
result: result,
callId: toolCall.callId,
);
} catch (e) {
_logger.error('Tool ${toolCall.toolName} failed: $e');
return ToolResult(
toolName: toolCall.toolName,
success: false,
error: e.toString(),
callId: toolCall.callId,
);
}
}