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

Agent step

An agent step is one recorded piece of work by an agent in a run. It starts from a step request, everything the agent gets, and ends with a step output, everything the agent produced. Each time your pipeline asks an agent for work, codeband starts a new agent step.

An agent can act differently each time it runs, even from the same prompt. codeband records the step request of every agent step as it was, so that a run fork starts the agent again from exactly the same files and prompt. A run fork runs in a new run with a changed harness, model, prompt or input, and you compare its step output with the original one.

An agent step: from its step request through one or more attempts to how it ends Step request rendered prompt input attached step artifacts start commit Attempts Attempt 0 harness in a new workspace Attempt 1 harness in a new workspace failed: the engine retries by failure kind Step output typed value, end commit, agent transcript and step artifacts Agent question questions for a person Failed its attempt failure

The write_hello pipeline of the example py-factory runs one agent step of the agent writer. The agent runs on the fake harness, which follows a script and runs no model: its one attempt writes hello.txt and gives a title and a summary.

examples/py-factory/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)
  1. The pipeline calls writer.do(req). The code server renders the prompt template writer.md with the input and sends the agent step to the engine, the part of the daemon that runs agent steps. The engine writes the agent step and its step request to the run journal, the ordered record of everything the run produces.
  2. The engine makes a new workspace, a checked-out commit of the target repository, at the agent step’s start commit. By default the start commit is the run head: the end commit of the run’s last agent step that may write and is not a parallel agent step, or the run’s start commit.
  3. The engine starts the harness in the workspace with the prompt, the agent’s output schema and its timeout. The harness writes the agent transcript while it runs.
  4. When the harness ends, the engine commits the files that the agent changed and did not commit, as codeband: leftovers of writer#0. That commit is the attempt’s end commit. The engine keeps it under a hidden ref and removes the workspace.
  5. The code server checks the title and summary against the agent’s output type, WriterOutput. It accepts them, and the agent step ends with a step output. Because writer may write, the run head moves to the end commit.
  6. After each step, the engine runs the pipeline code again from the start against the run journal: a run replay. From now on, writer.do(req) returns the recorded agent step at once and runs no agent.

The daemon logs the agent step as the step writer#0, with its attempt inside it:

Daemon log
Nov 24 15:34:32.890 INF Step started run=s2qp2v059p step=writer#0
Nov 24 15:34:32.940 INF Attempt started run=s2qp2v059p step=writer#0 attempt=0
Nov 24 15:34:33.047 INF Attempt finished run=s2qp2v059p step=writer#0 attempt=0 cost_usd=0
Nov 24 15:34:33.071 INF Step finished run=s2qp2v059p step=writer#0

The end commits live in the daemon’s own clone of the target repository, never in yours (see Architecture). RUN-ID is the ID of the run:

Ref Points to
refs/codeband/runs/RUN-ID/attempts/writer/0/0 The end commit of attempt 0 of agent step writer#0. Every attempt keeps its ref, failed ones too
refs/codeband/runs/RUN-ID/agent_steps/writer/0 The end commit of the agent step, from the attempt that gave its step output

The step request holds the rendered prompt, the input, the start commit and the sandbox: the name of its sandbox definition, its kind and, for a container, the ID of its image. The agent may explore the files of its start commit, and the harness may pass instruction files from it, such as a CLAUDE.md, to the agent.

A step request can also hold attached step artifacts: content-addressed files such as a spec or a log. An agent step can produce step artifacts too. Code changes are never step artifacts; they are commits.

codeband adds nothing else to what the agent sees, apart from the programs of its sandbox. Information from outside the start commit, such as a CI log, reaches the agent only through the step request. Without this rule, a run fork could not start from the same conditions as the agent step it repeats.

An attempt is the harness working on an agent step once. Every attempt runs in a new sandbox, the isolated place that holds the harness program and a new workspace at its start commit, and the engine removes the sandbox when the attempt ends. Nothing carries over between attempts, not even ignored files such as a .venv folder or build output. An agent step then depends only on what its step request records, so a run fork on another machine sees the same files, and a new attempt never meets a process that a stopped harness left running.

When an attempt fails, the engine starts a new attempt of the same agent step, a retry, depending on the kind of its attempt failure. Each kind has its own count of retries in one agent step. The step output and the end commit come from the last attempt, and the cost of the agent step is the sum of the known costs of its attempts.

Attempt failure kind The attempt The engine
rate_limit Hit the rate limit of the model’s API Retries after 5 minutes, then after 15 more minutes. --rateLimitBackoff of codeband daemon sets these waits and their number
api_error Got a server error from the model’s API, or lost its connection to it Retries once, at once
crash Stopped because its harness process stopped Retries once, at once
invalid_output Gave no structured result, or one that does not fit the agent’s output type Retries once, at once, in a workspace at the end commit of the failed attempt. The prompt of the retry adds the error text and asks the agent to check its changes and give the step output again
timeout Ran longer than the agent’s timeout, 30 minutes by default. The engine stops it Does not retry
cancelled Was stopped because someone cancelled the run, or because the run failed while the agent step ran Does not retry
setup Could not start, because its harness has no login, a variable of codeband.toml has no value, or its harness program is missing or too old Does not retry
error Failed for another reason, such as an end commit that does not descend from the start commit, or an end commit with conflict markers. When changed pipeline code no longer reaches the agent step, the attempt fails with the pipeline stopped before it reached the agent step, and the run goes on from where the new code stopped Does not retry

Every other retry starts at the start commit of the attempt before it, with its prompt. When the run is cancelled or fails while the engine waits for a retry, the agent step ends with cancelled. Each attempt keeps its own hidden ref, so the changes of a failed attempt stay readable.

End What pipeline code gets
Step output The agent step: the step output checked against the agent’s output type, the end commit and the cost. For an agent that may only read, it also lists the files that the agent changed. The run journal also records the agent transcript
Agent question The agent’s questions for a person
Failed An error with the agent step’s step ID, the attempt failure kind of its last attempt and a message, such as cb.AgentStepFailedError in Python. The run head does not move

The end commit holds the agent’s own commits and the files it left uncommitted. An agent set to discard its leftovers drops those files instead. An agent step whose agent may only read has its start commit as its end commit, and the engine discards the files the agent changed.

A failed agent step that your pipeline does not catch fails the run. Catch the error where the run can go on, or stop the run with a reason. Here, the agent step of the agent fixer timed out:

@cb.pipeline
def fix_or_stop(problem: str) -> None:
try:
fixer.do(FixInput(problem=problem))
except cb.AgentStepFailedError as err:
raise cb.Stop(f"{err.step_id} failed with {err.kind}") from err

codeband run prints stopped: fixer#0 failed with timeout and exits with code 3.

An agent that cannot go on without a decision from a person returns an agent question, its questions for that person, in place of a step output, and its agent step ends. Your pipeline asks the questions at a human step, a typed question to a person, and the run waits there with no agent running. The answer goes into the step request of a new agent step.

An agent step never pauses a live harness to wait for a person. A paused harness would hold a process for hours, would fail where nothing can wait, such as on a CI runner, and would make the agent step impossible to record as one unit and replay.

  • Agent defines the prompt, the harness and the input and output types that every agent step of the agent uses.
  • Run fork branches off a run at a chosen agent step to run it again with changes.
  • Run explains the run journal that records each agent step and the ways a run ends.
  • The Python SDK reference lists cb.Agent, cb.AgentStep and cb.AgentStepFailedError.