Back to Hub
Certification Study Notes

Agentic Design Patterns (ADP)

Vendor-neutral architectural guide for designing reliable AI systems: Sequential Decision Framework, Tripartite Execution Regimes (Deterministic Code vs. Probabilistic LLM vs. HITL), Architectural Evaluation Criteria, the 5 canonical workflow patterns, autonomous reasoning loops (ReAct, Plan-and-Execute, Reflection), 4-tier memory & context engineering, multi-agent topologies & typed HandoffContract schemas, and production failure modes.

Author: Michaël Bettan
Track: Google Cloud & Anthropic / Applied AI Architect
Test Yourself: Agentic Design Patterns Practice Quiz →
00

Overview & Mental Model

Definition

Agentic design patterns are reusable, framework-agnostic architectural blueprints that govern how an LLM-based system decomposes work, selects control flow, invokes tools, manages context memory, coordinates across specialized workers, and defers high-stakes decisions to deterministic code or human reviewers. They apply identically across Google ADK, the Claude Agent SDK, LangGraph, or direct model API loops.

What patterns solve for

A raw language model is a stateless, probabilistic token predictor—it can propose an action, but it cannot execute tools, enforce hard business invariants, persist session state, or halt a runaway loop. Architectural patterns define who owns the control flow (deterministic code vs. dynamic model reasoning), where authority sits (code gates vs. model judgment vs. human sign-off), and how context stays clean as tasks scale.

Rule 0 — The Simplicity Ladder

The model is the probabilistic reasoning engine; the architecture is the deterministic harness (nervous system, brakes, and safety interlocks). Start with the simplest architecture that passes your evaluation suite: climb from deterministic code → a single augmented LLM call → a predefined workflow → an autonomous agent only when empirical evaluations prove the simpler tier fails.

LayerControl OwnerRole & Runtime BehaviorMemory Hook
Raw LLMCaller (1 turn)Stateless token predictor; reasons over prompt context and emits text or structured tool requests, but never executes code."Brain in a jar"
Augmented LLMCaller (1 turn + tools)Single model call equipped with Retrieval (RAG), Tools (MCP/functions), and Memory (read/write state). Handles most production features."LLM with a backpack"
Composable WorkflowApplication codeMulti-step pipeline where LLMs and tools execute along predefined code paths with deterministic gates between steps."Railway tracks" — train cannot leave the rails
Autonomous AgentThe modelLLM dynamically directs its own multi-turn process, choosing which tools to call and when to stop based on environmental ground truth."Taxi" — driver picks the route dynamically
Agent Harness / FrameworkInfrastructureRuntime layer (ADK, Claude Agent SDK, LangGraph) supplying the event loop, state persistence, sandboxing, callbacks, and observability."Chassis, brakes & dashboard"

Classic architectural trap: Workflow vs. Autonomous Agent

Calling an LLM five times in a Python script does not make the system an "autonomous agent." If application code dictates the sequence, branching, and retry count, it is a workflow. It becomes an agent only when the model itself decides the next step and action trajectory at runtime.

01

1. Architectural Triage & Sequential Decision Framework

Before writing a single system prompt or selecting an agent framework, resolve four sequential architectural decisions. Skipping Decision 1 or 2 is the primary cause of over-engineered, brittle, or unsafe deployments.

01

Should an LLM be in the loop?

Decompose the business process across Tripartite Execution Regimes (Deterministic Code vs. Probabilistic LLM vs. Human-in-the-Loop).

02

What work shape fits?

Select Single Augmented Call, Composable Workflow, or Autonomous Agent using Architectural Evaluation Criteria.

03

Where & how is it routed/hosted?

Assign per-step model tiers and reasoning effort, transport mode (sync, stream, batch), and regional data boundaries.

04

What guardrails wrap it?

Enforce pre-LLM epistemic gates, tool-boundary callbacks, schema validators, cold-context critics, and HITL checkpoints.

Execution RegimeExecution EngineWhat Belongs HereCanonical ExamplesWhy Other Regimes Fail
Regime 1: Deterministic CodePlain application code, SQL, regex, type schemas, policy hooksExact arithmetic, schema validation, RBAC & permission enforcement, idempotency keys, database writes, PII redaction, hard policy gatesFee & tax math, date arithmetic, checking amount <= 500, enforcing user_id tenant scoping, verifying cited section headers exist in source textLLMs introduce deterministic invariant degradation (silent tail-risk math or rule violations); humans are too slow and inconsistent at scale
Regime 2: Probabilistic Model (LLM)Augmented LLM, Workflow node, or Agent loopUnstructured synthesis, semantic classification, ambiguous entity extraction, fuzzy matching, multi-step planning over open-ended inputsSummarizing conflicting legal clauses, triaging free-text support tickets, diagnosing novel stack traces across a codebase, drafting code diffsRigid code/regex shatters on phrasing variations; humans cannot manually read 50,000 documents per hour
Regime 3: Human-in-the-Loop (HITL)Human reviewer via durable approval queue / UI checkpointHigh-blast-radius irreversible actions, novel policy exceptions, regulated sign-offs, subjective value trade-offsApproving a $25,000 wire refund, executing a production database drop, granting an exception to legal policy, merging security-critical PRsCode lacks contextual judgment for novel exceptions; models cannot bear legal, financial, or ethical accountability

