JuliusBrussee/caveman · error

cave_tool_search_result_limit

cave_tool_search_result_limit

Error message

cave_tool_search_result_limit

What it means

The `cave_search_tools` recovery tool serializes its top-scored (max 4) original tool definitions to JSON and refuses to return payloads over 8,192 characters, throwing `cave_tool_search_result_limit`. This bounds the context cost of the recovery path so a search meant to save context cannot blow the budget by returning huge tool schemas.

Solutions

  1. Refine the `query` to a more specific term so fewer/smaller tool definitions match and the top 4 fit under the limit.
  2. Split tool registration so no single tool's schema is enormous; move rarely-used parameters out of the JSON schema.
  3. Wrap the call, catch the error, and retry with a narrower query instead of treating it as fatal.
  4. If you control the tool set, shorten descriptions and schema titles/defaults that inflate the serialized definition.

Example fix

// before
const r = await tools.cave_search_tools.execute(id, { query: "file" }); // matches 4 huge schemas > 8192 chars
// after
const r = await tools.cave_search_tools.execute(id, { query: "read file content" }); // narrower match, smaller payload
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

try {
  return await tools.cave_search_tools.execute(id, { query });
} catch (e) {
  if ((e as Error).message === "cave_tool_search_result_limit") {
    return await tools.cave_search_tools.execute(id, { query: narrower(query) });
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `cave_search_tools` when the combined JSON of the top 4 matching original tool definitions exceeds 8,192 characters — e.g. matching tools with very large `input` parameter schemas.

Common situations: Agents registered with many large MCP/tool schemas whose original definitions are huge; a broad query matching 4 giant tools; annotation compaction making the model search for tools whose definitions are individually large.

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/67711d96a6468d26. Report an issue: GitHub.

Appendix: source

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

        } catch {
          continue;
        }
        if (!isRecord(parsed) || typeof parsed.name !== "string" ||
            typeof parsed.description !== "string" || !isRecord(parsed.input)) continue;
        const haystack = `${parsed.name} ${parsed.description} ${JSON.stringify(parsed.input)}`.toLowerCase();
        const score = terms.reduce((total, term) => total + (haystack.includes(term) ? 1 : 0), 0);
        if (score > 0) hits.push({ score, value: parsed, handle });
      }
      hits.sort((first, second) => second.score - first.score ||
        String(first.value.name).localeCompare(String(second.value.name)));
      const selected = hits.slice(0, 4);
      for (const hit of selected) {
        for (const item of trace ?? []) {
          if (item.recoveryHandle === hit.handle) item.recoveryUsed = true;
        }
      }
      const text = JSON.stringify(selected.map((hit) => hit.value));
      if (text.length > 8_192) throw new Error("cave_tool_search_result_limit");
      return {
        content: [{ type: "text", text }],
        details: { recovery: "tool_schema_search", hits: selected.length },
      };
    },
  };
}

function validEngineTokenCount(value: unknown): number | undefined {
  return Number.isSafeInteger(value) && Number(value) >= 0 ? Number(value) : undefined;
}

function localMemoryTools(
  definition: NonNullable<AgentDefinition["memory"]>,
  agentId: string,
  config: MemoryStoreConfig | undefined,
): AgentTool<TSchema>[] {
  // Defense in depth: memory() already rejects a non-local provenance/consent at

View on GitHub (pinned to 3ee70a1026)