Skip to content
codeband is pre-release. These docs describe its first release, and some of what they describe is still being built.

Agent

An agent is a reusable role that your pipeline hands work to. It has a prompt template, a typed input and output, and a harness and model that do the work. Each time pipeline code asks an agent for work, codeband runs one agent step of it and records that agent step.

A coding agent that you start by hand reads free text and leaves its changes in your working tree. An agent in codeband gets a typed input, must report a step output that codeband checks against its output type, and leaves its changes as a commit. Pipeline code can then branch on what the agent reported, give it to the next agent or end the run with the agent’s commit. codeband records everything an agent step started from, so you can repeat it later on another harness or model and compare the two agent steps.

How one agent step of an agent goes from pipeline code to a step output Pipeline code asks the agent for an agent step with an input of its input type Step request rendered prompt input start commit Harness Claude Code, Codex CLI or the fake harness, in a new workspace Step output checked output end commit, cost agent transcript render record check recorded in the run journal and returned to the pipeline, also on every run replay

The example factory py-factory defines the agent writer and the pipeline write_hello. write_hello runs one agent step of writer and ends the run with the agent step’s commit. The prompt template writer.md sits next to the module that defines writer.

py_factory/hello.py
"""The pipeline write_hello: one agent step that writes a file, and a run that ends with that change.
The agent runs on the fake harness, which follows a script and runs no model, so the agent step writes the same file on
every run.
"""
import codeband as cb
class WriterInput(cb.Model):
"""The instruction for the writer. The prompt writer.md shows it to the agent."""
instruction: str
class WriterOutput(cb.Model):
"""What the writer reports at the end of its agent step."""
title: str
"""Title of the change, one line."""
summary: str
"""What the agent step changed and why."""
writer = cb.Agent(
"writer",
input=WriterInput,
output=WriterOutput,
harness=cb.Fake(
attempts=[
cb.FakeAttempt(
text=["writing hello.txt"],
write={"hello.txt": "hello\n"},
output={"title": "Add hello.txt", "summary": "The writer added hello.txt, which says hello."},
)
]
),
)
build = cb.Stage("build")
@cb.pipeline(stages=[build])
def write_hello(instruction: str = "add a file hello.txt that says hello") -> cb.RunResult | None:
"""Run one agent step of the writer in the stage build and end the run with its commit.
The writer may write, so its agent step ends in a commit. The file it leaves uncommitted goes into that commit too.
"""
with build:
agent_step = writer.do(WriterInput(instruction=instruction))
change = cb.CodeChange(
commit=agent_step.commit, title=agent_step.output.title, description=agent_step.output.summary
)
return cb.RunResult(code_change=change)
py_factory/writer.md
Do this task in the repository: {{ input.instruction }}

writer runs on the fake harness, which follows a script and runs no model. Every agent step of it writes the same hello.txt and reports the same step output, so the example runs anywhere and its tests can check it.

An agent for real work names Claude Code or Codex CLI as its harness. The rest of the agent, and the pipeline that uses it, stay the same.

Part What it sets
Name The name of the role, such as writer. It is part of the step ID of every agent step, such as writer#0
Prompt template A Markdown file in Jinja syntax that reads the agent step’s input as input. By default it is NAME.md next to the module that defines the agent
Input type The fields that pipeline code passes to each agent step
Output type What the agent reports at the end of an agent step. The harness gets its JSON Schema, and the code server checks each step output against it
Harness The coding agent program that does the work, with options that are typed for that harness
Access write moves the run head to the end commit of each agent step, so the next agent step starts from it. read leaves the run head where it is. A parallel agent step never moves it
Timeout How long one attempt may run before the engine stops it: 30 minutes by default
Leftovers What happens to the files that the agent changed but did not commit: commit puts them into the end commit, which is the default, and discard drops them

The run head is the commit where the next agent step or shell step starts unless pipeline code names another commit. The Python SDK reference lists every parameter with its type and default.

An agent also sets the model that its harness uses, its permissions and its budgets. A budget limits the number of agent steps or the cost of an agent. Going over a budget opens a human step, a typed question that a person must answer before the run continues.

The code server, the engine and the harness each do one part of an agent step of writer in write_hello.

  1. Pipeline code passes an input of type WriterInput. The code server renders writer.md with it. The rendered prompt, the input and the start commit make up the agent step’s step request. The start commit is the run head, unless pipeline code names another commit.
  2. The engine records the step request in the run journal, the ordered record of everything the run has produced. It creates a new workspace, a checked-out copy of the target repository at the start commit, and starts the harness in it with the rendered prompt and the JSON Schema of WriterOutput.
  3. The agent works in the workspace and reports its step output. When the attempt ends, the engine commits the files that the agent left, and records the end commit, the cost, the agent transcript and the version of the harness.
  4. The code server checks the step output against WriterOutput. A step output that does not fit fails the attempt with the attempt failure kind invalid_output.
  5. Pipeline code gets the agent step: its step ID, its step output, its end commit and its cost. writer may write, so the run head moves to the end commit.

codeband moves a run forward by run replay: it runs the pipeline again from the start, and each recorded step returns its recorded value. A recorded agent step returns at once, and the agent does not run again.

