kmail.at
contact

elsewhere

EnglishEN
← learning

langchain · difficulty ◆◆◆

ToolRetryMiddleware: Interrupts Now Propagate Through Retries

Stop agents reliably, even mid-retry

Your agent kept retrying after you told it to stop.

fully AI-generatedThis text is fully AI-generated and was published without human editorial review.

2026-07-14 · 8 min read

$ pip install -U langchain>=1.3.12
1.3.12
Release

langchain

#38722
PR

interrupt fix

Bugfix
Type

middleware

What it does

When a tool call fails and ToolRetryMiddleware retries it, any interrupt signal (a human Interrupt exception, or a forced termination) was silently swallowed, so the retry loop kept going. This fix ensures interrupts are properly propagated through the retry middleware, so the agent honours stop requests even mid-retry.

Why it matters

Interruptibility is critical in production agents. You may need to revoke a tool call mid-execution due to changing context, a timeout, or a security policy. If ToolRetryMiddleware ignores the interrupt and keeps retrying, you lose the ability to halt the agent safely. This closes that gap, making agent pipelines more robust and predictable under failure conditions.

Example

$ Build a ReAct agent with an unreliable tool that fails twice then succeeds, and confirm it retries.
[agent] Action: unreliable_tool with args {"query": "test"}\n[tool] RuntimeError: Transient failure #1\n[agent] Retrying (1/3)...\n[tool] RuntimeError: Transient failure #2\n[agent] Retrying (2/3)...\n[tool] Success after 3 attempts\nResult: Success after 3 attempts

Patch the tool to raise Interrupt on its second call and confirm the agent halts rather than retrying.

Common flags

ToolRetryMiddleware
Retries failed tool calls with exponential backoff
AgentExecutor
Runs the agent loop with retry policies
create_react_agent
Builds a ReAct agent from an LLM, tools, and prompt
Interrupt
LangChain base interrupt signal propagated through chains

History

Origin

The retry loop caught every exception, including interrupt signals, and continued as if nothing had happened.

The fix

PR #38722, fix(langchain): propagate interrupts through ToolRetryMiddleware, added a raise e path that re-raises the interrupt instead of swallowing it.

Under the hood

The on_exception_chain_start path

Inspect langchain_core agents.middleware.ToolRetryMiddleware.on_exception_chain_start. The new logic distinguishes a retryable tool error from an interrupt, and re-raises the interrupt immediately so the agent unwinds instead of entering another backoff cycle.

Fun facts

Pros & cons

pros

  • + Honours stop requests mid-retry
  • + Prevents runaway retry loops
  • + No app code changes

cons

  • − Touches an internal middleware path
  • − Requires upgrading langchain

Takeaways

  1. 1Interrupts now halt retries
  2. 2Inspect the raise e path
  3. 3Upgrade to 1.3.12+

Related commands

archive entry — written and published by a scheduled job, never editorially reviewed. Kept for reference: out of the site’s search index, and no ads run here. the reviewed library →

← all learning