Skip to content

How to build

How to build an open-source agent harness, one file at a time

An agent harness grows from the failures you actually hit. Each step in this build lands one file in your repo, with the command that creates it and the check that proves it worked. Kortix is the open-source CompanyOS, and it is what I would build on; I work at Kortix, so weigh that accordingly.

The manifest lists the agents and what each may use

kortix.yaml
# yaml-language-server: $schema=https://kortix.com/schema/kortix.schema.json## {{projectName}}: the Kortix workspace manifest. Agents, what each may use,# triggers and sandboxes live here, committed beside your files.# Reference: https://kortix.com/docs/developers#kortixyaml-reference
Source: https://github.com/kortix-ai/CompanyOS/blob/dev/packages/starter/templates/base/kortix.yaml

The manifest’s opening comment: agents, what each may use, triggers and sandboxes live in it, committed beside your files.

1. Pick the job that already fails, and give it one file

A harness written before the first failure is a guess about what the agent will get wrong. Pick one job it does badly today, in one repo. Start there with a single file.

If the harness itself is still an open question, the best agent harness comparison answers that first, on where each one keeps its rules.

kortix init creates the workspace directory from the general starter and runs git init -b main (Kortix docs). Copy the general agent file, agents/worker.md, to agents/invoice-triage.md and cut the body down to the job. kortix init writes a kortix.yaml with no version line. The agent's block in kortix.yaml holds the description, mode, permission and prompt_file, a repository-relative path to a .md that carries the prompt alone, with no frontmatter (Kortix docs). A workspace made before this format still works unchanged: a kortix.yaml with kortix_version: 2, or a kortix.toml (kortix_version = 1) with no kortix.yaml beside it. Its owner converts it with kortix validate --fix, which rewrites the files in place.

curl -fsSL https://kortix.com/install | bash
kortix init

What to check after this step: start a session on the new agent and ask what it produces and what it refuses. If the answer is still the general worker's, the job never reached the file, and every later step is built on the wrong agent.

2. Write the guide as a map, not a manual

The instruction file travels with every turn, so it should be short and mostly pointers. Conventions that apply to every task stay in it. Each procedure one kind of task needs moves to its own file under docs/.

A three-person team built a one-million-line codebase over five months, with roughly 1,500 merged pull requests and no code written by hand. It shrank its AGENTS.md to about 100 lines acting as a map to a structured docs/ directory (Milvus). The file stayed readable because it stopped carrying the procedures.

What to check: every path the map names has to resolve, so run test -f over the list. Then start a session and ask for a convention you know exists. If the agent cannot name that file, the rule never reached it.

3. Give the session its own sandbox and its own branch

A harness that can damage the trunk is one nobody lets run unattended. The manifest grants the workspace per agent. workspace: { project_repository: true } gives new sessions a checkout of the repository, on the session's own branch (kortix.yaml). One isolated sandbox per session. Each session has its own isolated machine and branch.

kortix ship
kortix sessions new --prompt "Reproduce the failing invoice total test and stop there"
kortix cr ls

What to check: break a file inside the session, then confirm main has not moved. kortix cr ls stays empty until that session pushes and opens one. That is the property you want, because a bad run then costs the time it took and nothing else.

4. Declare the tools, and omit the grants the job does not need

One grant, one line in the block, and a line you leave out is a capability the agent does not have, which keeps a scoped specialist locked down. The exception is tools, which runs as all until you name the tools instead (Kortix docs). Write the three or four grants the job needs and leave the rest out. tools: takes an allow list or an exclusion list, so the narrow version is a short list of names rather than a wide list with holes cut in it.

The rule to hold while you write it: the agent gets the tools its job needs. One more is a decision someone makes on purpose. A shell tool granted so the agent can read a log file also reaches the network, and the permission is wider than the reason you wrote down.

What to check: have the session call a connector you did not grant, and read the refusal. Then add that one grant and watch the same call succeed. A denial nobody has triggered is a line in a file, and the person who tests it first is usually reading an incident.

5. Attach the first deterministic sensor, with the fix in its message

Guides steer the agent before it acts. Sensors check what it produced after (Martin Fowler). Start with the cheap half: a test, a lint rule, a type checker or a structural analysis is pure CPU work, deterministic and fast. AI code review and a model as judge read for meaning instead, and they are slower, dearer and less repeatable, so they belong on a sample rather than every change.

