From 92ae63d7eb6bc919e57321c4abd48bb0cad7b105 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 12 Mar 2025 17:10:22 -0700 Subject: [PATCH] handle tool call error --- gui/src/redux/thunks/callTool.ts | 18 ++++++++++++++++-- gui/src/redux/thunks/cancelTool.ts | 5 +++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/gui/src/redux/thunks/callTool.ts b/gui/src/redux/thunks/callTool.ts index 0bd367587..1202f22bf 100644 --- a/gui/src/redux/thunks/callTool.ts +++ b/gui/src/redux/thunks/callTool.ts @@ -2,6 +2,7 @@ import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit"; import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall"; import { acceptToolCall, + cancelToolCall, setCalling, setToolCallOutput, } from "../slices/sessionSlice"; @@ -47,9 +48,22 @@ export const callTool = createAsyncThunk( ); unwrapResult(response); } else { - throw new Error( - `Failed to call tool ${toolCallState.toolCall.function.name}: ${result.error}`, + dispatch(cancelToolCall()); + + const output = await dispatch( + streamResponseAfterToolCall({ + toolCallId: toolCallState.toolCallId, + toolOutput: [ + { + name: "Tool Call Failed", + description: "Tool Call Failed", + content: `The tool call failed with the message:\n\n${result.error}\n\nPlease try something else or request further instructions.`, + hidden: true, + }, + ], + }), ); + unwrapResult(output); } }, ); diff --git a/gui/src/redux/thunks/cancelTool.ts b/gui/src/redux/thunks/cancelTool.ts index 89c4e8e12..d46195674 100644 --- a/gui/src/redux/thunks/cancelTool.ts +++ b/gui/src/redux/thunks/cancelTool.ts @@ -1,4 +1,4 @@ -import { createAsyncThunk } from "@reduxjs/toolkit"; +import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit"; import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall"; import { cancelToolCall } from "../slices/sessionSlice"; import { ThunkApiType } from "../store"; @@ -20,7 +20,7 @@ export const cancelTool = createAsyncThunk( dispatch(cancelToolCall()); - dispatch( + const output = await dispatch( streamResponseAfterToolCall({ toolCallId: toolCallState.toolCallId, toolOutput: [ @@ -34,5 +34,6 @@ export const cancelTool = createAsyncThunk( ], }), ); + unwrapResult(output); }, );