JuliusBrussee/caveman · error
cave_untrusted_tool_definition
cave_untrusted_tool_definition
Error message
cave_untrusted_tool_definition:${declared.name} What it means
Thrown by visit in validateAgentGraph when a tool declaration lacks a trusted implementation source: Reflect.get(declared, TOOL_IMPLEMENTATION_SOURCE) is not a string. Tool implementations must be registered through the library's tool factory, which stamps a private symbol proving the implementation came from trusted code; arbitrary object literals claiming to be tools are rejected.
Solutions
- Create tools with the library's official tool factory/helper so the trusted-source symbol is attached.
- Re-wrap copied tools through the factory instead of spreading plain objects.
- Do not serialize/deserialize tool definitions across boundaries; pass the live factory-created objects.
- If a custom implementation wrapper is required, use the library's extension point to register a trusted source string.
Example fix
// before
const tool = { kind: "tool", name: "search", run: async () => /* ... */ };
// after
const tool = defineTool({ name: "search", run: async () => /* ... */ }); // factory stamps TOOL_IMPLEMENTATION_SOURCE Defensive patterns
Strategy: validation
Validate before calling
import { TOOL_IMPLEMENTATION_SOURCE } from "@caveman/agent";
function isTrustedTool(t: ToolDefinition): boolean {
return typeof Reflect.get(t, TOOL_IMPLEMENTATION_SOURCE) === "string";
}
definition.tools.forEach(t => { if (!isTrustedTool(t)) throw new Error(`tool ${t.name} lacks a trusted implementation source`); }); Type guard
function isTrustedToolDefinition(v: unknown): v is ToolDefinition {
return typeof v === "object" && v !== null &&
typeof Reflect.get(v, TOOL_IMPLEMENTATION_SOURCE) === "string";
} Try / catch
try {
validateAgentGraph(def);
} catch (e) {
if (e instanceof Error && e.message.startsWith("cave_untrusted_tool_definition")) {
console.error(`Tool was not created by the library factory: ${e.message}; rebuild it with defineTool()`);
} else throw e;
} Prevention
- Always create tools with the library's tool factory so the trust symbol is stamped.
- Never build tool objects by hand or restore them from JSON — symbols do not survive serialization.
- Avoid spread/Object.assign copies of tool definitions; they drop symbol-keyed metadata.
- Pass live factory-created tool objects across modules instead of serialized copies.
When it happens
Trigger: Hand-constructing a plain object { kind: "tool", name: "x", ... } without the TOOL_IMPLEMENTATION_SOURCE symbol, deserializing tools from JSON (symbols cannot survive serialization), or copying a tool with a spread that drops symbol-keyed properties.
Common situations: Loading tool definitions from config/DB, sharing tools across process boundaries, or using object spread/Object.assign to build modified copies of tools — all of which lose the private symbol.
Related errors
- ambiguous escaped path sequence
- auth_token: in is ignored — the inbound token is read only…
- awscreds: AWS_CONTAINER_CREDENTIALS_FULL_URI is not a valid…
- awscreds: refusing plaintext container credentials endpoint…
- awscreds: refusing plaintext IMDS endpoint at host
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/a9e00a5356cf0e53.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/definition-graph.ts:46
}
const memo = visited[sandboxRequired ? 1 : 0]!;
if (memo.has(definition)) return;
active.add(definition);
const childSandboxRequired = sandboxRequired ||
definition.sandbox === "required";
const names = new Set<string>();
for (const declared of definition.tools) {
if (!declared || declared.kind !== "tool" ||
typeof declared.name !== "string") {
throw new Error("cave_tool_definition_invalid");
}
if (names.has(declared.name)) throw new Error("cave_duplicate_tool_name");
names.add(declared.name);
if (declared.name.startsWith("cave_")) {
throw new Error(`cave_reserved_tool_name:${declared.name}`);
}
if (typeof Reflect.get(declared, TOOL_IMPLEMENTATION_SOURCE) !== "string") {
throw new Error(`cave_untrusted_tool_definition:${declared.name}`);
}
if (declared.runtime?.kind !== "subagent") continue;
const child = declared.runtime.definition as AgentDefinition;
visit(child, depth + 1, childSandboxRequired);
}
active.delete(definition);
memo.add(definition);
};
visit(root, 0, false);
}
/**
* True when any agent in the graph opts into host mode.
*
* Lock eligibility is a property of the whole graph, not of its root: a host
* subagent runs its tool closures in the host process just as a host root does,
* so its evidence shows no containment either. Follows the same subagent edgesView on GitHub (pinned to 3ee70a1026)