JuliusBrussee/caveman · error

cave_tool_result_inline_limit

cave_tool_result_inline_limit

Error message

cave_tool_result_inline_limit

What it means

When a tool definition declares result policy "inline", the serialized result must fit within maxInlineBytes — either 32,768 bytes by default or artifact.maxInlineTokens*4 when an artifact is configured. Exceeding it throws this error rather than silently truncating or offloading.

Solutions

  1. Change the tool definition's result policy from "inline" to "page" so large results are offloaded automatically.
  2. Increase artifact.maxInlineTokens in the tool's artifact config if large outputs are expected.
  3. Truncate/summarize the tool output before returning.
  4. Move the bulk payload to an artifact and return a reference.

Example fix

// before
{ name: "dumpLogs", result: "inline" }
// after
{ name: "dumpLogs", result: "page", artifact: { maxInlineTokens: 8192 } }
Defensive patterns

Strategy: validation

Validate before calling

const maxInlineBytes = definition.artifact ? definition.artifact.maxInlineTokens * 4 : 32768;
if (new TextEncoder().encode(text).byteLength > maxInlineBytes) {
  text = summarizeOrOffload(text);
}

Type guard

function fitsInline(text: string, maxInlineBytes: number): boolean {
  return new TextEncoder().encode(text).byteLength <= maxInlineBytes;
}

Try / catch

try {
  return await callTool(args);
} catch (e) {
  if (e?.message === 'cave_tool_result_inline_limit') {
    return await callToolWithPaging(args);
  }
  throw e;
}

Prevention

When it happens

Trigger: A tool with definition.result === "inline" returns content whose encoded byteLength exceeds maxInlineBytes (32,768 default) at runtime.ts:3754.

Common situations: Registering a tool as inline but letting it return large outputs (long logs, big JSON); misconfigured maxInlineTokens on the artifact; version changes where outputs grew past the threshold.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/fb1349fd8a03d087. Report an issue: GitHub.

Appendix: source

Thrown at packages/agent/src/runtime.ts:3754

        ? await sandboxExecute(params, combined)
        : await raceToolTimeout(
          Promise.resolve(definition.execute(params, combined)),
          definition.timeoutMs,
        );
      const text = typeof value === "string" ? value : JSON.stringify(value);
      const raw = new TextEncoder().encode(text ?? "null");
      const maxInlineBytes = definition.artifact === undefined
        ? 32_768
        : definition.artifact.maxInlineTokens * 4;
      if (deferLockedToolResult) {
        if (raw.byteLength > 16 * 1024 * 1024) throw new Error("cave_tool_result_limit");
        return {
          content: [{ type: "text", text: text ?? "null" }],
          details: { effect: definition.effect, resultPolicy: definition.result, lockedRoutePending: true },
        };
      }
      if (definition.result === "inline") {
        if (raw.byteLength > maxInlineBytes) throw new Error("cave_tool_result_inline_limit");
        return {
          content: [{ type: "text", text: text ?? "null" }],
          details: { effect: definition.effect, resultPolicy: definition.result },
        };
      }
      const mustOffload = definition.result === "page" ||
        definition.result === "compress" ||
        definition.result === "exact_ccr" ||
        raw.byteLength > maxInlineBytes;
      if (!mustOffload) {
        return {
          content: [{ type: "text", text: text ?? "null" }],
          details: { effect: definition.effect, resultPolicy: definition.result },
        };
      }
      const transformed = await engineCompress(raw, engineBin);
      if (!transformed.handle || !recoveryHandles) {
        throw new Error("cave_tool_result_requires_recovery");

View on GitHub (pinned to 3ee70a1026)