createToolErrorBudgetMiddleware
createToolErrorBudgetMiddleware(
maxConsecutiveErrors?):AgentMiddleware<undefined,undefined,unknown, readonly (ClientTool|ServerTool)[], readonly []>
Defined in: _worktrees/docs-release/gaunt-sloth/packages/core/src/core/GthLangChainAgent.ts:70
GS2-36 — the tool-error retry budget as a standalone, testable middleware factory (exported so the
real thing can be unit-tested and exercised in a real createAgent graph, mirroring
createPathNamespaceCorrectionMiddleware).
Runs in beforeModel (like langchain’s own modelCallLimitMiddleware): after the tools node has
appended its result(s) and before the next model call is spent, it walks the trailing messages and
counts CONSECUTIVE errored tool results — a ToolMessage with status: 'error' (the shape the
shell/MCP softeners produce; GthAbstractAgent maps status==='error' → isError). The walk skips
the assistant tool-call requests between rounds, and RESETS on the first successful tool result
(progress / diagnosis) or a Human/System message (a fresh user turn). Once the count reaches the
cap it returns { jumpTo: 'end', messages: [<action-oriented notice>] }, ending the run without
spending another model call.
Scope: counts status: 'error' results only. The recoverable fs error STRINGS
(write_file/edit_file/…) are status: 'success' by the write_file precedent, so a pure fs
error loop is deliberately NOT capped here — it stays bounded by the coarse recursionLimit and is
the remit of the loop-DETECTION node (EXT-36). Counting status: 'error' overall (not per-tool)
catches both same-tool and alternating-tool error loops with one robust rule.
Parameters
Section titled “Parameters”maxConsecutiveErrors?
Section titled “maxConsecutiveErrors?”number = MAX_CONSECUTIVE_TOOL_ERRORS
Returns
Section titled “Returns”AgentMiddleware<undefined, undefined, unknown, readonly (ClientTool | ServerTool)[], readonly []>