Hard Invariant Enforcement in Code (Preventing Deterministic Drift)

Deterministic drift occurs when a team delegates exact, rule-bound logic—such as calculating pro-rated subscription refunds, enforcing role-based access control (RBAC), checking date eligibility windows, or redacting Social Security Numbers—to a system prompt instead of application code.

  • Why it is dangerous: Even when a frontier model follows a prompt rule on most test cases, probabilistic token sampling guarantees a non-zero tail-risk failure rate—especially under instruction crowding (long prompts with 20+ competing rules) or adversarial prompt injection.
  • The "Deterministic Handcuffs" rule: Let the LLM extract structured parameters or propose an action, but execute all math, eligibility comparisons, permission checks, and compliance gates in plain code (PreToolUse / before_tool_callback hooks, Pydantic validators, or SQL constraints).

HITL Checkpoints vs. Programmatic Guardrails

  • Guardrail callbacks (Regime 1 — milliseconds): Deterministic pre/post hooks enforcing PII redaction, budget caps, allowlisted paths, and JSON schemas on every turn without human latency.
  • HITL approval (Regime 3 — seconds to hours): Planned pause before an irreversible or regulated action commits. Persist session state so the workflow can pause indefinitely and resume cleanly.
  • Concrete argument inspection: Reviewers must inspect and approve concrete tool arguments (issue_refund(order_id="ORD-891", amount_usd=490.00)), never vague model prose.
  • Avoid approval fatigue: Gate by risk tier (e.g., auto-approve refunds <= $50 in code; require HITL for > $50) so human reviewers do not rubber-stamp alerts.
02

2. The Work-Shape Spectrum & Architectural Evaluation Criteria

Once Regime 2 (the probabilistic slice) is isolated, evaluate architectural criteria to choose between a Single Augmented LLM Call, a Composable Workflow, and an Autonomous Agent.

Evaluation CriterionSingle Augmented LLM CallComposable Workflow (DAG / Chain)Autonomous Agent (Open Loop)
1. Task Path PredictabilityFully known (1 step): Input maps directly to output with retrieved context or a single tool lookup.Known decomposition (K steps): Multi-step process where the sequence, branches, or fan-out categories are fixed in advance.Unknown / emergent (N steps): Step N+1 depends entirely on what tool observation N revealed (e.g., debugging an unknown bug).
2. Latency BudgetSub-second to ~3 s: Single model roundtrip; ideal for synchronous inline UI responses.~3 s to ~15 s: Predictable bounded latency (K sequential stages or 1 parallel fan-out + join).Seconds to minutes+: Open-ended O(N) sequential turns; requires streaming progress UI or background execution.
3. Error Blast Radius & ReversibilityLow / read-only: Output is displayed to a user or validated by caller code before any state mutation.Medium / gated: Intermediate code gates catch bad outputs between stages before downstream side-effects run.High if ungated: Multi-turn tool mutations can compound; requires sandboxing, file checkpoints, and HITL gates on writes.
4. Token Cost Ceiling~1× baseline: Minimal prompt overhead; highest prompt-cache hit ratio.~3–5× baseline: Bounded multiplier across K focused prompts; easy to route cheap tiers to simple nodes.~10–15×+ baseline: Context accumulates across turns and tool outputs; requires strict token/turn caps and compaction.
5. Auditability & Compliance RigorHigh: Single input/output pair; trivial to log and reproduce.Highest for multi-step: Deterministic transitions and explicit code gate pass/fail logs satisfy strict regulatory audits.Complex: Non-deterministic trajectories require full event-ledger tracing (tool_trajectory) and replay harnesses.

Operating Characteristics of Probabilistic Systems

1. Non-determinism
Identical prompts can yield different phrasings or tool trajectories across runs (and modern APIs reject non-default sampling knobs or still exhibit floating-point variance). Mitigation: Test structured properties and behavioral rubrics, never exact string equality; enforce JSON schemas at the token level.
2. Plausible-sounding errors (Hallucinations)
Models are trained to complete patterns helpfully. When fed garbled OCR text, an empty string "" from a timed-out tool, or a missing policy clause, an unguarded model invents confident facts or fabricated citations. Mitigation: Pre-LLM epistemic gates, explicit is_error: true tool results, and grounded citation verification.
3. Context sensitivity & instruction crowding
Packing 30 rules, 15 irrelevant documents, and 40 tool schemas into one call degrades mid-window recall and causes the model to silently skip late audit rules. Mitigation: Split generation from verification, keep tool catalogs <= 16 per agent, and isolate noisy exploration in subagents.
4. Compounding multi-step error rates
If a single autonomous step is 95% reliable, a 10-step unverified chain succeeds only 0.95^10 ≈ 60% of the time because an early misread file poisons every subsequent turn. Mitigation: Insert ground-truth environmental feedback (compilers, unit tests, schema validators, code gates) after every step to reset the error curve.
03

3. The 5 Canonical Workflow Patterns

