Self-Improving AI Coding Agents Through Accumulated Behavioral Rules: A Closed-Loop Framework
TL;DR Highlight
Turning accepted review comments into AGENTS.md rules gave zero recurrence across 9 tracked error classes
Who Should Read
Backend developers whose AI coding agent repeats the same mistakes every session, inflating PR review effort
Core Mechanics
- One accepted review comment, one rule
- Only comments that point to a recurring class of mistake, not a one-off, become rules in the instruction file.
- No model weights change; it is just a version-controlled Markdown file.
- Self-review checklist before submission
- The agent runs a checklist before presenting code.
- Each rule maps to a checklist item.
- More specific rules worked better
- Early rules were broad and later ones were precise.
- Specific, actionable rules were followed more reliably than general guidance.
- Rules can conflict
- 'All IDisposable must use using' clashed with 'never dispose a factory HttpClient'.
- Adding a scope qualifier to the first rule fixed it.
- Same file, transfer across tools
- An IDE agent and a terminal agent read the same instruction file.
Evidence
- Zero recurrences
- Across 9 error classes and 74 post-rule session exposures, nothing recurred.
- This is an observation without a control group.
- Review comment shift
- In 36 PRs across 6 repos, architecture, API design and performance made up 66% of comments.
- Mechanical correctness and style made up 14%.
- Rule set growth
- Over four weeks behavioral rules grew from 5 to 18, with 15+ code standards and a 15-item checklist.
- The file was about 4,809 words (~6,250 tokens), under 5% of a 128K context window.
- Rising specificity
- The specific-rule ratio rose from 0.60 in week 1 to 0.78 in weeks 3-4.
- 9 of 15 knowledge transfers (60%) crossed repo or tool boundaries.
How to Apply
- Put 3 mistake rules in AGENTS.md today
- Pick the 3 mistakes your agent repeated in recent PRs and write each as one line of must/never plus a reason.
- Place the file at the repo root so the agent loads it as system context.
- Add a rule-promotion item to the PR template
- If an accepted comment could recur elsewhere, require adding a rule in the same PR.
- Otherwise require a follow-up issue.
- Link a self-review checklist to the rules
- Add a numbered checklist to the instruction file and tell the agent to run it before submitting code.
- Note the checklist item number on each rule.
- Add a validation script for the file in CI
- Check required sections and the rule format (ID, scope, rationale) in pre-commit or CI.
- Send instruction-file changes through PR review like code.
Try It
# Paste into Claude, ChatGPT or Claude Code (simplified version of the paper's method)
Below are accepted code review comments from our team.
{{review comments}}
For each comment:
1. Decide whether it is a one-off typo or a class of mistake that could recur in other contexts.
2. If it can recur, write a rule for AGENTS.md in this format:
- Rule ID / Category / Scope / Constraint (one specific must/never line) / Rationale / Checklist Map
3. If it conflicts with or overlaps the existing rules {{existing AGENTS.md}}, say how to fix it.
4. Finally, write one self-review checklist line per rule, to run before submitting code.
Next step: load the resulting AGENTS.md in your next working session and check whether the same mistakes still recur.Terminology
Related Papers
Same Simulation, Different Evidence: Where Retrieved Tool Output Costs LLM Agents Accuracy
Saving long tool output to files cut GPT-5.1 accuracy by 11.3 points; naming the authoritative file restored it.
Fake News, Real Crashes: Information Injection Attacks on LLM Financial Trading Agents
Fake headlines hijacked LLM trading agents 62% of the time versus 14% for prompt injection.
Harness Engineering 101: The LLM is the brain, the harness is the body
An agent is a loop managing a JSON array; 16 chapters build one from scratch
Harness2 by Google Research – Recursive Agent Harnessing
Recursively refining the harness with fixed model weights raised benchmark scores by up to 11.8 points.
Ousted Savannah police officer gave ICE agent husband access to Flock system
A police officer shared her Flock login with her ICE-agent husband; an audit found 983 searches and she was fired
Tmux and Claude Code: Sessions, Send-Keys, and the Ceiling
Running Claude Code agents in tmux works well, but limits appear around four agents.
Original Abstract (Expand)
LLM-based coding agents repeat the same classes of mistakes across sessions because they lack a mechanism to retain corrections from human review feedback. We present a closed-loop framework in which every accepted review comment is codified as a persistent behavioral rule, progressively expanding the set of error classes the agent can self-detect. The framework combines an accumulating rule set in a version-controlled instruction file, a self-review checklist executed before code submission, and automated validation that ensures rule set integrity as it grows. In deployment across a 35+ service microservices platform, the rule set grew from 5 to 18 behavioral rules, 15+ language-specific standards, and a 15-item self-review checklist, all derived from real review feedback. We present empirical results from 11 recorded working sessions spanning code generation, PR review, incident investigation, and cross service refactoring. We observe that accumulated rules shift review effort from low-level correctness toward design-level validation, achieve a measured 0% recurrence rate for ruled-against error classes, and transfer across heterogeneous agent interfaces. We compare our approach against related work in experiential LLM learning (Reflexion, ExpeL, Voyager) and automated code review (CodeReviewer, SWE-bench agents), showing that our framework achieves persistent cross-session learning without weight updates, operates on production codebases rather than synthetic benchmarks, and addresses an orthogonal dimension (behavioral consistency over time) that existing benchmarks do not measure. The result is a coding agent that improves with every review cycle, accumulating the engineering wisdom of its human collaborators without changing a single model weight.