Skip to content
Docs
Request access

Add a gate

A gate is a check on a task’s output. A task is done only when every one of its gates passed, and each result is written to the ledger. This guide adds a rule gate to the dev-team template and shows it pass and fail.

The order gates run in on one task The worker's output goes through the task's gates: rule gates and test commands first, then verifier gates, then a human gate. The task is done only when every gate passed. Outputfrom theworker Rules, testsno modelcall Verifierone modelcall Humana persondecides Doneevery gatepassed Outputfrom theworker Rules, testsno modelcall Verifierone modelcall Humana persondecides Doneevery gatepassed
Cheap checks run before a verifier's model call. A task is done only when every gate passed.
Diagram as text
  1. The worker hands in its output.
  2. Rule gates and test commands run first. They make no model call.
  3. A verifier gate runs next. It costs one model call.
  4. A human gate asks a person.
  5. The task is done only when every gate passed.
Kind What checks the output
rule fixed checks on the output: text it must or must not contain, a pattern, a length, a value at a path
test_command a command, such as the project’s tests, run in the sandbox
verifier another agent: Add an independent verifier
human a person: Require a human approval

The template’s team.py has a working example of each of these four.

  1. Open my-team/team.py and find the task fix. Its definition_of_done has criteria, the statements that must be true, and gates, the checks that give evidence for them.

  2. Add a criterion to the criteria of fix, after the fixed criterion.

    Criterion(id="no-debug", text="The fix leaves no debug output behind"),
  3. Add a gate to the gates of fix, between the has-fix gate and the tests gate. checks names the criterion the gate gives evidence for.

    GateSpec(
    id="no-debug",
    kind=GateKind.RULE,
    checks=("no-debug",),
    config={
    "rules": [
    {
    "criterion": "no-debug",
    "check": {"type": "not_contains", "value": "print("},
    }
    ]
    },
    ),
  4. Run the team.

    Terminal window
    nuramesh try my-team --fake --approve-as human:you --allow-unsandboxed --run-id gate-1
type Passes when Keys
contains the text contains value value, case_sensitive (default true)
not_contains the text does not contain value value, case_sensitive (default true)
matches the regular expression pattern matches somewhere pattern
length_between the text has between min and max characters min (default 0), max
path_exists structured output has a value at path path
path_equals structured output has exactly value at path path, value

Text checks look at the output if it is text, and at its JSON form otherwise. A path is dotted keys and [index] steps, for example files[0].name.

The task has a new gate line:

[done] gate-1-fix-add (dana, attempts 1): Fix the failing add() test in calc.py
gate has-fix (rule): passed by gate:rule
gate no-debug (rule): passed by gate:rule
gate tests (test_command): passed by gate:test_command
gate review (verifier): passed by agent:rhea

To see a gate stop a task, change the gate’s "value": "print(" to "value": "return a + b", text the fix must contain, and run again with a new run id:

Terminal window
nuramesh try my-team --fake --approve-as human:you --allow-unsandboxed --run-id gate-2
Tasks: 2 cancelled, 1 needs_human
[needs_human] gate-2-fix-add (dana, attempts 2): Fix the failing add() test in calc.py
gate has-fix (rule): passed by gate:rule
gate no-debug (rule): failed by gate:rule
gate tests (test_command): passed by gate:test_command
note: failed after 2 attempts: no-debug

The developer got the gate’s feedback and tried again, up to the task’s max_attempts. Then the task went to a person. The review gate has no line: the verifier was not called, because a cheaper gate had already failed. The command exits with code 1. Put the value back afterwards.

You see Do this
gate 'no-debug' checks unknown criteria checks names a criterion that is not in the task’s criteria. Step 2 is missing or the ids differ
An error that names the task and the gate, before the run starts The gate’s config is not valid, for example an unknown check type
A gate fails on every attempt Read the gate line and the note, then the check itself: Read a gate result
A test gate refuses to run No container runtime was found: Run in a sandbox

Was this page helpful?