When a single call falls short due to instruction crowding, multi-stage dependencies, or latency/cost trade-offs—but the control structure can be designed upfront—compose the five canonical workflow patterns. In all five, application code owns or bounds the control flow.

PatternControl Flow ShapePrimary OptimizationCanonical Use CaseMemory Hook
1. Prompt ChainingLLM 1 → [Code Gate] → LLM 2 → LLM 3Accuracy via focused sub-steps + early fail-fastDrafting an outline → verifying structure in code → generating localized report"Assembly line with quality inspectors"
2. RoutingClassifier → Specialist Handler A | B | CSeparation of concerns & per-tier cost optimizationDirecting billing, refund, and tech-support tickets to distinct prompts, tools, and model tiers"Hospital triage desk"
3. ParallelizationFan-Out (N calls) → Programmatic AggregatorWall-clock speed (Sectioning) or high confidence (Voting)Running safety screening in parallel with answer generation (Sectioning); multi-prompt code security audit (Voting)"Sectioning = slice the pizza; Voting = poll 5 judges"
4. Orchestrator–WorkersOrchestrator LLM → Dynamic Workers (1..K) → SynthesizerRuntime task decomposition when sub-tasks depend on inputMulti-file refactoring or multi-source research where target files/sources aren't known upfront"Tech lead assigning tickets after reading the spec"
5. Evaluator–OptimizerGenerator → Critic/Auditor → (Pass | Feedback Loop [max M])Iterative quality & compliance against a strict rubricLegal clause extraction + adversarial citation auditor; literary translation refinement"Writer + strict editor"

Pattern 1: Prompt Chaining & Code Gates

  • Mechanism: Decomposes a predictable multi-stage task into sequential LLM calls where each call handles one focused transformation.
  • The Deterministic Gate (gate_check): Plain application code between steps that checks schema validity, required fields, length bounds, or citation existence before spending tokens on Step 2.
  • When NOT to use: Do not chain independent subtasks sequentially (use Parallelization — Sectioning to avoid serial latency), and do not chain tasks that a single structured prompt already passes on evals.

Pattern 2: Routing & Tier Dispatch

  • Mechanism: Classifies intent or difficulty (via a fast small model, embeddings, or rules) and dispatches to a specialized downstream prompt, scoped toolset, or model tier.
  • Model-tier cost optimization: Route high-volume routine queries to a fast tier (Haiku / Gemini Flash-Lite) at low effort, reserving frontier models (Sonnet / Opus / Gemini Pro) for complex reasoning.
  • Preventing misrouting cascades: Define an explicit ambiguous / fallback route that asks a clarifying question, log classifier confidence, and allow specialist handlers to reject misrouted inputs back to triage.

Pattern 3: Parallelization (Sectioning vs. Voting)

  • Sectioning (Speed & Focus): Splits a task into independent subtasks executed concurrently via asyncio.gather / ParallelAgent (e.g., extracting financial metrics, legal risks, and timeline milestones in parallel, or running input/output guardrail screening concurrently with the main response). Each branch must write to a distinct output_key to avoid state overwrites.
  • Voting (Confidence & Consensus): Runs the same task multiple times—either sampling identical prompts at T > 0 (Self-Consistency CoT for math/logic) or running diverse critique prompts—and aggregates programmatically. Tune vote thresholds to risk: use 1-of-N (any flag) for high-recall vulnerability detection, or majority vote for high-precision labeling.

Pattern 4: Orchestrator–Workers

  • Mechanism: A central Orchestrator LLM analyzes the request, dynamically invents a structured list of subtasks at runtime, dispatches scoped Worker LLMs in parallel waves, and synthesizes their compact outputs.
  • Key distinction vs. Parallelization: Topological shape is similar (fan-out → fan-in), but in Parallelization the subtasks are hardcoded in advance, whereas in Orchestrator–Workers the subtasks are decided dynamically at runtime by the model based on the specific input (e.g., choosing which 5 files in a repository need edits).
  • Spec-Driven Planner → Executor split: Use a high-capability model for the read-only orchestrator planning pass, then dispatch balanced/fast-tier workers in fresh context windows for execution.

Pattern 5: Evaluator–Optimizer & Separation of Authority

Pairs a Generator LLM with an independent Evaluator / Critic LLM that grades the draft against an explicit rubric and returns actionable feedback in a loop.

