{"record":{"id":"d7c92ee44e7632f1","repo":"FlowiseAI/Flowise","slug":"error-in-agent-node-error-instanceof-error-er","errorCode":null,"errorMessage":"Error in Agent node: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Error in Agent node: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/agentflow/Agent/Agent.ts","lineNumber":1546,"sourceCode":"                            (usedTools && usedTools.length > 0)) && {\n                            additional_kwargs: {\n                                ...(artifacts && artifacts.length > 0 && { artifacts }),\n                                ...(fileAnnotations && fileAnnotations.length > 0 && { fileAnnotations }),\n                                ...(usedTools && usedTools.length > 0 && { usedTools })\n                            }\n                        })\n                    }\n                ]\n            }\n        } catch (error) {\n            if (options.analyticHandlers && llmIds) {\n                await options.analyticHandlers.onLLMError(llmIds, error instanceof Error ? error.message : String(error))\n            }\n\n            if (error instanceof Error && error.message === 'Aborted') {\n                throw error\n            }\n            throw new Error(`Error in Agent node: ${error instanceof Error ? error.message : String(error)}`)\n        }\n    }\n\n    /**\n     * Extracts built-in used tools from response metadata and processes image generation results\n     */\n    private async extractBuiltInUsedTools(response: AIMessageChunk, builtInUsedTools: IUsedTool[] = []): Promise<IUsedTool[]> {\n        if (!response.response_metadata) {\n            return builtInUsedTools\n        }\n\n        const { output, tools, groundingMetadata, urlContextMetadata } = response.response_metadata as {\n            output?: any[]\n            tools?: any[]\n            groundingMetadata?: { webSearchQueries?: string[] }\n            urlContextMetadata?: { urlMetadata?: any[] }\n        }\n","sourceCodeStart":1528,"sourceCodeEnd":1564,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/agentflow/Agent/Agent.ts#L1528-L1564","documentation":"This is the top-level catch in Agent.run. It reports analytics via onLLMError when handlers and llmIds are present, re-throws Abort errors verbatim, and wraps every other error as 'Error in Agent node: <message>'. Seeing this means a downstream operation inside run() failed and was re-packaged; the inner cause is in the interpolated message.","triggerScenarios":"Any uncaught throw inside Agent.run: model invocation failure (auth, rate limit, network), tool init failure, message serialization error, structured-output schema mismatch, or one of the explicit guards above. AbortController.abort() is the one case re-thrown without wrapping.","commonSituations":"Expired/invalid LLM API key; provider rate limit or 5xx; token-context overflow; a tool node throwing during init; malformed BaseMessage objects from custom memory; transient network blip to the model provider.","solutions":["Read the interpolated message to find the root cause (e.g. '401 Unauthorized', 'context_length_exceeded').","For auth errors, refresh/rotate the model credential attached to the agent's model node.","For rate-limit/context errors, reduce input size, lower history, or switch to a higher-limit model.","For transient failures, retry the request; for Abort, check the upstream cancellation source.","If analytics are configured, inspect onLLMError events for structured diagnostics."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await agent.run(nodeData, input, options)\n} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e)\n  if (msg === 'Aborted') { /* user cancellation — expected */ return }\n  if (msg.startsWith('Error in Agent node: ')) {\n    const inner = msg.slice('Error in Agent node: '.length)\n    // classify inner: auth / rate-limit / context-length / tool failure\n  }\n  throw e\n}","preventionTips":["Keep model credentials valid and rotate before expiry.","Cap chat history length to avoid context overflow.","Wire onLLMError analytics to an alerting channel.","Distinguish Abort (expected) from real failures in your handler."],"tags":["agent","catch-all","error-wrapping","observability"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}