Loops and Graphs in Antigravity: Stopping Agent Babysitting with Deterministic Checks and Final Approval Gates

By | November 20, 2026

Most people babysit AI agents because nothing else is checking their work. You watch every step, approve every intermediate edit, and still end up with slow, linear execution.

Inspired by Hanako’s breakdown in Loops and Graphs: how to stop babysitting agents and only approve the last step (mined in 03-Resources/Clippings/2026-11-20 – Loops and Graphs how to stop babysitting agents and only approve the last step (.md), I implemented a reusable Loops-and-Graphs workflow template for Antigravity (agy): /home/gvoina/scripts/loop_graph_workflow.py.


The Core Split: Loops vs. Graphs

  • A Loop makes a single unit of work correct without you: produce -> deterministic check -> fix -> repeat until green. The check must be evaluated by code (exit codes, test suites, linters, schema validators)—never another LLM saying “looks good.”
  • A Graph shapes the work: what runs in parallel, what depends on what, and where the single human approval gate sits.

How It’s Implemented in agy

loop_graph_workflow.py wires Antigravity’s run_workflow primitives (parallel, phase, agent, log) into three stages:

  1. Parallel Graph Fan-Out (parallel): Every independent task in args["tasks"] runs concurrently in its own agent() context.
  2. Deterministic Check Loop (run_checked_loop): Each worker executes its task, then run_deterministic_check(check_cmd) runs a real shell command. If the exit code is non-zero, the trailing stdout/stderr is fed back into the same worker’s next turn—up to max_iters.
  3. Single Final Approval Gate: Once all nodes are GREEN, the workflow prints a concise summary and stops before running final_cmd, unless approved=True is explicitly passed.

How-To: Running a Loops-and-Graphs Workflow

Pass loop_graph_workflow.py to run_workflow with your tasks, deterministic check_cmds, and a gated final_cmd:

run_workflow(
    ScriptPath="/home/gvoina/scripts/loop_graph_workflow.py",
    Description="Fix and verify independent modules before deploying",
    Args={
        "tasks": [
            {
                "name": "api-tests",
                "prompt": "Fix the failing pagination edge case in api/routes.py.",
                "check_cmd": "pytest -q tests/test_routes.py",
            },
            {
                "name": "cli-lint",
                "prompt": "Resolve type and lint warnings in cli/main.py.",
                "check_cmd": "ruff check cli/main.py",
            },
        ],
        "max_iters": 3,
        "workspace": "share",
        "final_cmd": "git commit -am 'Fix pagination and lint' && git push",
        "approved": False,
    },
)

When all nodes report GREEN, review the summary and re-run with "approved": True to execute final_cmd.


How to Use It Effectively

  1. Write the check_cmd first: If you can’t express “done” as a command that exits 0 (e.g., pytest, ruff, bash -n, antigravity_eval.py), you don’t have a loop—you have a scheduler.
  2. Don’t chain independent tasks: Only put tasks in sequence if one literally consumes the other’s output. Otherwise, put them in tasks so parallel() runs them together.
  3. Use workspace="share" for parallel code edits: If multiple workers edit files in the same repo concurrently, give each its own working copy with "workspace": "share".
  4. Cap max_iters at 3–4: If an agent can’t fix a deterministic failure in 3 attempts, more iterations usually burn tokens; let it surface the failure at the gate.
  5. Gate only the last step: Keep intermediate checks autonomous and reserve approved=True for irreversible actions (pushes, deploys, publishes, or payments).

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.