Loop PhaseAgent / MechanismInputs & ContextExit / Escalation Criteria
GenerationGenerator LLMTask brief + prior critic feedback (if any)Emits structured draft with cited section headers
Pre-Critic GateDeterministic CodeSource text + draft citationsDeterministically checks that cited headers exist in source text; fails fast if missing
EvaluationCold-Context Critic LLMSource text + draft + rubric (include_contents='none')Emits approved: bool and actionable critique; loop terminates if approved == True
Termination / FallbackDeterministic GuardIteration counter (attempt <= max_iterations)If attempt > max_iterations without approval, fails closed to HITL escalation
Architectural PatternGeneral / Anthropic FramingGoogle Cloud / ADK PrimitiveGraph / State Machine Framing
Single Building BlockAugmented LLM (Retrieval + Tools + Memory)LlmAgent with tools + MemoryServiceSingle node with tool bindings
Pattern 1: SequentialPrompt Chaining + Programmatic GateSequentialAgent / Workflow + before_agent_callbackLinear edges + conditional gate node
Pattern 2: DispatchRouting (Intent / Tier Classifier)Coordinator (sub_agents) or custom router nodeConditional edge router from START
Pattern 3a: Split WorkParallelization — SectioningParallelAgent (distinct output_keys) + synthesizerFan-out branches → JoinNode
Pattern 3b: ConsensusParallelization — Voting / Self-ConsistencyParallelAgent (N× runs) + vote aggregatorParallel ensemble → majority/threshold reducer
Pattern 4: DynamicOrchestrator–WorkersLlmAgent invoking specialist AgentToolsDynamic map-reduce / send API
Pattern 5: RefinementEvaluator–OptimizerLoopAgent(max_iterations=N) + generator & criticCyclic edge bounded by iteration counter
Open-Ended AutonomyAutonomous Agent (Tools in a Loop)LlmAgent native ReAct loop (Runner)Cyclic agent ⇄ tools graph
Human CheckpointPlanned Checkpoint / HITL ApprovalFunctionTool(..., require_confirmation=True)interrupt() / RequestInput with checkpointer
04

4. Autonomous Agent Primitives & Reasoning Loops

When the number and sequence of steps cannot be predicted in advance—because step N+1 depends on what observation N uncovered—an Autonomous Agent drives its own execution loop using environmental ground truth.

