Reference · 24 Patterns · 6 Chapters
Agent Patterns
Repeatable techniques for engineering with AI coding agents. A structured reference — not tips, not tricks, not a beginner's guide.
Difficulty levels
No prior agent experience needed. Start here.
Assumes you've used coding agents on real projects.
Requires deep agent workflows and multi-session experience.
Foundation
Setting up your environment, codebase, and tools for agent success.
4 patterns
Convention File
Make implicit project rules explicit in a file the agent always reads, so it follows your standards without being told each time.
Safety Net
Establish automated checks (tests, types, linting) as guardrails so agent mistakes get caught immediately, not in production.
Memory Layer
Use persistent context files to maintain project knowledge across sessions, eliminating repetitive re-explanation.
Agent-Friendly Architecture
Organize code with clear boundaries, named modules, and explicit interfaces so agents can navigate and modify it confidently.
Context
Managing what the agent knows — and doesn't know.
4 patterns
Context Priming
Front-load the most relevant files and decisions before making a request, so the agent starts from understanding rather than guessing.
Scope Fence
Explicitly constrain the agent's working area to prevent drift into unrelated code, keeping changes focused and reviewable.
Progressive Disclosure
Reveal project complexity incrementally instead of dumping everything at once, avoiding context overload.
Anchor Point
Reference specific files, functions, and line numbers to ground the agent in concrete code rather than abstract descriptions.
Task
Breaking work into units that agents handle well.
4 patterns
Vertical Slice
Break features into thin end-to-end slices rather than horizontal layers, giving the agent complete context for each piece.
Checkpoint Loop
Work in small cycles of do-then-verify instead of one big request, catching drift early before it compounds.
Scaffold First
Have the agent build types, interfaces, and structure before filling in implementation, establishing constraints that guide the rest.
Parallel Fan-Out
Split independent subtasks across concurrent agent sessions to multiply throughput without multiplying errors.
Steering
Guiding agent behavior toward the output you actually want.
4 patterns
Test-First Steering
Write failing tests first so the agent has a concrete, verifiable target instead of an ambiguous description.
Example-Driven Spec
Show the desired output shape rather than describing it abstractly, reducing interpretation error.
Negative Space
Define what the agent should NOT do, because constraints eliminate more bad output than instructions produce good output.
Constraint Over Instruction
Specify boundaries and invariants rather than step-by-step procedures, giving the agent room to find good solutions within your guardrails.
Verification
Ensuring the agent's output is correct, complete, and safe.
4 patterns
Incremental Verification
Verify each unit of work as it is produced, not the whole batch at the end, so errors surface while they are cheap to fix and trivially attributable.
Adversarial Review
Have a separate agent or a fresh context attack the work, because the agent that produced it shares the blind spots that produced the bug.
Regression Guard
Pin the existing behavior with characterization tests before the agent touches the code, so "it still works" is a check the machine runs, not a hope you hold.
Diff Review
Read every changed line before accepting. The agent's summary is its intent; the diff is what it actually did — and they are not the same artifact.
Recovery
What to do when things go wrong.
4 patterns
Clean Slate
When the context is poisoned and the agent is looping, discard the conversation and restart from a tight written brief instead of arguing the agent out of its own history.
Rollback Point
Commit known-good states before risky agent work so reverting is one command, not an archaeology dig through entangled changes.
Reproduction First
When fixes keep missing, stop requesting fixes and require a deterministic reproduction first — an agent patching a bug it cannot reproduce is guessing.
Postmortem Note
After a recovery, encode the root cause into the persistent layer — a convention, a memory, a test — so the same failure cannot recur instead of recurring every session.
Find by Problem
Start from the symptom you're experiencing.
“The agent keeps making changes I didn't ask for”
“I keep re-explaining the same things”
“Output is correct but doesn't match codebase style”
“Huge diff and I'm not sure it's right”
“The conversation got confused and is going in circles”
“Not getting enough value from agents on complex tasks”
“The agent broke something unrelated”
“Spending more time fixing agent output than writing it myself”