WhoBuilt

Loop Engineering from First Principles

Jul 25, 2026· 18 min· 32K views·Watch on YouTube

Speaker

Kyle Mistele, co-founder of HumanLayer, explains how to build agent loops for complex, production codebases at AI Engineer.

Why blind loops fall short

Mistele argues that prompting coding agents in open-ended loops can produce enormous pull requests that teams cannot review. He says the approach works for some solo projects, but is a poor fit for teams building critical systems with users, service-level agreements, and regulatory obligations. He proposes incremental loops that keep code readable and manageable.

Treat loops as control systems

Mistele uses control theory to describe a loop: measure the current state, compare it with a desired state, choose a change, apply it, and measure again. Thermostats, Kubernetes autoscaling, infrastructure as code, Postgres autovacuum, and React's virtual DOM are examples of control loops. Incremental changes help reduce risk and avoid destabilizing the system.

Build a measurable migration loop

A loop needs a set point, a sensor, a controller, and an actuator. HumanLayer uses ast-grep to find RPC procedures that have not been migrated to Effect, then tracks a deterministic baseline so new procedures can be caught in pull requests. The controller can select the smallest procedure first, or use telemetry such as error rates and instrumentation gaps to prioritize work.

Keep humans in control of the workflow

HumanLayer pairs a coding agent with a skill and hand-written examples called golden patterns, then runs one loop iteration in CI to create a small pull request. A version-controlled feedback file and an “/iterate” comment let reviewers steer revisions without editing the skill by hand. The workflow pauses if a prior pull request from that loop is still open, preventing duplicate work from piling up.

Increase speed as confidence grows

Mistele describes scaling the loop after it proves reliable: select several procedures per run, give each procedure its own implementation phase and context window, or run multiple workflows and assign their pull requests to different teammates. He notes that migrating 150 procedures one at a time could take six months. The goal is more throughput while keeping changes reviewable.

Takeaways

  • Use a measurable target and repeat small changes instead of asking an agent to rewrite a large part of the codebase.
  • Prefer deterministic sensors such as ast-grep when they can identify violations reliably.
  • Give agents hand-written examples of the patterns your team wants them to reproduce.
  • Track reviewer feedback in version control so the loop can learn from corrections.
  • Limit each loop to one open pull request until a human has reviewed its previous result.

Mentioned in this talk

Search inside this talk

What was claimed 6

Related talks