1. ReAct (Interleaved) Turn-by-turn adaptive loop O(N) sequential turns Think (Reason) Choose next action from state Act (Tool Call) Invoke Poka-Yoke ACI tool Observe (Ground Truth) Append tool_result / is_error ↻ Repeat until exit criteria or max_turns cap 2. Plan-and-Execute ReWOO / LLMCompiler Upfront DAG + parallel I/O Planner LLM Emit DAG & vars (#E1, $1) Parallel Dispatcher / Workers Execute ready tools concurrently Solver / Replanner Synthesize or replan on error 3. Grounded Reflection External verifier / critic Bounded max_iterations Generator LLM Produce candidate draft / diff Code Gate + Cold-Context Critic pytest / schema + clean-window rubric Approved Output Or fail-closed HITL escalate ↻ Actionable critique (max M)
Reasoning ParadigmExecution MechanicsStrengthsFailure Mode & When to Avoid
ReAct (Reason + Act)Interleaves Thought → Action (tool call) → Observation (ground-truth tool result) turn-by-turn.Maximum adaptability; each action is chosen from the immediate observation of the prior step.High sequential latency (O(N) LLM turns); context grows every turn; can drift into local rabbit holes without an externalized checklist.
Plan-and-Execute (ReWOO / LLMCompiler)Planner emits an upfront multi-step plan or dependency DAG of symbolic variables (#E1, $1); Executor/Dispatcher runs ready steps concurrently; Solver/Replanner synthesizes or replans on failure.Cuts sequential latency and token re-ingestion dramatically by executing independent tool calls in parallel without intermediate LLM turns.Brittle if early observations invalidate the upfront plan; requires a dynamic replanning trigger when unexpected environment state appears.
Reflection / Self-CorrectionAgent inspects deterministic feedback (compiler error, failing pytest trace, schema violation) and revises its action or draft before finishing.Automatically resolves syntax, schema, and localized logic bugs when grounded in objective test/validator output.Ungrounded reflection drift: Asking a model to "reflect and improve" without external ground truth (tests, linters, search) often degrades accuracy or amplifies hallucinations.

Stopping Conditions & Loop Hygiene

  • 1. Objective exit criteria: Define concrete completion conditions (tests pass, schema validates, or explicit finish_task / end_turn).
  • 2. Hard iteration caps (max_turns / max_llm_calls): Always bound total turns per invocation so a stuck agent halts deterministically (error_max_turns).
  • 3. Token & spend budgets (max_budget_usd): Track cumulative token cost per session and abort or escalate before runaway spend occurs.
  • 4. Duplicate tool-call detection: Hash (tool_name, canonical_json_args) across turns. If an agent repeats the exact same failing or no-op call 2–3 times, block execution in the harness and inject a loop-breaker error telling the model to change strategy or escalate.
  • 5. Structured error feedback (is_error: true): Never swallow exceptions as "" (which looks like "0 records found"). Return structured error details (error type, retryability, corrective hint) inside the tool result so the model can adapt.

ACI Design & Poka-Yoke (Mistake-Proofing)

Invest as much engineering rigor in your Agent-Computer Interface (ACI) as in human UX:

  • Junior-developer docstrings: State clearly what the tool does, when to use it, when not to use it (pointing to the right sibling tool), parameter formats, and output limits.
  • Poka-Yoke arguments: Shape tool schemas so invalid calls are impossible—e.g., require absolute file paths (/workspace/src/main.py) instead of relative paths that break after directory changes, and use strict Literal / enum types instead of free-text strings.
  • Keep tool catalogs small (<= 16 tools): Tool selection accuracy drops sharply when an agent must choose among dozens of overlapping tools; split by domain across subagents or use on-demand tool search.
Loop Guardrail DimensionDetection MechanismRuntime Action on Trigger
Turn BudgetCounter tracking total completed model roundtripsHalts execution when turn > max_turns; returns error_max_turns
Financial Cost CeilingCumulative token spend tracker (spent_usd >= max_usd)Immediately terminates session; emits budget_ceiling_exceeded
Duplicate Call TrapHash map tracking (tool_name, hash(canonical_args)) across recent turnsIntercepts 3rd duplicate invocation; returns is_error: true loop-breaker feedback
Structured Tool ErrorsException handler wrapping tool execution harnessEmits {"type": "tool_result", "is_error": true, "content": "..."} with corrective advice
Completion SignalInspects stop_reason == "end_turn" and output schemaReturns completed payload with final answer and turn count
05

5. Memory Architecture & Context Budget Engineering

A large context window is not a substitute for memory architecture. Stuffing raw transcripts, 50 KB tool responses, and 80 tool schemas into every turn inflates cost and latency while causing Context Rot.

Memory TierCognitive RoleStorage & LifetimeProduction Engineering Rules
1. Working MemoryActive scratchpad for the current task (system prompt, recent turns, live tool observations, temp: state)In-window messages[] + ephemeral invocation state (temp:*); cleared after turn/sessionKeep lean; place byte-identical static instructions and tool schemas first for prompt-cache hits; externalize live checklists (TodoWrite / state keys) so goals survive long runs.
2. Episodic MemoryRecord of specific past sessions, interaction trajectories, and checkpoints (session.events)Persistent session store (DatabaseSessionService, JSONL transcripts, checkpointer) or session summariesPowers session resume (--resume), audit trails, trajectory evaluation, and few-shot recall of how similar past tasks succeeded.
3. Semantic MemoryVerified domain knowledge, entity facts, and consolidated user preferences (user:*)Vector/hybrid RAG index or managed Memory Bank (VertexAiMemoryBankService) across sessionsConsolidate, don't just append: Use background LLM extraction to update superseded user facts rather than retrieving contradictory raw chat logs. Keep policy stores read-only during inference.
4. Procedural MemoryHow the agent operates: system prompt heuristics, tool definitions, and reusable playbooks (Skills)Code repository (CLAUDE.md, .claude/rules/, SKILL.md bundles, MCP prompt templates)Use 3-level progressive disclosure: load only compact YAML name + description (~60–100 tokens) at startup, load the full SKILL.md body only when triggered, and run bundled scripts/ outside context.

Context Rot Taxonomy: Poisoning vs. Confusion vs. Clash

  • Context Poisoning: An early hallucination, wrong file path, or refused turn enters messages[] and gets repeatedly referenced on later turns. Critical trap: Running summarization/compaction on a poisoned session preserves the poisoned assumption inside the summary block! Fix by rewinding prior to the bad turn or clearing/resetting into a fresh context window with only verified facts.
  • Context Confusion: Unrelated file dumps, bulky 50 KB JSON tool payloads, and dozens of unused tool schemas dilute model attention. Fix by paginating/pruning tool outputs, deferring tool schemas behind search, and delegating noisy exploration to subagents.
  • Context Clash: Contradictory rules across global prompts, path rules, and multi-turn instructions cause unpredictable behavior. Fix by scoping rules via path globs and resolving conflicts in an upfront spec.

The 4 Context Strategies & Compaction Mechanics

  • 1. Write (Externalize): Save plans, checklists, and large generated artifacts to typed state keys, disk files, or an ArtifactService outside messages[].
  • 2. Select (Just-in-Time): Retrieve narrow file line ranges (Grep → paginated Read), path-scoped rules, and on-demand skills only when needed.
  • 3. Compress (Compaction & Pruning): Strip verbose historical tool payloads once key fields are extracted, and trigger summarization checkpoints (Compaction) at 70–80% window capacity while retaining the last K turns verbatim (sliding window overlap). Keep the static prompt prefix byte-identical (no per-call timestamps at the top!) so prompt caching cuts input token cost by 75–90%.
  • 4. Isolate (Subagents): Offload high-volume exploration or independent verification to subagents with fresh messages[] arrays.
06

6. Multi-Agent Topologies & Handoff Contracts

The "Agent Theater" Litmus Test

Multi-agent orchestration is justified if and only if subagents have distinct tools or permissions, private data scopes, isolated context windows to contain noisy exploration, parallel I/O, or an independent verification role. Chaining three "persona" prompts that share the exact same tools and context is Agent Theater—multiplying token cost (~4×) and latency (1.5–2.5×) for zero architectural gain.

1. Hub-and-Spoke (Coordinator / Subagents) Coordinator LLM AgentTool / Task HandoffContract Subagent A (Fresh Context) Subagent B (Scoped Tools) Subagent C (Cold Auditor) 2. Sequential Pipeline (Deterministic Relay) Agent 1 Extract Code Gate Agent 2 Analyze Agent 3 Format Output State passed via explicit output_key + output_schema 3. Mesh / Debate / Swarm (Peer Handoff) Agent A (Proposer) transfer_to_agent Agent B (Red-Team) Critique / Handoff Agent C / Judge (max_turns cap) 4. Hierarchical Teams (Scoped Tool Trees ≤ 16) Root Coordinator Team Lead 1 (Data) Team Lead 2 (Code) Worker W1 Worker W2 Worker W3 Worker W4
TopologyControl & Routing MechanicsStrengthsKey Risks & Required Safeguards
1. Hub-and-Spoke (Coordinator / Subagents)Central coordinator decomposes the request, invokes specialist subagents as tools (AgentTool / Task), collects compact results, and synthesizes the final response.Central visibility, strict context isolation per spoke, easy to enforce hub-level guardrails and wave limits (3–5 concurrent workers).Coordinator context overflows if spokes return raw 50 KB dumps instead of structured summaries. Block subagents from spawning recursive subagents unless explicitly needed.
2. Sequential PipelineFixed relay (Agent 1 → Gate → Agent 2 → Agent 3) passing state via explicit keys (output_key + output_schema).Zero routing overhead; deterministic transitions; ideal for Staged Extract → Redact → Analyze → Format pipelines.Rigid; if Step 1 misclassifies an input and no deterministic gate catches it, Steps 2 and 3 compound the error.
3. Mesh / Debate / SwarmPeer specialists transfer control directly to one another (transfer_to_agent) or critique each other's proposals without a central hub.Useful for adversarial red-teaming, multi-perspective design critique, or seamless specialist conversation handoffs.Highest risk of infinite ping-pong loops, state corruption, and diffusion of responsibility. Requires strict max_turns, explicit exit tools, and a deterministic tie-breaker/judge.
4. Hierarchical TeamsMulti-tier tree where a root orchestrator delegates to domain leads, which in turn manage narrow execution workers.Scales to large enterprise systems with dozens of tools by keeping each node's tool catalog <= 16.High cumulative latency and token spend; trace debugging requires correlation IDs across every parent-child boundary.

The Context Isolation Rule

  • Fresh, task-scoped context by default: When a coordinator delegates a task (codebase search, diff audit, SQL analysis) to a subagent, the subagent must execute in a fresh context window containing only its specialist system prompt and explicit task input—never inheriting the coordinator's noisy 80-turn history. (Use full-history context forking only when the child explicitly requires the exact prior transcript and shared prompt cache.)
  • No shared mutable scratchpads in parallel waves: When running 3–5 parallel workers, assign each worker a distinct output_key or isolated file/worktree path so concurrent writes never race or overwrite one another.
  • Artifact pointer pattern: Because only a subagent's final message returns to the parent, workers generating large diffs or tables must write the full payload to disk or an ArtifactService (artifact_uri) and return only a compact HandoffContract summary to the coordinator.

Vertical (MCP) vs. Horizontal (Subagents / A2A)

  • Vertical execution (Agent → Tool/Data via MCP): Equips an agent with deterministic tools, database queries, and resources. Enforce least privilege with tool_filter allowlists and scrub PII/injections in after_tool_callback.
  • Horizontal in-process (Coordinator → Subagent): Cognitive delegation inside the same runtime via AgentTool / Task with fresh context and typed output schemas.
  • Horizontal cross-boundary (Agent → Remote Agent via A2A): Delegates stateful tasks across organizational boundaries via an AgentCard (/.well-known/agent-card.json). Remote A2A agents are opaque black boxes (they never expose internal tools, prompts, or memory)—authenticate via card securitySchemes and validate all returned artifacts as untrusted input.
class HandoffContract(BaseModel):
    task_id: str
    status: Literal["completed", "partial", "blocked", "escalation_required"]
    confidence_band: Literal["high", "medium", "low"]
    summary: str = Field(max_length=1200, description="Compact synthesis")
    artifact_uri: str | None = Field(default=None, description="Artifact path")
    verified_citations: list[dict] = Field(default_factory=list)
07

7. Anti-Patterns, Failure Modes & Architectural Checklist

Production Trust Architecture: Why Single-Prompt "Happy-Path" Prototypes Fail

While a single multimodal LLM call with a JSON schema can summarize a clean 1-page demo PDF in 2 seconds, unguarded single-prompt pipelines break on real enterprise workloads for five structural reasons:

Production SymptomRoot Architectural CauseDeterministic Architectural Fix
Agent miscalculates fees, discounts, or date windows on edge casesDeterministic drift: Delegating Bucket 1 arithmetic or policy thresholds to probabilistic prose instructions.Move calculations and threshold checks into deterministic Python/SQL tools or PreToolUse / before_tool_callback hooks.
Simple 3-step pipeline takes 45 seconds and costs $0.80 per runOver-agentification: Using an open-ended autonomous ReAct agent (or Agent Theater) where the task path is known in advance.Replace the autonomous loop with a Prompt Chain or Parallel Sectioning Workflow using fast-tier models for routine steps.
Coordinator hits model_context_window_exceeded after calling 4 research workersMissing context isolation: Workers return raw 40 KB tool dumps into the parent window, or inherit full parent history.Enforce the Context Isolation Rule: spawn workers in fresh windows, write bulky artifacts to disk/storage, and return a bounded HandoffContract summary.
Parallel workers intermittently lose data or overwrite each other's findingsShared mutable state race: Concurrent branches write to the same session state key (state["result"]) or edit the same file simultaneously.Give each parallel branch a unique output_key (result_a, result_b) merged by a downstream JoinNode/synthesizer, or isolate file edits in separate worktrees.
Generator–Critic loop burns 15 turns and still ships a hallucinated citationUnbounded loop + ungrounded reflection: No max_iterations cap, and the critic grades prose by "vibes" without checking source text in code.Cap the loop at max_iterations=3, verify citations deterministically against source text (regex/substring match), and escalate to HITL if the cap trips without approval.
Agent tells the user "You have no active orders" during a database timeoutSwallowed tool error: Tool wrapper caught the timeout exception and returned "" or {} with HTTP 200 success semantics.Return a structured error block (is_error: true or {"status": "error", "retryable": true, "message": "DB timeout"}) so the model knows the lookup failed.
After compacting a confused session, the agent keeps repeating the same wrong file pathCompacting poisoned context: Summarization compressed the earlier hallucinated file path into the compacted summary block.Use rewind / hard context reset (/clear) to discard poisoned turns entirely instead of summarizing them.
Agent selects the wrong tool when given 45 enterprise MCP endpointsTool catalog saturation: Model attention degrades when forced to discriminate among > 16 overlapping tool schemas in one prompt.Group tools by domain across specialist subagents (<= 16 tools each) or enable on-demand progressive tool disclosure / Tool Search plus tool_filter allowlists.
Summarizer agent reading an external email is tricked into calling send_emailIndirect prompt injection + excessive agency: Untrusted data entered the same context that held high-privilege mutation tools.Enforce least privilege (strip send_email from the reader agent), screen tool outputs in after_tool_callback, and gate external sends with a HITL checkpoint.

8-Point Pre-Production Architectural Checklist

08

8. Glossary, Self-Assessment & Practice Quiz

Tripartite Execution Regimes
Triage framework dividing logic into Regime 1 (Deterministic Code) for math/validation/RBAC, Regime 2 (Probabilistic LLM) for unstructured synthesis/planning, and Regime 3 (HITL) for irreversible or accountability-bearing decisions.
Sequential Decision Framework
Ordered architectural triage run before prompt writing: (1) Should an LLM be used at all? → (2) What work shape fits? → (3) How is it routed/hosted? → (4) What guardrails and verification wrap it?
Architectural Evaluation Criteria
Rubric comparing Single Call, Composable Workflow, and Autonomous Agent across path predictability, latency budget, error blast radius, token cost ceiling (~1× vs. 3–5× vs. ~15×), and auditability.
Deterministic Invariant Degradation (Deterministic Drift)
Silent reliability failure caused by delegating exact arithmetic, schema validation, or policy enforcement to probabilistic prompt instructions instead of deterministic code.
Augmented LLM
The foundational building block of agentic systems: a single LLM call equipped with retrieval, tools (often via MCP), and memory.
Prompt Chaining & Gate
Sequential workflow decomposing a predictable task into fixed LLM steps separated by deterministic plain-code checks (gate_check) that fail fast on invalid intermediate outputs.
Routing
Workflow pattern that classifies an input's intent or complexity and dispatches it to a specialized prompt, scoped toolset, or cost-appropriate model tier.
Parallelization (Sectioning vs. Voting)
Running concurrent LLM calls either on independent subtasks for speed/focus (Sectioning) or repeating the same task for consensus/high-recall verification (Voting).
Orchestrator–Workers
Workflow pattern where a central LLM dynamically decomposes an unpredictable task at runtime, dispatches scoped workers, and synthesizes their results.
Evaluator–Optimizer
Workflow pattern pairing a generator LLM with an independent critic/auditor LLM (plus deterministic checks) in a rubric-driven loop bounded by max_iterations.
ReAct vs. Plan-and-Execute
ReAct interleaves Thought → Action → Observation sequentially for exploratory tasks; Plan-and-Execute (ReWOO / LLMCompiler) plans a step list or symbolic DAG upfront and runs independent tools concurrently.
ACI & Poka-Yoke
Agent-Computer Interface design and mistake-proofing: crafting junior-dev docstrings, strict enums, and unambiguous parameters (e.g., absolute file paths) so invalid tool calls cannot occur.
4-Tier Memory Model
Working (in-window scratchpad), Episodic (session transcripts/checkpoints), Semantic (consolidated RAG/Memory Bank facts), and Procedural (system instructions, rules, progressive-disclosure Skills).
Context Rot (Poisoning / Confusion / Clash)
Poisoning (hallucinated premise survives in history; requires rewind/clear, not compaction), Confusion (bulky tool dumps dilute attention), and Clash (contradictory instructions).
Context Isolation Rule & HandoffContract
Subagents execute in fresh, task-scoped context windows rather than inheriting the coordinator's noisy history, returning a compact schema-validated HandoffContract (with artifact_uri pointers for large outputs).
Epistemic Gating & Separation of Authority
Epistemic gating blocks corrupted/unreadable inputs in code before calling the LLM; Separation of Authority pairs generation with an independent cold-context critic and deterministic citation checks.

Related guides

  • Agent Development Kit (ADK): Google's runtime architecture, LlmAgent, graph Workflow, callbacks, and Memory Bank.
  • Claude Code & Agent SDK: permission rules, hooks, subagents, progressive-disclosure skills, and Managed Agents.
  • Claude Platform & API: Messages API, tool-use loop, stop_reason, adaptive thinking, prompt caching, and batches.
  • MCP, A2A, and RAG: vertical tool protocols, horizontal agent federation, and retrieval pipelines.

Audio Deep Dive & Study Downloads

Listen to the 55-minute Agentic Design Patterns audio deep dive, open the 2-column study guide PDF, 21-slide deck, and sketchnote infographic in the Hub Viewer, or drill scenario-based questions on workflow vs. agent selection, canonical workflows, and multi-agent isolation.

Agentic Design Patterns (Video Walkthrough)
Agentic Design Patterns: Workflows vs. Autonomous Agents (Podcast)
Open Study Notes, Slide Deck & Infographic in Hub Viewer Launch Interactive ADP Practice Quiz →

Self-Assessment Questions (Click to Reveal)

Q1. What is the Sequential Decision Framework, and why must it run before prompt engineering?

(1) Problem decomposition & triage across Tripartite Execution Regimes (Deterministic Code vs. Probabilistic LLM vs. HITL), (2) Work-shape selection (Single Call vs. Workflow vs. Autonomous Agent), (3) Routing and hosting (model tiers, effort, batch/stream, residency), and (4) Deterministic guardrails and verification wrapping. Running this sequence first prevents delegating exact math/RBAC to prompts (deterministic drift) or building a 15× token autonomous agent where a 2-step workflow suffices.

Q2. How do Parallelization (Sectioning), Parallelization (Voting), and Orchestrator–Workers differ?

In Parallelization (Sectioning), the task is split into predefined, independent subtasks (e.g., running a safety screen alongside answer generation) to cut wall-clock latency. In Parallelization (Voting), the same task runs multiple times (diverse prompts or multi-sample self-consistency) and aggregates via vote thresholds to boost confidence/recall. In Orchestrator–Workers, the subtasks are not known in advance—a central orchestrator LLM inspects the input at runtime, dynamically invents the worker task list, dispatches scoped workers, and synthesizes their outputs.

Q3. Why does asking a single prompt to both generate a 30-page contract summary and verify every citation fail at scale, and what pattern fixes it?

Packing generation and strict auditing into one prompt causes instruction crowding (attention dilution) and self-grading confirmation bias—the model prioritizes fluent generation and rationalizes or skips late audit rules. Fix it with Evaluator–Optimizer + Separation of Authority: pair the generator with a separate critic in a clean context window (include_contents='none') backed by a deterministic code gate that verifies every cited section header exists in the source text, bounded by max_iterations and HITL escalation on failure.

Q4. When should you choose Plan-and-Execute (or ReWOO / LLMCompiler) over a standard ReAct loop?

Use ReAct when the task is exploratory and step N+1 cannot be predicted until step N's observation returns (e.g., debugging an unknown production outage). Choose Plan-and-Execute / ReWOO / LLMCompiler when the required subtasks or dependency DAG can be planned upfront and executed concurrently—avoiding O(N) sequential LLM turns and repetitive prompt re-ingestion.

Q5. A coding session hallucinates a non-existent helper module in turn 3 and spends the next 6 turns failing to import it. Why is context compaction (/compact) the wrong fix, and what should you do instead?

This is context poisoning. Compaction summarizes the existing conversation history, which preserves the hallucinated premise inside the summary block so the agent continues acting on it. Instead, rewind to the checkpoint prior to turn 3 or clear/reset into a fresh context window carrying over only verified facts.

Q6. What is the Context Isolation Rule in multi-agent systems, and how should a worker return a 40 KB generated report to its coordinator?

A subagent must receive a fresh, task-scoped context window containing only its specialist instructions and explicit task inputs—never the coordinator's full noisy conversation transcript. Because only the subagent's final message returns to the parent, it should write the 40 KB report to disk or an ArtifactService and return a compact, schema-validated HandoffContract containing a short summary, status, verified citations, and the artifact_uri pointer.

Q7. During an evaluator–optimizer loop with max_iterations=3, the critic rejects the draft on all 3 attempts. What must happen next?

Many frameworks exit a loop silently when max_iterations trips. The exit tool must explicitly set an approval flag (approved = True) when the critic passes; a downstream deterministic gate checks that flag and, if False after iteration 3, halts automatic delivery and routes the draft + critic diagnostics to Human-in-the-Loop (HITL) escalation or a safe fallback.

Q8. What is the "Agent Theater" litmus test?

Multi-agent orchestration is justified if and only if subagents have distinct tools/permissions, private data scopes, isolated context windows to contain noisy exploration, parallel I/O, or an independent verification role. Wrapping multiple persona prompts in a sequential relay with identical tools and shared context is Agent Theater—multiplying token cost and latency without improving reliability.