Loop Engineering: Give Your AL Copilot a Repeat Button

Note: This blog is a personal notebook. I write it to record what I work on, for my own reference, not to publish it on social media or to promote myself. If a post is still useful to you, I am glad, but that is not why it exists.

This post was published on July 03, 2026. Software versions, product features, links, and tool availability may have changed since then. Always check official documentation for the latest information. Some screenshots show small details. Zoom in on the page to see them clearly.

The last post described the harness that lets a model act on your AL project. This post adds a repeat cycle on top: the model tries a step, checks the result, and tries again until it succeeds or runs out of attempts.

IBM explains the general idea. This post applies it to one AL task: a compile error.

Problem

A normal Copilot request runs once: you ask, the model answers, you act. A compile error breaks this: the model writes a fix, the fix fails, you paste the error back, and the model tries again. It is slow, and it repeats three actions: run, read, retry.

Why this matters

Loop engineering removes the copy-paste step: the model runs the check, reads the result, and decides whether to try again.

The cost: a loop with no stopping point can make many small, unwatched changes, and some can be wrong. So this is a design task, not a setting you switch on.

Architecture

Loop engineering has one shape: plan, act, check, decide. Your client (the GitHub Copilot CLI, Claude Code, or VS Code agent mode) runs the cycle. You set two things first:

  • The exit condition. What counts as done? “Compiles with zero errors” is clear. “Looks better” is not.
  • The limit. How many attempts before the loop stops on its own? A fixed number, such as three, prevents an endless run.

In Business Central, the loop checks two facts that do not lie: compiler output and test codeunit results. Both only read your project, so the check is safe to run many times.

Think of cruise control: you set the speed once, and the car corrects itself. You still choose the speed and stay in control.

1
Plan
The model picks one small step toward the goal, such as one code fix.
2
Act
The client applies the step: it edits a file, or runs a command.
3
Check
The client runs the compiler or the test codeunit, and reads the result.
4
Decide
Done, or plan the next small step and repeat steps 1 to 3.
✓
Your review: read the diff and confirm the result before you commit.

Steps 1 to 4 repeat on their own, inside your limit. Step 5 is yours: no change reaches your project’s history without your review.

Demo steps

  1. Open an AL project in VS Code with GitHub Copilot, and pick a codeunit with a known compile error.
  2. Ask Copilot agent mode: “Fix the compile error, then build again. Repeat until zero errors, or three tries.”
  3. Watch the agent build, read the error, fix it, and build again.
  4. Confirm that the build is clean, and read the diff before you commit.

The exit condition is “zero build errors,” and the limit is “three tries.”

What is intentionally simple

  • One compile error and one check: the compiler. No test codeunit run.
  • A fixed attempt limit, set before the loop starts.
  • No automatic commit and no CI pipeline, such as AL-Go for GitHub.

Risks/limits

  • A weak exit condition, such as “looks correct,” lets the loop report success on a bad result.
  • Without an attempt limit, the loop can make many small edits before you notice.
  • Each attempt is a new model call, with more time and cost.
  • The loop does not replace code review, only the copy-paste between attempts.

Next iteration

  • Add the test codeunit result as a second check.
  • Save a record of every attempt for the reviewer: the error, the fix, and the build result.
  • Add a stricter exit condition from your rules file, such as a required naming pattern.

Try it yourself

mb-copilot-al-loop-demo is a free VS Code add-on that runs this loop on a real AL project.

Open a project with a build error and type /fix-build-loop in Copilot Chat. Copilot builds, finds the error, and fixes it, up to three times.

The limit is real: a small script counts each try and stops Copilot after three. It is code, not a request to a model, so it always holds. The add-on never saves a change on its own.

See the project page for install steps.

Closing note

Loop engineering does not make Copilot smarter. It gives Copilot a clear stopping point and a way to check its own work. The exit condition and the limit stay your choice.

Update (August 25, 2026)

Anthropic published a blog post on loop engineering, worth a read if you use Claude Code for AL work. It names four loop types:

  • Turn-based. You prompt, Claude acts, you review.
  • Goal-based. Claude works until it meets a condition you set, such as “zero build errors.” This is the pattern in this post.
  • Time-based. Claude runs on a schedule.
  • Proactive. An event triggers Claude, not a schedule or a prompt.
← Back to AI