From 08b8ae120ecaf282ec2ca91f59569cd32990a374 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Mon, 10 Jun 2024 22:01:52 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20fix(Assistants):=20Ensure=20Requ?= =?UTF-8?q?ired=20Actions=20always=20have=20Outputs=20(#3031)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/server/services/Runs/StreamRunManager.js | 31 +++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/api/server/services/Runs/StreamRunManager.js b/api/server/services/Runs/StreamRunManager.js index bea8042aef..f19c73d736 100644 --- a/api/server/services/Runs/StreamRunManager.js +++ b/api/server/services/Runs/StreamRunManager.js @@ -497,6 +497,34 @@ class StreamRunManager { return `${stepId}_tool_call_${toolCall.index}_${toolCall.type}`; } + /** + * Check Missing Outputs + * @param {ToolOutput[]} tool_outputs - The tool outputs. + * @param {RequiredAction[]} actions - The required actions. + * @returns {ToolOutput[]} completeOutputs - The complete outputs. + */ + checkMissingOutputs(tool_outputs, actions) { + const missingOutputs = []; + + for (const item of actions) { + const { tool, toolCallId, run_id, thread_id } = item; + const outputExists = tool_outputs.some((output) => output.tool_call_id === toolCallId); + + if (!outputExists) { + logger.warn( + `The "${tool}" tool (ID: ${toolCallId}) failed to produce an output. run_id: ${run_id} thread_id: ${thread_id}`, + ); + missingOutputs.push({ + tool_call_id: toolCallId, + output: + 'The tool failed to produce an output. The tool may not be currently available or experienced an unhandled error.', + }); + } + } + + return [...tool_outputs, ...missingOutputs]; + } + /* <------------------ Run Event handlers ------------------> */ /** @@ -519,7 +547,8 @@ class StreamRunManager { }; }); - const { tool_outputs } = await processRequiredActions(this, actions); + const { tool_outputs: preliminaryOutputs } = await processRequiredActions(this, actions); + const tool_outputs = this.checkMissingOutputs(preliminaryOutputs, actions); /** @type {AssistantStream | undefined} */ let toolRun; try {