An agent step runs as one or more attempts. Each attempt has its own new workspace, which the engine removes when the attempt ends. An agent step that ends without a step output raises cb.AgentStepFailedError in pipeline code, and the run head does not move. Pipeline code may catch the error; an uncaught one fails the run.

The engine retries a failed attempt depending on the kind of its attempt failure, such as rate_limit or crash, as Attempts and retries lists. The step output comes from the last attempt.

The daemon logs each agent step as a step, and each attempt inside it. In this run of write_hello, the agent step writer#0 has one attempt, and the run ends after it.

Daemon log
Nov 24 15:34:38.336 INF Step started run=exhbsffwc8 step=writer#0
Nov 24 15:34:38.389 INF Attempt started run=exhbsffwc8 step=writer#0 attempt=0
Nov 24 15:34:38.498 INF Attempt finished run=exhbsffwc8 step=writer#0 attempt=0 cost_usd=0
Nov 24 15:34:38.524 INF Step finished run=exhbsffwc8 step=writer#0
Nov 24 15:34:38.632 INF Run finished run=exhbsffwc8 status=finished reason=""

The run ends with a code change built from the agent step’s end commit and step output. The engine delivers that code change to its run result destination: a patch file or a pull request.

The prompt template holds only the prompt. It is a Jinja template, rendered in Jinja’s sandbox, whose only value is input, the agent step’s input. {{ input.instruction }} in writer.md prints the field instruction of WriterInput. Conditions and loops work too: a section between {% if input.FIELD %} and {% endif %} shows only when the field is set. A text field prints as it is, an empty value as empty text, and any other value as JSON indented by two spaces.

The code server checks the syntax of every prompt template when it loads the factory, so a template that is not valid Jinja fails before any run starts. It does not check field names. If writer.md named {{ input.taks }}, loading py-factory would succeed, and the run would fail when the prompt of the first agent step of writer renders. The prompt templates reference lists the error for each mistake.

Harness, model and every other setting live on the agent in code, not in the Markdown file. The same prompt can then run on harnesses whose options differ. Harness options are typed, so a wrong option fails when the code server loads the factory instead of during an agent step.

A harness is an existing coding agent program, such as Claude Code, that codeband drives to run the agent steps of an agent. codeband has no agent loop of its own. Harnesses get better faster than codeband could keep up with, and your team keeps the harness it already knows. codeband works between the agent steps: it checks their contracts, records them and replays the run.

Harness What it runs Use it for
Claude Code The claude CLI, with the model you choose Real work
Codex CLI The codex CLI, with the model you choose Real work
Fake No model. Each attempt writes the files, the commit and the step output that its script names Tests and examples, such as writer

Each harness has its own options type. An option that only one harness has stays available, and codeband never reduces the harnesses to the options they share. codeband harness list lists the harnesses and whether each one can run on your machine.

Pipeline code can run one agent step on another harness than the agent’s, with the same name, prompt template and types. A run fork does the same for an agent step that a run already recorded, in a new run.

One agent step can also run on another model than the agent’s.

Put everything the agent needs in its input

Section titled “Put everything the agent needs in its input”

codeband adds nothing to what an agent sees. An agent step starts from its step request and from the files of its start commit, which include instruction files such as AGENTS.md that the harness can read. Information from somewhere else, such as a CI log or the text of an issue, goes into the agent’s input. A run fork then starts from the same step request and the same files as the agent step it repeats.

The name is part of the step ID of every agent step, such as writer#0. Run replay finds a recorded agent step by its step ID, so a run that has agent steps of an agent cannot continue after you rename that agent.

Report decisions in the step output and code in commits

Section titled “Report decisions in the step output and code in commits”

The end commit carries the agent’s changes to the code. The output type holds what pipeline code needs to decide the next step, such as a title, a summary or a verdict. WriterOutput holds the title and the description of the code change, and its commit comes from the agent step.

An agent that cannot go on without a decision from a person does not wait inside its agent step. The agent step ends with an agent question: the agent’s questions for a person. Pipeline code asks those questions at a human step, and the answer goes into a new agent step. An agent step that waited would hold a harness process open for hours, could not run where nothing can wait, such as a CI runner, and could not be replayed as one recorded unit.

Pipeline code can also start several agent steps at once and wait for all of them, for example three agent steps at the same fix. These parallel agent steps all start at the run head and never move it, also when their agent may write. codeband never merges their code on its own. The pipeline picks one agent step, or runs an explicit merge function step. Pipeline has the rules.

An agent step runs only inside a run, where a harness runs the agent. A test gives each agent step its step output instead and checks what the pipeline does with it, as Test a pipeline without a daemon shows. Such a test runs no agent, so it doesn’t check the agent’s work. It does render the agent’s prompt with each input, and tests/test_hello.py of py-factory also compares a rendered prompt with the text it should be.

Every attempt starts in a new workspace at its start commit. Files that git ignores, such as .venv or build output, do not carry over from an earlier agent step or shell step. An agent that needs installed dependencies installs them in each attempt; tool caches outside the workspace, such as the cache of uv, keep that fast.

  • Agent step follows one agent step from its step request to its step output.
  • Run fork repeats a recorded agent step with another harness, model, prompt or input.
  • Run result explains how the engine delivers the code change at the end of a run as a patch file or a pull request.
  • The Python SDK reference lists the agent API, the prompt template syntax and the options of each harness.