Skip to content
Français

Create a tool for your agent

Expose one sandbox operation to the model, then connect it to a harness.

Start from Give the model tools and its configuration. Expose one sandbox operation to the model, then connect it to a harness.

This tool lets the model run tests inside the sandbox. The model can request the whole suite or select tests by name.

import { z } from "zod";

export const testInput = z.object({ match: z.string().optional() });
export type TestInput = z.infer<typeof testInput>;
import type { TestInput } from "./test-input.ts";
import type { HarnessToolContext } from "@elie-laloum/outpost/harness";

export async function executeTests(
  { match }: TestInput,
  { sandbox, signal }: HarnessToolContext,
) {
  const result = await sandbox.invoke({
    executable: "npm",
    arguments: [
      "test",
      ...(match ? ["--", `--test-name-pattern=${match}`] : []),
    ],
    signal,
  });
  return {
    content: result.stdout + result.stderr,
    isError: result.status !== 0,
  };
}
import { defineHarnessTool } from "@elie-laloum/outpost/harness";
import { testInput } from "./test-input.ts";
import { executeTests } from "./execute-tests.ts";

export const runTests = defineHarnessTool({
  name: "run_tests",
  description:
    "Run the test suite, optionally only the tests whose name matches.",
  input: testInput,
  resources: ({ match }) => ({ command: `npm test ${match ?? ""}`.trim() }),
  execute: executeTests,
});

API reference: HarnessToolOptions, HarnessToolContext and ToolOutput.

A tool name must contain 1 to 64 letters, digits, _ or -. By default, an execution error is sent back to the model as a failed tool result. Set toolExecution.onError: "fail" to stop the turn instead; see Built-in harness.

defineHarnessToolset() bundles tools and other toolsets under one name, so you can share them between harnesses.

import {
  defineHarnessToolset,
  createHarnessFileTools,
  createHarnessSearchTools,
  createHarnessGitTools,
} from "@elie-laloum/outpost/harness";

export const inspect = defineHarnessToolset({
  name: "inspect",
  tools: [
    createHarnessFileTools(),
    createHarnessSearchTools(),
    createHarnessGitTools(),
  ],
});
import {
  defineHarnessToolset,
  createHarnessEditTools,
  createHarnessShellTools,
} from "@elie-laloum/outpost/harness";
import { inspect } from "./inspect-tools.ts";

export const coding = defineHarnessToolset({
  name: "coding",
  tools: [inspect, createHarnessEditTools(), createHarnessShellTools()],
});

Each tool name must be unique across the harness: its tools, nested toolsets and skill tools. A duplicate fails when you create the harness.

Reuse read-model.ts from built-in tools and the setup configuration. Install zod. The repository needs a working npm test; configure the model and its key as on the harness page. Save this file and run node test-agent.ts.

import { createAgent, dispatch } from "@elie-laloum/outpost/core";
import { createHarness } from "@elie-laloum/outpost/harness";
import { repository, sandboxProvider } from "./outpost.config.ts";
import { modelProvider } from "./read-model.ts";
import { runTests } from "./run-tests.ts";

const agent = createAgent({
  model: "claude-sonnet-5-5",
  harness: createHarness({ modelProvider, tools: [runTests] }),
});
const result = await dispatch({
  repository,
  sandboxProvider,
  agent,
  hooks: { sandboxReady: [{ executable: "npm", arguments: ["ci"] }] },
  brief: { text: "Call run_tests and report its result." },
});
console.log(result.text);

The agent can call run_tests and receives stdout, stderr and the command verdict. Its final text is not an enforced check: use a command task when passing tests must gate the next step. execute runs on the host; only context.sandbox runs the command inside the sandbox.