Caveman Agent SDK· Open sourceAgent SDK & Harness v4
Harness v4 Engine: Loadouts, Code-Mode MCP, and Environments
Embed @caveman-ai/harness directly: model-native loadouts (app-gpt, app-claude, app-code, app-general), QuickJS with_mcp code mode, byte-stable cache prefixes, and Local/Docker/Sandbox environments.
@caveman-ai/harness (also re-exported from @caveman-ai/agent/harness) is the open-source agent engine underneath @caveman-ai/agent and Caveman Code. It matches tool surfaces to each model family, preserves byte-stable prompt prefixes across turns, isolates subprocess credentials (inheritEnv: false), and exits with stable codes when parked.
Install and run a session#
npm install @caveman-ai/agentimport { tool } from "@caveman-ai/agent";
import {
HarnessSession,
LocalEnv,
appLoadoutFor,
resolveHarnessModel,
toHarnessTool,
} from "@caveman-ai/agent/harness";
const { model, stream } = resolveHarnessModel("anthropic/claude-sonnet-4-6");
const recordFinding = tool(
"record_finding",
"Record a finding from workspace inspection.",
{ type: "object", properties: { note: { type: "string" } }, required: ["note"] },
async ({ note }: { note: string }) => ({ recorded: true, note }),
);
const session = new HarnessSession({
model,
stream,
loadout: appLoadoutFor(model),
env: new LocalEnv({ cwd: process.cwd() }),
tools: [toHarnessTool(recordFinding)],
});
try {
const outcome = await session.runTurn("Inspect this repo and record one key finding.", {
onEvent: (event) => {
if (event.type === "text_delta") process.stdout.write(event.delta);
},
});
console.log(outcome.finalText, outcome.usage);
} finally {
await session.close();
}Model-native loadouts#
A loadout defines the exact prompt sections, tool schemas, limits, and wire flags sent to a model. Every loadout hashes canonically (normalizeLoadout() + loadoutHash()), so benchmarked configurations match production byte for byte.
Cache-stable prefix contract & QuickJS code-mode MCP#
- Deterministic ordering. Built-in, custom, and MCP tools serialize in a fixed order so earlier prefix bytes never shift between turns.
- 270 s Anthropic cache keepalive. Keeps warm prompt caches alive across long-running tool pauses.
- QuickJS code-mode MCP (
with_mcp). Attached MCP servers run inside a sandboxed QuickJS WASM cell with compact one-line tool signatures andask()fan-out, loaded only when MCP servers are connected (connectMcp()/mcpDirectTools()). - Explicit compaction. The
compacttool writes a clean handoff frame rather than mutating earlier cached history.
Published Harness v4 benchmark results#
Each optimization in Harness v4 was evaluated on held-out paired tasks (caveman-ai/agent-sdk README). Local cost figures are inferred, not invoice promises:
Execution environments (LocalEnv, DockerEnv, SandboxEnv)#
Every environment implements the same ExecEnv interface so the same agent runs locally, in Docker, or on Caveman Cloud without changing agent code:
import { SandboxEnv } from "@caveman-ai/harness";
const env = new SandboxEnv({
controlURL: "https://api.caveman.so",
apiKey: process.env.CAVEMAN_API_KEY!,
cwd: "/workspace",
});Headless exit codes#
When driven as a headless subprocess (caveman-harness), exit codes tell schedulers when to reclaim compute: