From af24a851e36348bd91326635cbbb5f87bcdd5576 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 22 Jun 2025 23:47:00 -0700 Subject: [PATCH] log whether tool calls fail or succeed --- gui/src/redux/thunks/callCurrentTool.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gui/src/redux/thunks/callCurrentTool.ts b/gui/src/redux/thunks/callCurrentTool.ts index af8b4d4d9..02137d822 100644 --- a/gui/src/redux/thunks/callCurrentTool.ts +++ b/gui/src/redux/thunks/callCurrentTool.ts @@ -1,6 +1,7 @@ import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit"; import { ContextItem } from "core"; import { CLIENT_TOOLS_IMPLS } from "core/tools/builtIn"; +import posthog from "posthog-js"; import { callClientTool } from "../../util/clientTools/callClientTool"; import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall"; import { selectSelectedChatModel } from "../slices/configSlice"; @@ -45,6 +46,9 @@ export const callCurrentTool = createAsyncThunk( let errorMessage: string | undefined = undefined; let streamResponse: boolean; + // Check if telemetry is enabled + const allowAnonymousTelemetry = state.config.config.allowAnonymousTelemetry; + // IMPORTANT: // Errors that occur while calling tool call implementations // Are caught and passed in output as context items @@ -110,6 +114,17 @@ export const callCurrentTool = createAsyncThunk( ); } + // Because we don't have access to use hooks, we check `allowAnonymousTelemetry` + // directly rather than using `CustomPostHogProvider` + if (allowAnonymousTelemetry) { + // Capture telemetry for tool calls + posthog.capture("gui_tool_call_outcome", { + succeeded: errorMessage === undefined, + toolName: toolCallState.toolCall.function.name, + errorMessage: errorMessage, + }); + } + if (streamResponse) { if (errorMessage) { dispatch(