Skip to content

Write your first writ

This procedure creates a writ, runs it, and shows the result. The example agent makes one failing test pass.

Before you start, do these two things:

  1. Go to the root directory of your project.

  2. Run this command:

    Terminal window
    writ init bug-fixer

The command creates bug-fixer.yaml. The file contains the three necessary fields and some example bounds in comments.

writ: bug-fixer
mandate: ""
grants: []
# bounds:
# iterations: 25
# cost: $1.00
# wall_clock: 15m

To include each optional field, add the --full flag.

  1. Open bug-fixer.yaml.

  2. Replace the contents with these terms:

    writ: bug-fixer
    mandate: "The failing test {failing_test} passes without breaking other tests."
    grants:
    - read: { paths: ["**/*"] }
    - shell: { commands: ["pytest *"] }
    - edit: { paths: ["src/**"] }
    bounds:
    iterations: 40
    cost: $2.50
    wall_clock: 20m
    invariants:
    - { layer: letter, no_edits_outside: ["src/**"] }
    satisfaction:
    all:
    - { layer: letter, run: "pytest {failing_test} -x -q", exit: 0 }
    remedies:
    on_bound_breach: { do: halt, inform: issuer }

The name in braces is a placeholder. You give the placeholder a value when you issue the writ. Read more about placeholders.

The invariants clause stops the agent from a change outside src. The satisfaction clause is the proof of completion: the test command must exit with code 0.

  1. Run this command:

    Terminal window
    writ check bug-fixer.yaml
  2. If the command prints an error, correct the file. Then do step 1 again.

The command prints bug-fixer.yaml: valid when the file is correct.

To see the terms with each default value applied, add the --explain flag.

  1. Run this command. Use the name of a test that fails in your project:

    Terminal window
    writ issue bug-fixer.yaml --set failing_test=tests/test_sync.py::test_retry

The registrar starts the run. The registrar shows each action, each check, and each decision while the run continues.

The run stops for one of these three reasons:

  • The satisfaction clauses pass. The exit code is 0.
  • A bound stops the run, or an invariant stops the run. The exit code is 1.
  • An error stops the run. The exit code is 2 or 3.

Read more about exit codes.

  1. Run this command:

    Terminal window
    writ record bug-fixer

The command shows the last run. Each line shows one action and the checks that applied to that action.

To see the record in a browser, add the --web flag:

Terminal window
writ record bug-fixer --web