{"record":{"id":"cfdfad548cfe1c06","repo":"different-ai/openwork","slug":"toolcalllimitexceeded","errorCode":"ToolCallLimitExceeded","errorMessage":"Execution exceeded its tool-call limit of ${maxToolCalls}.","messagePattern":"Execution exceeded its tool-call limit of (.+?)\\.","errorType":"error_code","errorClass":"ToolRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/tool-runtime.ts","lineNumber":750,"sourceCode":"        return onEnd({\n          ...call,\n          durationMs: Date.now() - startedAt,\n          outcome: \"failure\",\n          message,\n        })\n      }),\n    )\n  }\n\n  const decodeOutput = (value: unknown, name: string) =>\n    Effect.try({\n      try: () => copyIn(value, `Result from tool '${name}'`),\n      catch: () => new ToolRuntimeError(\"InvalidToolOutput\", `Invalid output from tool '${name}'.`),\n    })\n\n  const recordCall = (call: ToolCall): void => {\n    if (maxToolCalls !== undefined && calls.length >= maxToolCalls) {\n      throw new ToolRuntimeError(\"ToolCallLimitExceeded\", `Execution exceeded its tool-call limit of ${maxToolCalls}.`)\n    }\n    calls.push(call)\n  }\n\n  return {\n    root: new ToolReference([]),\n    calls,\n    keys: (path) => namespaceKeys(callableTools, path),\n    invoke: (path, args) =>\n      Effect.gen(function* () {\n        const name = path.join(\".\")\n        const externalArgs = args.map((arg) => copyOut(copyIn(arg, `Arguments for tool '${name}'`)))\n        const call = { name }\n        const recordAndObserve = (input: unknown) =>\n          Effect.sync(() => {\n            recordCall(call)\n            return calls.length - 1\n          }).pipe(Effect.tap((index) => hooks?.onToolCallStart?.({ index, name, input }) ?? Effect.void))","sourceCodeStart":732,"sourceCodeEnd":768,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/tool-runtime.ts#L732-L768","documentation":"The codemode tool runtime tracks every tool call made during a scripted execution and enforces an optional per-execution cap (maxToolCalls). When recordCall sees calls.length already at the cap, it throws ToolCallLimitExceeded to stop runaway agent loops. This is an intentional guardrail against infinite tool-calling loops, not a bug.","triggerScenarios":"Executing a codemode script whose interpreter issues more tool calls than maxToolCalls for the run; the call that exceeds the cap is rejected before it is dispatched to the tool.","commonSituations":"Agents stuck in retry loops calling the same failing tool; scripts with unbounded loops over large datasets each invoking a tool; misconfigured (too low) maxToolCalls for a legitimate multi-tool task; long-running autonomous sessions where the cap was set for a single turn.","solutions":["Raise maxToolCalls in the execution options to a value that fits the task's expected number of tool calls","Inspect the script/agent for loops that re-invoke tools without progress and fix the loop logic","Break the task into multiple executions, each with its own tool-call budget","If the call itself was legitimate, ensure calls are deduplicated (cache results) so fewer tool calls are consumed"],"exampleFix":"// before\nawait runtime.execute(code, { maxToolCalls: 5 })\n// after\nawait runtime.execute(code, { maxToolCalls: 50 })","handlingStrategy":"try-catch","validationCode":"const remaining = maxToolCalls - callsSoFar\nif (remaining <= 0) throw new Error(`Tool-call budget exhausted before execution`);","typeGuard":null,"tryCatchPattern":"try {\n  await runtime.execute(code, { maxToolCalls })\n} catch (e) {\n  if (e instanceof ToolRuntimeError && e.code === 'ToolCallLimitExceeded') {\n    // resume with a higher limit or split the task\n  } else throw e\n}","preventionTips":["Set maxToolCalls generously above the expected number of tool calls","Deduplicate repeated tool invocations in scripts","Loop over data in-process instead of issuing one tool call per item","Monitor calls length and stop the script before the cap"],"tags":["codemode","tool-call-limit","agent-loop"],"backgroundTag":"tool-call-limit-exceeded","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}