Skip to content

Lesson 5: Close the Loops

Tactical Agentic Coding

The one tactic: Always add feedback loops — teach your agents to test, validate, and self-correct so they close the loop on their own work.

Overview

The most valuable thing an engineer creates is not code, architecture, or features — it is the experience delivered to users. That means the highest-value work is proving the code actually does what it was designed to do. We test, we validate, we close the loop.

Agentic coding lets your agents test on your behalf at a scale you could never reach by hand. The whole lesson turns on one question: given a unit of production-ready work, how would you, the engineer, test and validate it? Answer that for every class of work in your codebase, encode the answers into commands and tool calls, and your agents will fly while other engineers run.

A closed loop is an agent operating on work, calling a command or tool to get feedback on success, then continuing to build until the feedback is positive. When you do this you let the code write itself. Every passing test frees your context window, ends the second-guessing, and lets you focus on what is next for your users.

The debate about testing is over: engineers who test with their agents win, full stop. The value of a test is multiplied by the number of agent executions that hit it. Testing is one of the highest agent-leverage points you have.

Key concepts

Closed-loop prompt anatomy: Request → Validate → Resolve

Every closed-loop prompt has three parts. This is what separates it from an ordinary prompt — it instructs the agent to validate itself and creates a small loop.

  • Request — the change, spec, task, or feature you want built (often large).
  • Validate — the concrete validators to run: linter, unit tests, compile, e2e.
  • Resolve — direction on what to do when a validator fails: fix it, then rerun every validation step from the top.

Run validators in order, top to bottom. If any step surfaces an issue, stop, resolve it immediately, then rerun the full set — resolving one issue must not silently break another.

Stacking feedback loops

Start tiny and stack confidence layer by layer. A worked progression:

  1. One linter (ruff) catching an unused import.
  2. Add backend unit tests (pytest) plus a Python compile step.
  3. Add frontend checks (TypeScript compile, Vite/Jest, production build).
  4. Add end-to-end browser tests.

Each added validator raises the confidence that the agent shipped complete work with no regression.

Tests as the rule of law

You must make a rule inside your codebase architecture: what matters more, the code or the tests? The answer must be the tests. Your tests are the rule of law. If a test is wrong, have your agent fix the test so your testing commands keep their weight — never weaken the test to make the code pass.

Playwright MCP end-to-end validation

Browser control is another tool for validation. Using the Playwright MCP server, the agent opens the browser, types a query, takes a screenshot, reads the before/after images, and verifies a precise result (for example, "confirm seven results are returned"). Point the URL at local, staging, or a production test account depending on how much confidence you need. Vision-mode reading of the screenshots gives the agent real proof, not just a pass/fail flag.

Templating testing into the Agentic layer

Bake validation into reusable prompts so it happens by default. The plan template includes a Validation commands section, so every generated feature, bug, or chore plan ships with baked-in validation. Conditional lines like "if this bug affects UI or user interactions, add an end-to-end test" let the agent decide when to escalate to Playwright.

How to apply it

  1. For each class of work, list every step you take by hand to confirm a ship: lint, unit tests, UI tests, integration/CI, build/compile, log checks, evals, LLM-as-judge, manual click-through.
  2. Encode each of those steps as a command or tool call the agent can run.
  3. Write closed-loop prompts using Request → Validate → Resolve. Keep validators explicit and ordered.
  4. Instruct the agent to run validators top to bottom, resolve failures immediately, then rerun all of them.
  5. Add Playwright MCP e2e validation for anything touching UI: navigate, act, screenshot before/after, read images, verify a precise expected result.
  6. Template the validation into your reusable prompts (slash bug, slash feature) so every plan carries validation commands by default.
  7. Move the whole pipeline off your device into an ADW so it runs plan → build → test out of the loop, triggered by a GitHub issue.
  8. Route failed tests to isolated resolver agents (one failed test, one fresh agent) via a standardized JSON report.

Commands & conventions

Command / toolPurpose
slash installReusable setup: reset DB, copy env files, boot server
slash bugMeta prompt that generates a bug-fix plan with validation commands
slash featureMeta prompt that generates a feature plan with validation commands
slash implement <plan>Higher-order prompt: read plan, think hard, implement
slash testRun frontend + backend tests, return standardized JSON
slash test-end-to-end <file>Higher-order prompt running a Playwright e2e test file
ruff / uv run pytestLint and unit-test the Python backend
tsc --noEmit / bun run buildTypecheck and build the frontend

Directory conventions for the Agentic layer:

text
.claude/commands/   # reusable slash-command prompts (bug, feature, test, implement)
adws/               # AI developer workflows (plan, build, test, and compositions)
specs/              # generated plans, keyed by issue + ADW ID
agents/<adw-id>/    # per-agent logs, state, raw output for tracing
app/client/e2e/     # end-to-end test files + before/after screenshots

A closed-loop prompt sketch:

text
Request:  Update @app/sql_processor.py — remove the insights endpoint
          and move load_dotenv() above its first import.
Validate: run ruff, run `uv run pytest`, run python compile.
Resolve:  run in order top to bottom. If any step has issues, stop,
          resolve immediately, then rerun every validation step.

Key takeaways

  • Answer one question for every class of work: how would you test and validate it? Then encode the answer.
  • A closed loop = execute → validate via command/tool → resolve → repeat until feedback is positive.
  • Every closed-loop prompt is Request → Validate → Resolve.
  • Stack validators (lint → unit → compile → frontend → e2e); each layer adds confidence.
  • Tests are the rule of law — fix the test, never weaken it.
  • Playwright MCP lets agents drive the browser and verify precise results with screenshot proof.
  • Template validation into reusable prompts so every plan ships with validation commands by default.
  • Push the pipeline off-device into an ADW, and route failed tests to isolated one-purpose resolver agents.

Notable quotes

"Always add feedback loops. Your work, my work, any engineer's work is useless unless it's tested."

"Your tests should be the rule of law in your codebase."

"The value of tests are multiplied by the number of agent executions that occur in your codebase."

"We're building the system that builds the system."