JuliusBrussee/caveman · error

cave_tool_search_query_required

cave_tool_search_query_required

Error message

cave_tool_search_query_required

What it means

The built-in `cave_search_tools` recovery tool throws `cave_tool_search_query_required` when the model calls it with a `query` that is empty or whitespace-only after trimming/lowercasing. The tool searches the original, un-compacted tool definitions stored in the engine, so without a query it cannot rank or select anything. The throw happens inside `execute` and surfaces as a normal tool-call error in the agent loop.

Solutions

  1. Supply a non-empty `query` string containing terms from the tool name/description you are looking for.
  2. If a caller wraps this tool, validate the query is non-blank before forwarding and retry with a real query.
  3. If the model repeatedly sends empty queries, restate the task or the needed tool name in the prompt so it can form a search term.

Example fix

// before
await agent.run("find a tool", { /* model calls cave_search_tools with query: "" */ });
// after
await agent.run("Use cave_search_tools with a non-empty query, e.g. query=\"read file\", to locate the file-reading tool.");
Defensive patterns

Strategy: validation

Validate before calling

function canSearch(query: unknown): query is string {
  return typeof query === "string" && query.trim().length > 0;
}
if (!canSearch(args.query)) throw new Error("supply a non-empty query for cave_search_tools");

Type guard

const hasQuery = (p: unknown): p is { query: string } =>
  typeof p === "object" && p !== null && typeof (p as { query?: unknown }).query === "string";

Try / catch

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

Prevention

When it happens

Trigger: Calling `cave_search_tools` with `{ query: "" }`, `{ query: " " }`, or when the model omits/garbles the query parameter so the trimmed string is empty.

Common situations: A model hallucinating an empty argument during context-compaction recovery; a wrapper that passes through an unset variable as the query; string interpolation producing an empty string.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

      };
    },
  };
}

function toolSchemaSearchTool(
  handles: ReadonlySet<string>,
  engineBin: string | undefined,
  trace?: MutableTransformTrace[],
): AgentTool<TSchema> {
  return {
    name: "cave_search_tools",
    label: "cave_search_tools",
    description: "Search exact original tool definitions when compacted annotations are insufficient.",
    parameters: Type.Object({ query: Type.String() }),
    executionMode: "parallel",
    async execute(_toolCallId, params) {
      const query = (params as { query: string }).query.trim().toLowerCase();
      if (query === "") throw new Error("cave_tool_search_query_required");
      const terms = tokenize(query);
      const hits: Array<{ score: number; value: Record<string, unknown>; handle: string }> = [];
      for (const handle of handles) {
        const original = await engineRetrieve(handle, undefined, engineBin);
        let parsed: unknown;
        try {
          parsed = JSON.parse(new TextDecoder().decode(original));
        } 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)));

View on GitHub (pinned to 3ee70a1026)