The Research Report
Write the Loop Before the Prompt: Agentic Design Patterns Are Becoming Test-Built Programs in 2026
Prompting is the easy half of agent building. The hard half is making the loop around the model trustworthy - and in 2026 that trust is less a matter of prompt craft and more a matter of enforcement: typed contracts at the tool boundary, caps written in code, and tests that decide when a change ships. Two bodies of work converged this year to make that concrete. The agentic design patterns catalog has settled into a stable shared vocabulary. And a maturing practice of test-driven development for agents - evals as the spec, failing tests as deploy gates - gives the vocabulary teeth. This piece puts the two together: what each pattern actually looks like as a runnable, testable program, and what the TDD-for-agents workflow adds on top.
The vocabulary settled: four canonical patterns, then production additions
The four canonical agentic patterns - Reflection, Tool Use, Planning, and Multi-Agent Collaboration - were popularized in Andrew Ng's 2025 agentic-AI course with Antonio Gulli. Gulli's "Agentic Design Patterns: A Hands-On Guide to Building Intelligent Systems" (updated with Mauro Sauco) extends them into a 21-chapter catalog in four parts: seven core patterns (prompt chaining, routing, parallelization, reflection, tool use, planning, multi-agent), advanced patterns including memory management and Model Context Protocol, production patterns (exception handling, human-in-the-loop, RAG), and enterprise patterns from A2A inter-agent communication through evaluation and monitoring. A 2026 practitioner taxonomy (SitePoint, via GladLabs) adds two production shapes - orchestrator-worker, and evaluator-optimizer, which is effectively "test-driven agent development."
Two realities cut through any taxonomy of five or six names. First, ReAct - the think-act-observe loop - is the operational backbone under most of it, not a competing sixth pattern; Addy Osmani calls it "the most fundamental agentic design pattern. If you only learn one pattern, make it this one." Second, production systems stack two patterns, rarely all of them. Reflection without planning gives you an agent that critiques itself fluently but never decomposes a task; tool use without the evaluator shape gives you an agent that touches the real world with no rail stopping it from touching the wrong thing - GladLabs' summary of what actually breaks when teams skip them.
Each pattern is a testable contract, not a prompt
The most useful shift in 2026 writing on these patterns is that each one is described less as prompting advice and more as a loop with bounds you can assert on. That makes each pattern a natural command-line program with tests.
Reflection - generate, critique against an explicit rubric, refine, then stop. The cap is the contract: ergini's defaults are three rounds maximum, and the per-run economics are $0.005-0.02 and 3-6 seconds. The critique step is load-bearing: without a sharp rubric you are running three identical samples and praying. Two guardrails recur everywhere. Scaler's warning: a model grading its own work is overconfident, so prefer external verdicts - unit tests, linters, schema validators - over self-opinion. GladLabs runs two distinct passes rather than one blurred one: first "does this match the spec, line by line," then "is the code any good" - because a single pass tends to average correctness and quality and miss both. As a CLI: a --max-retries flag defaulting to 2, and an exit code that distinguishes converged from capped.
Tool Use - a registry plus schemas written like product specs: clear name, clear description, strict schema, predictable errors. The two rules that survive 2 a.m. incidents, per GladLabs: own your interface, rent your implementation; stay CLI-first with MCP as the parity layer for anything that must talk to the wider tool ecosystem. Osmani's scaling guideline: three to five well-designed tools outperform fifty poorly-designed ones. The testable part needs no model at all: schema round-trip tests, error-mapping tests, and trace assertions that verify which tool was called with which arguments.
ReAct - think, act, observe, repeat until done or capped. The cap is enforced in code, not suggested in a prompt: ergini's default is 5-10 steps for most loops. The trajectory log is the other contract piece - every step's model input, tool name, arguments, result, and latency get written down, because that log is what makes a bad answer debuggable when a user reports it.
Planning - plan-then-execute versus interleaved replanning. A single planning call up front lets you reject a bad plan before paying for execution, and the plan earns its keep as a reviewable artifact: ergini's Caldra example lets the operator read and edit the plan (channels, message order, contingency branch) before execution starts - that human gate is what makes planner-executor defensible for side-effectful work. The model asymmetry is deliberate: a stronger model for the one high-leverage plan, a cheaper model per mechanical executor step. Expected cost lands at $0.02-0.08 and 5-15 seconds with the plan in hand; replan only on failure, not continuously.
Multi-Agent - a manager decomposing and dispatching to scoped workers, each in its own context with its own tools (and its own git worktree if they touch code). This pattern earns its complexity only when a single agent visibly runs out of context room or tool surface; debuggability is the worst of any shape, and the price is real - $0.20 to $5+ per task and p95 latency measured in minutes. The testable part is isolation: workers that cannot see each other's files cannot corrupt each other's state, which is exactly what a test can guarantee.
TDD for agents: red, green, full suite
Closest to a canonical workflow is Arize's six-step loop, straight from their production practice: identify a failing trace (a user report or an observed anomaly), add it to the test dataset with the expected behavior spelled out, run the test (it should fail - if it passes, the expectation is not specific enough), fix the system prompt, tool descriptions, or agent logic, rerun until green, then run the whole eval suite to be sure the fix broke nothing else. Their cautionary tale is worth keeping: an upgrade from GPT-3.5 to GPT-4 changed tool-call behavior and output formats in ways nobody noticed for days - customers found the regressions first. Now every model swap runs the full suite before it ships.
The test matrix answers "which assertion for which output": deterministic checks - JSON schema, regex, trace analysis of tool-call sequences - for structured facts and API-shaped outputs; LLM-as-judge with a written rubric for behavioral guidelines and tone; metric thresholds for latency and cost. Not every test needs a judge, and the deterministic ones run locally in seconds.
Google's harness-engineering writeup sharpens the assertion style: assert behavior, not prose. A weather agent that answers from memory fails its test because the search tool call never happened - the pytest assertion reads "Agent answered from memory without consulting live search." Because single runs are noisy from model nondeterminism, they batch behavioral evals and read aggregate pass-rate trends instead of blocking a PR on one nondeterministic sample.
The research frontier is formally TDD. TDAD - "Test-Driven AI Agent Definition" (arXiv, March 2026) - treats the system prompt as a compiled artifact: engineers write behavioral specifications, a coding agent converts them into executable tests, and a second coding agent iteratively refines the prompt until tests pass. The anti-gaming machinery is the interesting part: visible/hidden test splits withhold the evaluation tests from the compiling agent, and semantic mutation testing injects plausible faulty prompt variants to prove the suite actually catches regressions. Across four deeply specified agents and 24 trials: 92% initial compile success, 97% mean hidden-set pass rate, 86-100% mutation detection, and 97% regression safety when specs evolve.
Fresh evidence that the tests remain the hard part: Req2Test-Bench (arXiv, October 2026) asked agents to generate behavior tests from natural-language requirements across 5,086 real BDD artifacts in eight open-source projects. The best configuration produced passing tests for 82.8% of instances - but only 33.8% were behaviorally adequate, meaning they killed every mutant the developer's own test killed. A red test that does not test the behavior is worth nothing.
Eval-driven development: the suite is the spec
Braintrust generalizes the practice beyond red-green: evaluation sits at the beginning of the cycle as the working specification, not at the end as a report card. Four properties make it hold up: evals as specs (requirement changes flow into eval criteria first), dataset and run lineage (dataset version, prompt version, model configuration, and judge settings pinned, so any prior result is reproducible months later), judge calibration (LLM-as-judge scores drift over time unless recalibrated against human ratings - otherwise scores quietly stop meaning anything), and regression thresholds enforced as release gates in CI. Every prompt tweak, model swap, and pipeline change becomes a measurable experiment: score went up, or score went down.
A build order for a five-program set
For anyone turning this into code, the pattern-to-program shape is uniform:
- Pick the pattern and define the CLI contract: arguments, exit codes, output files (a reflection run's converged/capped status, the plan JSON for planner-executor, the trajectory log for ReAct).
- Write failing pytest tests against that contract using a fake model that returns canned traces. The loop logic - retry caps, tool registry dispatch, plan checkpointing, worker isolation - is ordinary Python and needs no API calls to test.
- Implement the loop until the fake-model tests pass.
- Add exactly one live integration test per program against a real model, asserting trace shape rather than prose: a tool call happened, a plan file exists, the retry cap held.
- Add the production scaffolding ergini lists as the common five: a hard step cap in code, a per-request cost ceiling computed at request time, a per-tenant daily dollar cap, full trajectory logging, and human-in-the-loop gates on every side-effectful tool.
The payoff, especially for a one-person practice, is credibility. When a client asks "how do you know the agent works?", the honest answer is not a chat transcript - it is a pytest suite, a run history, and a pass-rate trend. The same discipline applies when the client is your own automation: pattern loops with caps, traces, and evals are what let an unattended process run at 3 a.m. and be trusted in the morning.
Sources
- https://www.arize.com/blog/why-testing-ai-agents-is-non-negotiable
- https://developers.googleblog.com/the-anatomy-of-harness-engineering-how-to-evaluate-iterate-and-guard-ai-coding-agents
- https://arxiv.org/abs/2603.08806
- https://braintrust.dev/articles/eval-driven-development
- https://addyosmani.com/agents/04-agentic-design-patterns
- https://ergini.com/blog/ai-agent-design-patterns
- https://gladlabs.io/posts/the-prompt-engineering-era-is-over-637977a8
- https://scaler.com/topics/agentic-ai-design-pattern
- https://github.com/Mathews-Tom/Agentic-Design-Patterns
- https://arxiv.org/abs/2610.36584