handle tool call error
This commit is contained in:
parent
24c7ec82ea
commit
92ae63d7eb
2 changed files with 19 additions and 4 deletions
|
|
@ -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<void, undefined, ThunkApiType>(
|
|||
);
|
||||
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);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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<void, undefined, ThunkApiType>(
|
|||
|
||||
dispatch(cancelToolCall());
|
||||
|
||||
dispatch(
|
||||
const output = await dispatch(
|
||||
streamResponseAfterToolCall({
|
||||
toolCallId: toolCallState.toolCallId,
|
||||
toolOutput: [
|
||||
|
|
@ -34,5 +34,6 @@ export const cancelTool = createAsyncThunk<void, undefined, ThunkApiType>(
|
|||
],
|
||||
}),
|
||||
);
|
||||
unwrapResult(output);
|
||||
},
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue