The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Mark failed tool calls in Metabot's thinking panel (#83044)
Andrei Simionescu7b327c132ccd
diff --git a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.module.css b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.module.cssindex 204fb5b533a..4d2fcc1f938 100644--- a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.module.css+++ b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.module.css@@ -128,6 +128,11 @@color: var(--mb-color-text-tertiary);}+.failed {+ margin-left: 0.375rem;+ color: var(--mb-color-feedback-negative);+}+.resultsList {display: flex;flex-direction: column;diff --git a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.unit.spec.tsx b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.unit.spec.tsxindex a8389db4010..90396254359 100644--- a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.unit.spec.tsx+++ b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.unit.spec.tsx@@ -496,6 +496,25 @@ describe("MetabotChainOfThought", () => {expect(screen.queryByText("Reading resource")).not.toBeInTheDocument();});+ it("keeps a failed resource read out of the aggregated row", async () => {+ setup(+ chain({+ steps: [+ { kind: "tool", id: "r1", name: "read_resource", status: "ended" },+ { kind: "tool", id: "r2", name: "read_resource", status: "ended" },+ { kind: "tool", id: "r3", name: "read_resource", status: "errored" },+ ],+ startedAtMs: 1000,+ endedAtMs: 2000,+ }),+ false,+ );+ await expandChain();+ expect(screen.getByText("Read 2 resources")).toBeInTheDocument();+ expect(screen.getByText("Reading resource")).toBeInTheDocument();+ expect(screen.getByText("Failed")).toBeInTheDocument();+ });+it("keeps reasoning and entity names out of embedded sessions", async () => {const message = chain({steps: [diff --git a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/ToolStep.tsx b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/ToolStep.tsxindex 8f3549d836b..0128489f884 100644--- a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/ToolStep.tsx+++ b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/ToolStep.tsx@@ -47,11 +47,15 @@ const ToolStepLabel = ({step: ToolChainStep;done: boolean;className?: string;-}) => (- <Text component="span" className={className} c="inherit" lh="inherit">- {toolLabelContent(step, done)}- </Text>-);+}) => {+ const isFailed = step.status === "errored";+ return (+ <Text component="span" className={className} c="inherit" lh="inherit">+ {toolLabelContent(step, done && !isFailed)}+ {isFailed && <span className={S.failed}>{t`Failed`}</span>}+ </Text>+ );+};export const ResourceGroupStep = ({count,diff --git a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/utils.tsx b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/utils.tsxindex 5b8a3e377f0..f588ec518fb 100644--- a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/utils.tsx+++ b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/utils.tsx@@ -158,12 +158,19 @@ export type DisplayItem =| { kind: "tool"; step: ToolChainStep; index: number }| { kind: "resourceGroup"; steps: ToolChainStep[]; index: number };+const isGroupableResourceStep = (step: MetabotChainStep) =>+ isResourceStep(step) && step.status !== "errored";+const groupConsecutiveResources = (steps: MetabotChainStep[],): MetabotChainStep[][] =>steps.reduce<MetabotChainStep[][]>((groups, step) => {const last = groups.at(-1);- if (last && isResourceStep(step) && isResourceStep(last[0])) {+ if (+ last &&+ isGroupableResourceStep(step) &&+ isGroupableResourceStep(last[0])+ ) {return [...groups.slice(0, -1), [...last, step]];}return [...groups, [step]];diff --git a/frontend/src/metabase/metabot/state/reducer-utils.ts b/frontend/src/metabase/metabot/state/reducer-utils.tsindex b7531288367..ad94827869b 100644--- a/frontend/src/metabase/metabot/state/reducer-utils.ts+++ b/frontend/src/metabase/metabot/state/reducer-utils.ts@@ -252,12 +252,13 @@ export const endChainTool = (convo: WritableDraft<MetabotConversationState>,id: string,nowMs?: number,+ isError?: boolean,) => {const found = findChainToolStep(convo, id);if (!found) {return;}- found.step.status = "ended";+ found.step.status = isError ? "errored" : "ended";if (!found.chain.finished && nowMs != null) {found.chain.endedAtMs = nowMs;}diff --git a/frontend/src/metabase/metabot/state/reducer.ts b/frontend/src/metabase/metabot/state/reducer.tsindex 522455c6356..341dd27b1af 100644--- a/frontend/src/metabase/metabot/state/reducer.ts+++ b/frontend/src/metabase/metabot/state/reducer.ts@@ -280,7 +280,12 @@ export const metabot = createSlice({convo.activeToolCalls = convo.activeToolCalls.map((tc) =>tc.id === action.payload.toolCallId ? { ...tc, status: "ended" } : tc,);- endChainTool(convo, action.payload.toolCallId, action.payload.nowMs);+ endChainTool(+ convo,+ action.payload.toolCallId,+ action.payload.nowMs,+ action.payload.isError,+ );// Update the message in messages array with result for debug historyconst message = findLastToolCallPart(convo, action.payload.toolCallId);diff --git a/frontend/src/metabase/metabot/state/types.ts b/frontend/src/metabase/metabot/state/types.tsindex 3887a37f392..bcc2df5d78d 100644--- a/frontend/src/metabase/metabot/state/types.ts+++ b/frontend/src/metabase/metabot/state/types.ts@@ -145,7 +145,7 @@ export type MetabotChainStep =name: string;title?: string;searchResults?: MetabotSearchResults;- status: "started" | "ended";+ status: "started" | "ended" | "errored";startedAtMs?: number;};diff --git a/frontend/src/metabase/metabot/tests/reducer.unit.spec.ts b/frontend/src/metabase/metabot/tests/reducer.unit.spec.tsindex 10640f1ebfb..e34f068d28e 100644--- a/frontend/src/metabase/metabot/tests/reducer.unit.spec.ts+++ b/frontend/src/metabase/metabot/tests/reducer.unit.spec.ts@@ -442,6 +442,38 @@ describe("metabot reducer", () => {]);});+ it("marks the matching tool step errored when its call fails", () => {+ const store = createStreamingStore();+ store.dispatch(+ metabotActions.toolCallStart({+ conversationId,+ toolCallId: "t1",+ toolName: "search",+ }),+ );+ store.dispatch(+ metabotActions.toolCallStart({+ conversationId,+ toolCallId: "t2",+ toolName: "read_resource",+ }),+ );+ store.dispatch(+ metabotActions.toolCallEnd({+ conversationId,+ toolCallId: "t1",+ result: "Search is unavailable",+ isError: true,+ }),+ );++ const chain = getChain(store);+ expect(chain?.type === "chain_of_thought" && chain.steps).toEqual([+ { kind: "tool", id: "t1", name: "search", status: "errored" },+ { kind: "tool", id: "t2", name: "read_resource", status: "started" },+ ]);+ });+it("persists the chain but closes it when the answer text starts", () => {const store = createStreamingStore();store.dispatch(metabotActions.reasoningStart({ conversationId }));diff --git a/frontend/src/metabase/metabot/tests/tool-calls.unit.spec.tsx b/frontend/src/metabase/metabot/tests/tool-calls.unit.spec.tsxindex 7ebf7c165e6..22d5440d271 100644--- a/frontend/src/metabase/metabot/tests/tool-calls.unit.spec.tsx+++ b/frontend/src/metabase/metabot/tests/tool-calls.unit.spec.tsx@@ -130,6 +130,37 @@ describe("metabot > tool calls", () => {});});+ it("should show a tool call that errored as failed", async () => {+ setup();+ mockAgentEndpoint({+ events: [+ {+ type: "tool-input-available",+ toolCallId: "x",+ toolName: "search",+ input: {},+ },+ {+ type: "tool-output-error",+ toolCallId: "x",+ errorText: "Search is unavailable",+ },+ { type: "finish", finishReason: "stop" },+ ],+ });++ await enterChatMessage("Find the revenue dashboard");+ expect(+ await screen.findByText(/Worked (briefly|for|on)/),+ ).toBeInTheDocument();+ await userEvent.click(+ screen.getByTestId("metabot-chain-of-thought-header"),+ );++ await waitFor(() => expect(screen.getByText("Searching")).toBeVisible());+ expect(screen.getByText("Failed")).toBeVisible();+ });+it("should start a new message if there's tool calls between streamed text parts", async () => {setup();mockAgentEndpoint({