---
title: "Caveman Agent SDK: Build Production Agents on Harness v4"
description: Install @caveman-ai/agent to define, gate, evaluate, and run AI agents in-process on the open-source Harness v4 engine or deploy the exact same definition to Caveman Cloud.
canonical: https://docs.caveman.so/agent
product: Caveman Agent SDK
group: Agent SDK & Harness v4
---

# Caveman Agent SDK: Build Production Agents on Harness v4

> Install @caveman-ai/agent to define, gate, evaluate, and run AI agents in-process on the open-source Harness v4 engine or deploy the exact same definition to Caveman Cloud.

`@caveman-ai/agent` (`caveman-ai/agent-sdk`, Apache-2.0) is the TypeScript Agent SDK built directly on the open-source **Harness v4** engine (`@caveman-ai/harness`). Run an agent in-process with Node.js 22+ and your own Anthropic or OpenAI key (zero daemon, no account required), or run the exact same definition on Caveman Cloud with durable zero-compute parking.

Want to deploy an `AGENT.md` template straight from the CLI with zero TypeScript setup? Go to [Templates & Quick Setups](/templates).

## Install or scaffold a project

```bash
# Add to an existing project (Node.js 22+)
npm install @caveman-ai/agent

# Or scaffold a starter project
npm create @caveman-ai/agent
```

## Run an agent in-process (zero daemon, no account)

Set `ANTHROPIC_API_KEY` or `OPENAI_API_KEY` and run:

```ts
import { defineAgent, runInProcess, tool } from "@caveman-ai/agent";

const lookupInvoice = tool(
  "lookup_invoice",
  "Find an invoice by id",
  { type: "object", properties: { id: { type: "string" } }, required: ["id"] },
  async ({ id }: { id: string }) => ({ id, status: "paid", amountUsd: 42 }),
);

const billing = defineAgent({
  name: "billing",
  instructions: "Answer billing questions briefly using lookup_invoice.",
  computer: "none",
  tools: [lookupInvoice],
});

const result = await runInProcess({
  agent: billing,
  task: "Check invoice 4411",
  model: "anthropic/claude-sonnet-4-6",
});

console.log(result.text);
console.log(result.usage);
```

## Run the exact same definition on Caveman Cloud

Pass your Caveman Cloud API key to `new Caveman(...)` to run durable sessions with zero-compute parking, event logs, and Cloud sandboxes:

```ts
import { Caveman } from "@caveman-ai/agent";

const cave = new Caveman({ apiKey: process.env.CAVEMAN_API_KEY });
const result = await cave.run({
  agent: "billing",
  task: "Check invoice 4411",
  budget: { usd: 1 },
});
console.log(result.text);
```

## Package ecosystem

| Package | License | Purpose |
| --- | --- | --- |
| `@caveman-ai/agent` | Apache-2.0 | `defineAgent`, `tool`, `runInProcess`, `Caveman`, `Session`, `compileAgentFolder`, Caveman Gates, Sensors, plus `@caveman-ai/agent/harness` |
| `@caveman-ai/harness` | Apache-2.0 | Open-source Harness v4 engine (`HarnessSession`, model-native loadouts, `LocalEnv`, `DockerEnv`, `SandboxEnv`, QuickJS code-mode MCP) |
| `@caveman-ai/protocol` | MIT | Canonical `SessionEvent`, `UserEvent`, exit codes `0..6`, and JSON Schemas (`agent-build.schema.json`, `eval-file.schema.json`) |
| `@caveman-ai/evals` | MIT | 30 fail-closed TypeScript graders (deterministic checks, tool-call checks, BLEU/ROUGE, SSRF-pinned webhooks, bias-guarded judges) |
| `caveman-evals` (Python) | MIT | Python eval runner and grader parity |
| `@caveman-ai/react` | Apache-2.0 | React hooks for streaming sessions and approval UIs |
| `@caveman-ai/adapter-kit` | Apache-2.0 | Adapter interfaces for bringing external frameworks onto the Caveman protocol |
| `@caveman-ai/create-agent` | Apache-2.0 | Project scaffolder (`npm create @caveman-ai/agent`) |

## Explore the Agent SDK

- [Harness v4 Engine](/agent/harness): Model-native tool surfaces, QuickJS `with_mcp` code mode, 270 s cache keepalive, and execution environments.
- [Sessions, Gates & Escalation](/agent/sessions-and-gates): Multi-turn streaming sessions, fail-closed Caveman Gates, Sensors, and cheap-first model escalation.
- [Evals, Graders & Protocol](/agent/evals-and-protocol): 30 fail-closed graders, Session Protocol v1 schemas, and the 5 verified starter recipes.
- [AGENT.md Format](/agents/agent-md): Compile identical deterministic `agent.json` manifests from folders or TypeScript.
