All posts

· 2 min read

Building Agentic Loops That Write, Verify and Ship Code

How I design multi-agent workflows with Claude and GPT that plan, build, review and test code, and why verification matters more than generation.

By Sai Ram Sana

Most teams start with AI by pasting code into a chat window. That's useful, but it isn't agentic. An agentic system owns a goal from start to finish: it plans, acts through tools, checks its own work and decides what happens next.

Here's a five-step loop that holds up well beyond the demo stage.

1. Plan: decompose before you generate

A planner agent gets the goal plus context (relevant files, conventions, the ticket) and returns a short, ordered task list. Keeping the plan explicit makes every later step auditable.

2. Act: give the agent real tools

The builder agent doesn't just "write code". It reads files, runs commands, calls APIs and edits the repo through well-defined tools. Tool design is prompt design: narrow, well-named tools produce far more reliable behaviour than one giant "do anything" tool.

3. Verify: never trust a single model

This is where most setups fall short. A good verification stage stacks independent checks:

  • Deterministic gates: tests, type-checks and linters must pass.
  • Cross-model review: a reviewer on a different model (for example GPT reviewing Claude's output) often catches mistakes the original model glosses over in its own work. Treat its comments as signals to check, not verdicts.
  • Schema and policy checks: structured outputs are validated before anything touches production data.

4. Decide: confidence-based routing

Not every change needs a human, and not every change should skip one. The loop scores confidence and routes accordingly: auto-ship, retry with feedback, or escalate to a human with a concise summary.

One caveat matters a lot: don't trust a model's self-reported confidence. LLMs are poorly calibrated about their own correctness. Derive confidence from signals you can measure instead: tests and type-checks passed, the reviewer agreed, outputs validated against their schema, and the change is small and touches low-risk files. Start with everything escalating to a human, and loosen the rules only once your logs show they're safe.

5. Learn: close the loop

Every run is logged. Failures become evaluation cases, so the same mistake is caught automatically next time.

The pattern works beyond code

The same Plan → Act → Verify → Decide loop applies to almost any agent workflow. Take a support-ticket triage agent. It plans which knowledge to consult, acts by drafting a reply, verifies the draft against policy and the cited docs, then decides whether to send it automatically or queue it for a human.

Agentic AI isn't about the smartest model. It's about the most reliable system around the model.

Building something agentic?

I share build notes and connect with builders on LinkedIn.

Connect