|
|
|
@ -26,6 +26,8 @@ export class ToolCallingStage extends BasePipelineStage<ToolExecutionInput, { re
|
|
|
|
log.info(`========== TOOL CALLING STAGE ENTRY ==========`);
|
|
|
|
log.info(`========== TOOL CALLING STAGE ENTRY ==========`);
|
|
|
|
log.info(`Response provider: ${response.provider}, model: ${response.model || 'unknown'}`);
|
|
|
|
log.info(`Response provider: ${response.provider}, model: ${response.model || 'unknown'}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info(`LLM requested ${response.tool_calls?.length || 0} tool calls from provider: ${response.provider}`);
|
|
|
|
|
|
|
|
|
|
|
|
// Check if the response has tool calls
|
|
|
|
// Check if the response has tool calls
|
|
|
|
if (!response.tool_calls || response.tool_calls.length === 0) {
|
|
|
|
if (!response.tool_calls || response.tool_calls.length === 0) {
|
|
|
|
// No tool calls, return original response and messages
|
|
|
|
// No tool calls, return original response and messages
|
|
|
|
@ -34,8 +36,6 @@ export class ToolCallingStage extends BasePipelineStage<ToolExecutionInput, { re
|
|
|
|
return { response, needsFollowUp: false, messages };
|
|
|
|
return { response, needsFollowUp: false, messages };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.info(`LLM requested ${response.tool_calls.length} tool calls from provider: ${response.provider}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Log response details for debugging
|
|
|
|
// Log response details for debugging
|
|
|
|
if (response.text) {
|
|
|
|
if (response.text) {
|
|
|
|
log.info(`Response text: "${response.text.substring(0, 200)}${response.text.length > 200 ? '...' : ''}"`);
|
|
|
|
log.info(`Response text: "${response.text.substring(0, 200)}${response.text.length > 200 ? '...' : ''}"`);
|
|
|
|
@ -45,6 +45,12 @@ export class ToolCallingStage extends BasePipelineStage<ToolExecutionInput, { re
|
|
|
|
const availableTools = toolRegistry.getAllTools();
|
|
|
|
const availableTools = toolRegistry.getAllTools();
|
|
|
|
log.info(`Available tools in registry: ${availableTools.length}`);
|
|
|
|
log.info(`Available tools in registry: ${availableTools.length}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Log available tools for debugging
|
|
|
|
|
|
|
|
if (availableTools.length > 0) {
|
|
|
|
|
|
|
|
const availableToolNames = availableTools.map(t => t.definition.function.name).join(', ');
|
|
|
|
|
|
|
|
log.info(`Available tools: ${availableToolNames}`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (availableTools.length === 0) {
|
|
|
|
if (availableTools.length === 0) {
|
|
|
|
log.error(`No tools available in registry, cannot execute tool calls`);
|
|
|
|
log.error(`No tools available in registry, cannot execute tool calls`);
|
|
|
|
// Try to initialize tools as a recovery step
|
|
|
|
// Try to initialize tools as a recovery step
|
|
|
|
@ -70,8 +76,12 @@ export class ToolCallingStage extends BasePipelineStage<ToolExecutionInput, { re
|
|
|
|
|
|
|
|
|
|
|
|
// Execute each tool call and add results to messages
|
|
|
|
// Execute each tool call and add results to messages
|
|
|
|
log.info(`========== STARTING TOOL EXECUTION ==========`);
|
|
|
|
log.info(`========== STARTING TOOL EXECUTION ==========`);
|
|
|
|
|
|
|
|
log.info(`Executing ${response.tool_calls.length} tool calls in parallel`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const executionStartTime = Date.now();
|
|
|
|
const toolResults = await Promise.all(response.tool_calls.map(async (toolCall, index) => {
|
|
|
|
const toolResults = await Promise.all(response.tool_calls.map(async (toolCall, index) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
log.info(`========== TOOL CALL ${index + 1} OF ${response.tool_calls.length} ==========`);
|
|
|
|
log.info(`Tool call ${index + 1} received - Name: ${toolCall.function.name}, ID: ${toolCall.id || 'unknown'}`);
|
|
|
|
log.info(`Tool call ${index + 1} received - Name: ${toolCall.function.name}, ID: ${toolCall.id || 'unknown'}`);
|
|
|
|
|
|
|
|
|
|
|
|
// Log parameters
|
|
|
|
// Log parameters
|
|
|
|
@ -176,6 +186,10 @@ export class ToolCallingStage extends BasePipelineStage<ToolExecutionInput, { re
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const totalExecutionTime = Date.now() - executionStartTime;
|
|
|
|
|
|
|
|
log.info(`========== TOOL EXECUTION COMPLETE ==========`);
|
|
|
|
|
|
|
|
log.info(`Completed execution of ${toolResults.length} tools in ${totalExecutionTime}ms`);
|
|
|
|
|
|
|
|
|
|
|
|
// Add tool results as messages
|
|
|
|
// Add tool results as messages
|
|
|
|
toolResults.forEach(result => {
|
|
|
|
toolResults.forEach(result => {
|
|
|
|
// Format the result content based on type
|
|
|
|
// Format the result content based on type
|
|
|
|
|