Loop Engineering from First Principles

AI Engineergo watch the original →

Avoid massive, unreviewable AI-generated pull requests by implementing incremental control loops that treat code migration as a feedback-driven system.

The Control Loop Architecture

Instead of using agents to generate large, monolithic pull requests, developers should design control loops that treat the codebase as a dynamic system. By applying principles from control theory, engineers can define a set point (the desired end state), use a sensor to measure the current state, and employ a controller to emit incremental changes. This approach minimizes risk by ensuring that each iteration produces a small, readable, and verifiable change rather than a massive diff that requires blind trust.

Implementing Incremental Migrations

The author demonstrates this by migrating an RPC API to Effect, using a structured loop to manage the process:

  • Sensor: Use ast-grep to identify unmigrated procedures. This tool is language-agnostic and operates outside of standard configuration files, making it robust against AI-generated overrides.
  • Controller: Sort violations deterministically and select the smallest unit of work to reduce the scope of each change. For advanced use cases, the controller can ingest telemetry data to prioritize procedures with high error rates or poor instrumentation.
  • Actuator: Pair an agent with a specific "skill" and a set of handwritten "golden patterns." These patterns serve as idiomatic templates that prevent the agent from hallucinating or relying solely on outdated internet knowledge.
  • Flow Control: Prevent stacked, unreviewed pull requests by checking for existing open PRs labeled by the loop before initiating a new iteration. If an unmerged PR exists, the loop halts to ensure human oversight.

Human-in-the-Loop Feedback

To maintain control without high friction, track a feedback markdown file in version control. This file is loaded into the agent's context during each iteration. By adding a comment trigger (e.g., /iterate) to the PR, developers can provide instructions that the agent uses to refine the code and update the feedback file, creating a persistent, versioned history of the loop's steering logic.

  • #ai
  • #dev-tooling
  • #automation

summary by google/gemini-3.1-flash-lite. probably wrong about something. check the source.