AI engineering, for a software engineer, is the work of making a coding agent’s output safe to merge. You write the rules it follows, the checks it can’t skip and the access it gets.
The best setup has a second agent check the first, behind a test gate enforced by code. Below are four rungs to get there. Each shows what it buys and what it costs. Stop at the one that fits your team.
Table of Contents
- Why agent code needs checks
- Good: rules file and diff review
- Better: a test gate
- Even better: scoped access
- Best: a second agent checks
- Which rung fits
- What to do this week
- FAQ
- Sources
- Also from Insurgency Labs
Why agent code needs checks you don’t run by hand
Agents write code that is almost right. In the 2025 Stack Overflow Developer Survey, 66% of developers named “almost right” AI output as their top frustration. 45% said debugging AI-generated code takes more time. Only 33% trust the accuracy of AI output.
The fix is to move checks out of your head and into things that run every time. Each rung below moves one more check.
Good: one agent, a rules file, and you read the diff
Start with one agent in your repository and a rules file it reads on every run. Claude Code reads CLAUDE.md. Codex, Cursor and Copilot read AGENTS.md. Put in it what a model can’t guess:
# AGENTS.md
- Run tests with: go test -race ./...
- Wrap errors with fmt.Errorf("doing x: %w", err). Never return nil on error.
- Don't add a dependency without asking.
- Don't touch migrations/.
Then read every diff before its description. A description written by the model that wrote the bug won’t mention the bug. Look for tests that assert nothing, invented flags and files the ticket never named. The full list is in the AI pull request review checklist.
It’s fast on small, well-understood tasks. You are the only check, though, and your attention runs out first.
Better: a test gate enforced by code
A rule in a prompt can be skipped. A gate in code fails the work, the same way CI fails a person’s PR. Make untested new code a failure.
Here is the gate from loops, run on a new function with no tests:
$ loops gate --base main
✓ build 0.0s
✓ gofmt 0.0s
✓ vet 0.1s
✓ arch 0.0s
✓ test 0.3s
✗ coverage 0.0s
file stmts covered % uncovered lines
internal/domain/order/order.go 6 0 0.0 17-24
internal/domain/order/order.go:17: new code in order.go is untested (0/6 statements)
new code coverage 0.0% < 70%
$ echo $?
1
It measures only new code against the base branch and names the uncovered lines. With two tests added, the same command exits 0.
You don’t need loops for this. A CI job does the same: tests under the race detector, with a coverage floor on changed code. Claude Code hooks can also deny a command before it runs, such as a test run without -race.
Untested code stops reaching your review queue. The loop gets slower, and coverage can’t tell a useful test from an empty one, so you still open the tests.
Even better: give agents only the access they need
Agents send and run more than you type. Claude Code put signed-in users’ email in the User-Agent header of web requests. One user found 53 tool calls carrying it. Decide what an agent can see and change before it runs.
Databases are where this matters most. Anthropic’s original Postgres MCP server ran queries in a READ ONLY transaction. Datadog showed that COMMIT; DROP SCHEMA public CASCADE; ends that transaction and runs the drop. The server is now archived, with “NO SECURITY GUARANTEES”.
The safer pattern keeps credentials on a server and exposes read-only tools. pREST’s MCP server, which I maintain, gives agents SELECT tools only. Each call returns at most 100 rows, behind the REST API’s auth and table ACL. Six Postgres MCP servers compared ranks the alternatives on the same test.
A wrong or tricked agent can’t drop your data. Setup takes time, and agents will sometimes ask for access you didn’t grant.
Best: a second agent checks the first
The agent that wrote the code is the worst one to verify it. Split the roles so no agent checks its own work:
| Phase | Who | What it leaves |
|---|---|---|
| Research | researchers, in parallel | briefs with sources |
| Plan | a planner, then a plan reviewer | an approved plan |
| Build | an architect, then engineers in parallel | code, tests and claims |
| Verify | one QA agent per engineer, then the gate | each claim verified or sent back |
| Prove | a product reviewer | a proof per acceptance criterion, then the PR |
That’s how loops works, a free plugin I built. It runs in Claude Code, Copilot, Codex, Cursor, Gemini CLI and five more agents, across 15 backend languages:
npx ai-loops # Claude Code
npx ai-loops --target cursor # or copilot, codex, gemini, opencode, amp, windsurf, cline, antigravity
Superpowers, GSD Core and BMAD-METHOD take related approaches; the loops comparison cites each one’s docs.
You get a PR where each requirement links to its proof. It spends more tokens than one agent and proves backend behavior only; it doesn’t drive a browser. For a one-line fix, a single agent is cheaper.
Which rung fits your team
| Your situation | Start with |
|---|---|
| Solo, small tasks, you read every line | Good |
| Agents open PRs that other people review | Better: add the gate |
| Agents can reach production data or secrets | Even better: scope access first |
| Several agent PRs a day, and review is the bottleneck | Best |
| Spikes and one-line fixes | Good is enough |
The rungs stack. Each one keeps the checks below it. To find where you are, answer three questions:
- Does an agent’s PR fail CI when its new code has no tests? If not, you’re on Good.
- Can an agent reach a database with a write credential? Fix that before anything else.
- Does anything other than the writing agent re-run its claims? If not, you’re below Best.
What to do this week
- Monday, 30 minutes: write
AGENTS.mdorCLAUDE.mdwith the test command, error style and files to leave alone. - Tuesday, 1 hour: add a CI coverage floor on changed code, with tests under the race detector.
- Wednesday, 30 minutes: list every credential your agents can read and remove the write access they don’t need.
- Thursday: review the next agent PR with the checklist, diff first.
- Friday, 1 hour: split one ticket between two agents. One writes; a fresh session reviews and runs the tests.
FAQ
What is AI engineering?
For a software engineer, it’s making a coding agent’s output safe to merge. That means the rules it follows, the gates it can’t skip and its access. The term also covers building products on top of LLMs. Both rest on checks that run every time.
Is AI engineering the same as prompt engineering?
No. A prompt is one input. AI engineering covers what surrounds it: rules files, test gates, tool access and review. A good prompt with no gate still ships almost-right code.
How do I get a coding agent to write tests?
Make the work fail without them. Put the test command in AGENTS.md or CLAUDE.md. Add a coverage floor on new code, in CI or a hook. Then check that each test fails when the code is wrong.
Should AI coding agents have database access?
Read-only, through a server that holds the credentials. Avoid putting a connection string in the agent’s client config. The Postgres MCP comparison ranks six servers on this.
Do multi-agent workflows cost more?
Yes. Several agents research, review and re-test, so a run spends more tokens than one agent. They pay off on tickets where review time is the bottleneck.
Can an AI agent review another agent’s code?
It catches a lot, so use it as a filter. Keep a human approval, because a reviewing model can share the writer’s blind spots. The review checklist covers what to check yourself.
Sources
- Stack Overflow 2025 Developer Survey: AI and the results post
- Datadog Security Labs: SQL injection in the PostgreSQL MCP server
- Archived MCP reference servers
- Claude Code issue: email in the User-Agent header
- loops on GitHub and its latest release
Related posts:
- loops: a Claude Code plugin that turns a ticket into a tested pull request
- Reviewing AI-generated pull requests: a Staff Engineer’s checklist
- Why reviewers stop reading AI-written PR descriptions
- Six Postgres MCP servers compared
- How to handle a flood of AI-found bugs
Also from Insurgency Labs
Want to see how agent PRs change your team’s delivery? DeliveryCompass shows PR cycle time and review patterns from GitHub, with read-only access.