AI tools are usually introduced through prompting: you ask a question, receive an answer, and then decide what to ask next.

That works well for one-off tasks. But it becomes tiring when the work contains the same repeated cycle:

  • give the AI a task;
  • check what it produced;
  • explain what failed;
  • ask it to fix the problem;
  • repeat until the result is acceptable.

Loop engineering moves that repeated coordination into the system itself.

Instead of manually prompting an AI agent at every step, you design a workflow that gives it a goal, lets it act, checks the result, feeds the evidence back into the next attempt, and stops when the goal has been reached or human approval is required.

The basic process looks like this:

Goal → Act → Check → Learn → Act again → Stop

The important part is not simply that the task runs automatically. The important part is that each result affects what happens next.

A Scheduled Task Is Not Necessarily a Loop

A scheduled task usually runs an instruction at a particular time:

Every weekday at 9:00 a.m. → Generate a report

It may run repeatedly, but each run can still be independent. The system does not necessarily inspect the previous result, react to errors, or decide whether more work is needed.

A loop-engineered workflow adds a feedback relationship between the steps:

Generate report
→ validate the data
→ identify missing sections
→ regenerate those sections
→ validate again
→ publish when complete

A schedule can trigger a loop, but the schedule itself is only the starting signal.

A useful distinction is:

  • Scheduling decides when the process begins.
  • Loop engineering decides how the process continues.

The Core Parts of an AI Loop

A reliable loop needs more than a long prompt. It needs a small system around the agent.

1. A Trigger

Something must start the process.

The trigger could be:

  • a scheduled time;
  • a new GitHub issue;
  • a failed CI workflow;
  • a support request;
  • a new file in a folder;
  • a change in a monitored data source.

The trigger tells the loop that work is available.

2. A Clear Goal

The agent needs to know what success looks like.

“Improve the project” is too broad. A better goal would be:

Implement the feature described in the issue, pass the existing tests, and open a draft pull request without deploying or merging it.

A clear goal prevents the agent from expanding the scope indefinitely.

3. Context and Tools

The agent needs access to the information and tools required for the current task.

For a coding loop, that may include:

  • repository instructions;
  • the relevant source files;
  • the GitHub issue;
  • a terminal;
  • tests and linting tools;
  • GitHub access for creating a branch or pull request.

Without the right context, the loop can repeat perfectly while repeatedly doing the wrong thing.

4. Action

The agent performs the next useful step based on the current state.

It may write code, update a document, classify an issue, create a report, or call another tool. Unlike a fixed script, the agent can choose a different next action when the situation changes.

5. Verification

The output must be checked using real evidence.

For software development, verification might include:

  • unit tests;
  • type checking;
  • linting;
  • build results;
  • browser screenshots;
  • API responses;
  • a separate review agent;
  • human review.

This is one of the most important parts of loop engineering. The agent saying “done” is not proof that the task is complete.

6. Feedback and State

The result of the verification step becomes input for the next attempt.

Test fails
→ read the error
→ identify the likely cause
→ change the code
→ run the test again

The loop may also save state between runs, such as completed tasks, previous failures, generated reports, or review comments. This prevents it from forgetting what has already happened.

7. A Stopping Condition

Every loop needs a reason to stop.

Possible stopping conditions include:

  • all tests pass;
  • the output matches a schema;
  • the pull request has been created;
  • a maximum number of attempts has been reached;
  • the cost or token budget has been reached;
  • the agent encounters a decision that requires a human.

Without a stopping condition, an agent can continue retrying, consume resources, or create unnecessary changes.

A Practical Coding Example

Imagine a repository where issues with the label agent-ready can be handled by a coding agent.

The workflow could be:

New agent-ready GitHub issue
→ read the issue and repository instructions
→ create an isolated branch
→ implement the requested change
→ run linting, tests, and the build
→ inspect failures
→ fix the code
→ run the checks again
→ review the final diff
→ open a draft pull request
→ stop for human approval

The agent is doing most of the repetitive work, but the human still controls the important final decision: whether the change should be merged.

This is much more useful than a scheduled task that simply tells an AI, “Work on the repository every morning.” The loop has a work source, a goal, verification, boundaries, state, and a human gate.

Does Loop Engineering Remove Humans?

Not necessarily.

Loop engineering is about choosing where human judgment is needed instead of requiring a person to guide every small step.

There are three common models:

Human in the Loop

The agent pauses for approval during important stages.

Agent creates a plan → human approves → agent implements

This is useful for risky, ambiguous, or high-impact tasks.

Human on the Loop

The workflow runs mostly by itself, while a person monitors it and can intervene.

Agent processes routine tasks → human reviews alerts and exceptions

This works well when the process is reliable but still needs supervision.

Human at the Final Gate

The agent completes the work and prepares the result, but a person controls the irreversible action.

Agent writes code → tests it → opens a PR → human merges

For software development, this is often the most practical starting point.

Loop Engineering vs Prompt Engineering

Prompt engineering is still useful, but it solves a smaller problem.

ApproachMain question
Prompt engineeringHow should I ask for this result?
Context engineeringWhat information should the agent receive?
Tool or harness engineeringWhat can the agent access and do during one run?
Loop engineeringHow should repeated agent work be triggered, checked, corrected, remembered, and stopped?

A prompt is one component inside a loop. Better prompts can improve an individual step, but they do not replace verification, state management, budgets, or stopping rules.

Common Failure Modes

Poorly designed loops can create more work instead of less.

The Agent Reviews Its Own Work Without Evidence

An agent that writes the output and then simply declares it correct is not a strong verification system. Whenever possible, use external checks such as tests, schemas, real API responses, or a separate reviewer.

No Maximum Number of Attempts

Some problems will not be solved by trying the same loop forever. Set retry limits and escalate when the loop is stuck.

Too Much Permission

A loop that can merge, deploy, delete data, and spend money has a much larger failure surface. Begin with reversible actions such as creating drafts, branches, reports, or pull requests.

Missing or Stale Context

The agent may repeatedly make incorrect decisions because it is reading old documentation or incomplete project instructions. Context quality matters as much as the model itself.

No Cost Limit

Repeated model calls, tool calls, test runs, and review agents can consume a surprising amount of time and money. A useful loop should have a token, cost, or execution budget.

How to Build Your First Loop

Start with a narrow, repetitive, low-risk task.

A good first loop might:

  • summarize new issues every morning;
  • identify duplicate support tickets;
  • draft release notes from merged pull requests;
  • diagnose a failed test and prepare a report;
  • create a draft blog post from approved source material;
  • update dependencies and open a pull request without merging it.

Before running it, answer these questions:

  1. What starts the loop?
  2. What exact goal must it achieve?
  3. What information and tools can it use?
  4. How will the result be verified?
  5. What information should be saved?
  6. When must it stop?
  7. Which action requires human approval?
  8. How can a bad result be reversed?

If those answers are clear, the workflow is probably ready for a small experiment.

The Real Shift

The biggest change is not that AI can perform more tasks without a person clicking every button.

The real shift is that the human moves from operating the agent step by step to designing the system that operates the agent.

Instead of repeatedly saying:

Try this. Now check that. Fix the error. Run it again.

You define the cycle once:

Goal → Act → Observe → Verify → Learn → Repeat or Stop

That is the core idea of loop engineering: not removing human responsibility, but turning repeated prompting into a controlled, testable, and reusable process.

Further Reading

Written and reviewed by /lico

Just writing down my thoughts, interests, and the things I learn along the way.