[GH-ISSUE #485] feat: handle_tool_errors — JS equivalent of Python's ToolNode(handle_tool_errors=True) #266

Closed
opened 2026-06-05 17:21:21 -04:00 by yindo · 2 comments
Owner

Originally created by @anouar-bm on GitHub (Apr 23, 2026).
Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/485

Problem

Python LangGraph has ToolNode(handle_tool_errors=True) which catches exceptions inside tool functions and returns them as ToolMessage content instead of crashing the superstep. The JS/TypeScript deepagentsjs package has no equivalent.

When any MCP tool throws (timeout, connection error, validation error), LangGraph JS propagates it as a "Multiple errors occurred during superstep N" crash. The agent cannot recover because it never sees the error in a ToolMessage — the graph just dies.

Real example from production:

Error: MCP tool 'wam_load_chain' on server 'wam' returned an error: 
Timeout: browser did not respond to "loadPlugin" within 10s
→ Multiple errors occurred during superstep 9.

Current workaround

Every tool must manually wrap its body in try/catch and return { ok: false, error, hint } as JSON text content instead of throwing. This is boilerplate that belongs in the framework:

// What every tool currently has to do manually
async (params) => {
  try {
    const result = await callBrowser(...)
    return { content: [{ type: "text", text: JSON.stringify(result) }] }
  } catch (err) {
    return { content: [{ type: "text", text: JSON.stringify({ ok: false, error: err.message, hint: "retry..." }) }] }
  }
}

Requested API

// Option A — createDeepAgent config
createDeepAgent({ tools, handleToolErrors: true })

// Option B — ToolNode level (matches Python API)
new ToolNode(tools, { handleToolErrors: true })

When enabled: any exception thrown inside a tool function is caught, serialized as a ToolMessage with content "Error: <message>", and the graph continues — giving the LLM a chance to read the error and retry with a corrected call.

Related

Originally created by @anouar-bm on GitHub (Apr 23, 2026). Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/485 ## Problem Python LangGraph has `ToolNode(handle_tool_errors=True)` which catches exceptions inside tool functions and returns them as `ToolMessage` content instead of crashing the superstep. The JS/TypeScript `deepagentsjs` package has no equivalent. When any MCP tool throws (timeout, connection error, validation error), LangGraph JS propagates it as a **"Multiple errors occurred during superstep N"** crash. The agent cannot recover because it never sees the error in a ToolMessage — the graph just dies. Real example from production: ``` Error: MCP tool 'wam_load_chain' on server 'wam' returned an error: Timeout: browser did not respond to "loadPlugin" within 10s → Multiple errors occurred during superstep 9. ``` ## Current workaround Every tool must manually wrap its body in try/catch and return `{ ok: false, error, hint }` as JSON text content instead of throwing. This is boilerplate that belongs in the framework: ```ts // What every tool currently has to do manually async (params) => { try { const result = await callBrowser(...) return { content: [{ type: "text", text: JSON.stringify(result) }] } } catch (err) { return { content: [{ type: "text", text: JSON.stringify({ ok: false, error: err.message, hint: "retry..." }) }] } } } ``` ## Requested API ```ts // Option A — createDeepAgent config createDeepAgent({ tools, handleToolErrors: true }) // Option B — ToolNode level (matches Python API) new ToolNode(tools, { handleToolErrors: true }) ``` When enabled: any exception thrown inside a tool function is caught, serialized as a `ToolMessage` with content `"Error: <message>"`, and the graph continues — giving the LLM a chance to read the error and retry with a corrected call. ## Related - deepagents #947 — validation errors not retried (model responds with plain text instead of corrected tool call) - deepagentsjs #68 — original feature request, no resolution - langgraph #6486 — `handle_tool_errors` disabled by default after 1.0.1, breaking existing graphs - [LangGraph forum: self-healing agents via tool error messages](https://forum.langchain.com/t/raising-tool-call-errors-so-agents-can-be-self-healing/3152)
yindo closed this issue 2026-06-05 17:21:21 -04:00
Author
Owner

@JadenKim-dev commented on GitHub (Apr 28, 2026):

Hello, I've always felt this was a necessary feature as well, so I've worked on it in #493.

Please take a look and let me know if you had something different in mind!

<!-- gh-comment-id:4335040976 --> @JadenKim-dev commented on GitHub (Apr 28, 2026): Hello, I've always felt this was a necessary feature as well, so I've worked on it in #493. Please take a look and let me know if you had something different in mind!
Author
Owner

@hntrl commented on GitHub (Jun 2, 2026):

Hi @anouar-bm + @JadenKim-dev!

See our guidance on how to handle tool errors using middleware here: https://docs.langchain.com/oss/javascript/langchain/tools#error-handling

handleToolErrors is something that we also have on ToolNode in langchain, but its something that we don't deliberately expose to the public-facing API

<!-- gh-comment-id:4606650982 --> @hntrl commented on GitHub (Jun 2, 2026): Hi @anouar-bm + @JadenKim-dev! See our guidance on how to handle tool errors using middleware here: https://docs.langchain.com/oss/javascript/langchain/tools#error-handling handleToolErrors is something that we also have on ToolNode in langchain, but its something that we don't deliberately expose to the public-facing API
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#266