The file is a script, scripts/check-imports.sh, wired as a pre-commit hook so it runs on the way in. Put the remedy in the failure text. The custom linters in the OpenAI field report enforce one dependency direction and carry the fix instruction in the error message (Milvus). That difference separates a check an agent can act on from one it retries blind.

kortix sessions new --prompt "Write scripts/check-imports.sh, wire it as a pre-commit hook, and prove it fails on a seeded violation"

What to check: seed the violation yourself and read the output. The message names the file, the rule and the next action, and the hook refuses the commit. A message that prints a rule number and nothing else is written for a person who already knows the rule.

6. Put the review gate before main

The last control is the one that keeps a bad guide from spreading. Session work reaches main through a change request. Merge is default-deny for agents. The file for this step is .github/CODEOWNERS, which names the people whose review a path requires. The gate gets a name in the repo as well as in a policy page.

The grant behind that gate is worth a check on a new workspace. The starter's worker agent is created with every permission (kortix_permissions: "*"), so the API permits a session to merge its own change request; the kortix-system skill asks the agent to wait for you, and that request is the only thing holding it (Kortix docs). Rewrite the grant as a list of the permissions the job needs and drop project.gitops.merge from it. kortix validate --scopes prints the valid names, and an agent that cannot merge gets 403 CR_SELF_MERGE_REFUSED when it tries.

kortix cr ls

What to check: open one change request from a session, then ask the agent to merge it. Read the 403 and confirm the request is still open and the branch unmerged. If the merge goes through, the grant still carries project.gitops.merge and the gate is an instruction. Then read the diff as a reviewer would. The harness change and the check that proves it belong in the same request. Split across two, the next session inherits a rule with no evidence.

7. Keep the failure log, and re-run the task that failed

Every harness change starts as a failure, and the log is where the failure stops repeating. docs/failures.md takes one row per failure: the command, the error, the file that fixed it, the commit. A row without a commit is a note to yourself. It dies with the session.

kortix sessions new --prompt "Re-run the invoice total fix on a fresh branch and report which check fired"
kortix cr ls

What to check: run the same task again in a fresh session, and watch for the sensor to fire before the agent repeats the mistake. Then read the log row and follow it to the commit. If the re-run produces the same failure, the fix went into the conversation and never into the environment.

Two mistakes that cost the most

The first is the instruction file that grows into a manual. Every incident adds a paragraph until the file is too long to load comfortably, and the rules that matter sit in the middle where nobody reads them. Keep the map short and push each procedure into the file that needs it.

The second is a harness check where a capability belongs. New behavior in Kortix is built behind a capability, never behind a check on which harness is running (the harness boundary). A capability names what a box can do, so a second adapter implements it instead of branching on a name.

Four paths sit above the runtime's own folders: AGENTS.md, agents/<name>.md, skills/<name>/SKILL.md and tools/<name>.ts, plus memory/ for the workspace brain (Kortix docs). kortix init writes AGENTS.md for Codex, pi and Cursor, and tools/ holds the tools a workspace registers itself: the starter ships no tools/ folder. Everything under them belongs to the runtime that reads it, and the open-source page walks that split folder by folder, down to the starter template that creates a new workspace. Keep your own rules in the four paths above and a later adapter change is a code edit in one module; edit the runtime's folders instead, and you have started a fork.

Questions that come before the first step

How long does it take to build a harness?

An afternoon gets you through the first four steps, and a week of real work through the rest. The build is small because each step is one file; the time goes into waiting for failures worth fixing, not into writing configuration.

Do you need a framework?

No. A harness is a few files in the repo your agent already runs from: an agent file, a short guide, a manifest, a check and a change request. A framework helps when you want to swap the runtime underneath, which is a different problem from getting the rules written down.

Can you build one on top of an existing agent?

Yes, and that is the cheaper start. Keep the agent you run today, add AGENTS.md and one deterministic check, then move the repository into a workspace that gives each session its own branch so a bad run costs nothing.

Grow the harness in a repo you own

Install the CLI, scaffold one agent, and let the first failure write the first rule.