SandboxEvaluate agents

Evaluate agents

@tangle-network/agent-eval runs your agent on a fixed set of cases, scores each result with a judge, and reports the scores so you can compare one change against another. The sandbox runs the agent; agent-eval runs in your own TypeScript process.

npm install @tangle-network/agent-eval @tangle-network/sandbox

agent-eval needs Node.js 20.19 or later.

WordMeaning
Case (scenario)One task, with an id and a kind.
SurfaceThe thing you change between runs: a prompt, a model, a coding agent or a whole configuration.
JudgeScores one result on named dimensions and returns a composite score.

Score a coding agent on fixed cases

defineAgentEval takes the cases, the agent and the judge. The agent receives the surface and one case and returns an artifact; here, the exit code of the test that case names.

import { defineAgentEval, type Scenario } from "@tangle-network/agent-eval/contract";
 
// client is a Sandbox created with baseUrl "https://sandbox.tangle.tools".
const evalKit = defineAgentEval<Scenario & { task: string }, number>({
  scenarios: [
    { id: "cli-flag", kind: "fix", task: "The test tagged cli-flag fails." },
    { id: "null-guard", kind: "fix", task: "The test tagged null-guard fails." },
    { id: "timezone", kind: "fix", task: "The test tagged timezone fails." },
  ],
  baselineSurface: "claude-code",
  agent: async (harness, scenario) => {
    const box = await client.create({
      git: { url: "https://github.com/tangle-network/sandbox-demo" },
      backend: { type: harness as "claude-code" | "codex" },
    });
    try {
      await box.prompt(`${scenario.task} Fix the cause.`);
      return (await box.exec(`npm test -- --test-name-pattern=${scenario.id}`)).exitCode;
    } finally {
      await box.delete();
    }
  },
  judge: {
    name: "suite",
    dimensions: [{ key: "pass", description: "the tagged test passes after the turn" }],
    score: ({ artifact }) => {
      const pass = artifact === 0 ? 1 : 0;
      return { dimensions: { pass }, composite: pass, notes: "" };
    },
  },
  expectUsage: "off",
});
 
for (const harness of ["claude-code", "codex"]) {
  const result = await evalKit.evaluate({ surface: harness });
  console.log(harness, result.aggregates.byJudge.suite?.mean);
}

evaluate() runs every case against the baseline surface; evaluate({ surface }) runs them against another one. aggregates.byJudge.<name>.mean is the mean composite score.

expectUsage: "off" fits here because the sandbox meters each turn itself. Set expectUsage: "assert" when the agent makes model calls agent-eval should see, so a missing usage record counts as a failure.

To compare models instead, keep the coding agent fixed (OpenCode below; Claude Code and Codex take a model the same way) and pass the model as the surface: backend: { type: "opencode", model: { model: String(surface) } }. Model ids come from GET /v1/router-models with your Sandbox key, or the model list.

Grade text with a model judge

llmJudge scores an artifact against a rubric with a model on the Tangle Router. It works on any text, with or without a sandbox.

import { createChatClient, llmJudge } from "@tangle-network/agent-eval/contract";
 
const judge = llmJudge("support", "Score this reply to the customer's message against the policy.", {
  chat: createChatClient({
    transport: "openai-compatible",
    baseUrl: "https://router.tangle.tools/v1",
    apiKey: process.env.TANGLE_API_KEY!,
    defaultModel: process.env.TANGLE_MODEL!,
  }),
  dimensions: [
    { key: "answers", description: "Answers the question the customer asked" },
    { key: "honest", description: "Promises nothing the policy does not allow" },
  ],
});
 
const score = await judge.score({
  artifact: { message, policy, reply },
  scenario: { id: "refund", kind: "support" },
  signal: AbortSignal.timeout(60_000),
});
console.log(score.composite, score.dimensions, score.notes);

To grade an agent run, pass the run’s answer and tool calls as the artifact: { task, answer: run.response, tools: run.toolInvocations } from box.prompt(). A judge can then score whether the answer is grounded and whether the agent repeated work.

A model judge is itself a measurement. Check it against results you graded by hand before you let it decide a release.

Fail CI when a change scores lower

Score the shipped surface and the candidate on the same cases, and exit non-zero when the candidate scores lower:

const score = async (surface: string) =>
  (await evalKit.evaluate({ surface })).aggregates.byJudge.suite?.mean ?? 0;
 
const before = await score(shippedPrompt);
const after = await score(candidatePrompt);
if (after < before) {
  console.error("Regression: the candidate passes fewer cases.", { before, after });
  process.exit(1);
}

A mean over a few cases moves with noise. For a release rule with uncertainty, heldOutGate from @tangle-network/agent-eval/contract ships a candidate only when the lower bound of the paired interval on its score improvement clears the deltaThreshold you set, on cases held out from any tuning.

Read what a run did

Every sandbox turn is traced. An Intelligence report reads a sandbox’s traces and reports what the agent did:

const job = await client.intelligence.createReport({
  subject: { type: "sandbox", id: box.id },
  mode: "deterministic",
});
const report = await client.intelligence.waitForReport(job.jobId, { timeoutMs: 180_000 });
console.log(report.status, report.billing.costUsd);
console.log(JSON.stringify(report.result, null, 2));

Create the report before you delete the sandbox. See Observability for traces and the Intelligence commands for the CLI.

The complete programs for comparing coding agents and models, grading replies, scoring a trace and gating CI are in eval and runtime examples.

Next