0% read on this device
Browse the curriculum

Start Here

Vision

First Principles

Operating Model

Domain Model

Agent Factory

Runtime Architecture

AI Engineering

Autonomous Workflows

Verification & Delivery

Factory Platform

Quality Engineering

Security & Governance

Case Studies

Labs

Interview Practice

Research Journal

Reference

Curriculum/AI Engineering/A rapid review of the chapter’s existing Quick Read, principles, definitions, lessons, and review material.
AI Engineering7 min readchapter

Agent and Loop Engineering Patterns

An agent can reason, act, observe, and continue, but production work needs more than an open ended loop. The system must decide which tasks deserve agents, which agent configuration is eligible, when to use one agent or several, what happen

Status: Draft for studyRisk: highLifecycle: plan · execute · verify · learnContent reviewed 2026-08-30Maturity guide →
Claim boundaryThis is curriculum guidance. It does not by itself prove a production implementation.
study mode

A rapid review of the chapter’s existing Quick Read, principles, definitions, lessons, and review material.

Whiteboard exercise

Reconstruct and defend this chapter’s architecture.

Reconstruct the architecture, name each boundary, and defend the tradeoffs.

agent runtimemodelscontext7 min chapter
Open the source exercise

Design a workflow that classifies an issue, routes it to a specialist profile, plans, implements, verifies, repairs twice, detects oscillation, and escalates. Show deterministic and model decisions, typed handoffs, budgets, stop conditions, separate Attempts, and the human decision packet.

3. Enduring Principle

Use the least agentic mechanism that solves the problem

Choose among:

  • a deterministic function for known transformations and policy;
  • a deterministic workflow for stable ordered work;
  • one agent loop for bounded ambiguous reasoning and tool use;
  • a routed set of specialized agents when task classes differ materially; and
  • a multi-agent workflow when independence, parallelism, context isolation, or distinct expertise creates measurable value.

The objective is not to maximize agent count. It is to minimize total error, human attention, cost, and lead time while preserving authority and evidence.

Define a task-specific agent profile

A Task-Specific Agent Profile records the capabilities required for a class of work: reasoning depth, context window, tool use, structured output, repository scale, environment, latency, cost, security, privacy, availability, and historical evaluation. It binds an eligible model route, instructions, skills, tools, context policy, harness capabilities, budgets, and verifier requirements.

Profiles should reflect task roles such as classification, planning, implementation, review, recovery, or summarization. They are eligibility templates, not permanent assignments to one model provider.

Route conditionally under policy

Conditional routing uses observable state to select a permitted next node:

  • task type, risk, complexity, repository, and required capability;
  • confidence or ambiguity calibrated on representative cases;
  • tool, provider, environment, and capacity availability;
  • cost, latency, retry, and attention budgets;
  • prior failures and changed hypotheses; and
  • required independence or human authority.

Deterministic routing should handle known rules. Model classification may propose a route for ambiguous inputs, but the orchestrator filters it through eligibility and records alternatives, reason, uncertainty, and fallback.

Use named orchestration patterns

PatternUse whenPrincipal risk
Single agent with toolsOne bounded context and authority set is sufficientBroad context and self-confirmation
Router to specialistTask classes need materially different profilesMisclassification and hidden fallback
Planner then executorUpfront decomposition reduces implementation ambiguityPlan becomes stale or invents requirements
Generator then independent verifierOutput needs separate assuranceCorrelated model, context, or tool failure
Parallel fan-out/fan-inIndependent research or candidate generation benefits from parallelismCost, duplication, synthesis error
Map-reduceWork divides into uniform independent unitsLost global invariant
Supervisor-workerDynamic delegation is requiredSupervisor becomes unbounded authority bottleneck
Debate or adversarial reviewCompeting hypotheses improve a consequential judgmentConfident argument without external evidence
Human escalationMeaning, risk, authority, or unresolved ambiguity exceeds automationPoor decision packet and approval fatigue

Every handoff should use a typed contract containing objective, source lineage, scope, inputs, outputs, unresolved questions, evidence, budget, and completion state. Conversational memory is not a reliable handoff contract.

Engineer the attempt loop explicitly

The canonical loop is Generate → Verify → Diagnose → Repair or Replan → Retry → Escalate or Stop. Verification should produce structured findings linked to criteria. Retry requires a changed hypothesis, input, tool, configuration, or recovery action. Repeating the same conditions is not a strategy.

Define convergence and stop conditions

Track progress through resolved criteria, failing tests, finding count and severity, changed uncertainty, artifact distance, policy state, and consumed budgets. Stop or escalate when:

  • the required outcome is independently verified;
  • a hard gate fails;
  • work requires authority the Attempt does not possess;
  • the retry, token, time, tool, compute, or monetary budget is exhausted;
  • consecutive iterations produce no material progress;
  • the loop oscillates between prior states;
  • new work expands the approved scope;
  • the environment or dependency is not trustworthy;
  • evidence becomes stale or contradictory; or
  • a human decision is required.

An iteration limit is a final containment boundary, not the only convergence mechanism.

Separate retry, fallback, replan, and escalation

  • Retry repeats a logical operation after a transient or corrected failure.
  • Repair changes the artifact or local implementation hypothesis.
  • Replan changes the authorized sequence while preserving approved intent and scope; material changes require a new Plan revision.
  • Fallback selects a different eligible route, tool, or environment under policy.
  • Escalation asks a human or higher authority to resolve a bounded decision.
  • Stop contains unsafe, unauthorized, or non-converging work.

Each action creates new history. It must not overwrite the failed Attempt or hide why the strategy changed.

Preserve verifier independence inside multi-agent workflows

Different role prompts on the same model and context may produce correlated errors. Choose independence according to consequence: separate execution, different tools or methods, deterministic checks, blinded context, different model families, or human review. The verifier must not silently edit the candidate it is certifying.

8. Notes and lessons learned

  • A retry without a changed hypothesis is usually repeated cost, not recovery.
  • Multi-agent architecture is justified by measurable independence, parallelism, specialization, or context isolation.
  • Convergence belongs to the runtime contract, not to a model's confidence.
  • The best router often filters with deterministic policy before asking a model to rank eligible choices.

9. Interview and discussion questions

  1. When should a deterministic workflow replace an agent?
  2. What belongs in a Task-Specific Agent Profile?
  3. How do retry, repair, replan, fallback, and escalation differ?
  4. Which signals show that an agent loop is not converging?
  5. When is a multi-agent system worth its coordination cost?
  6. How would you establish verifier independence for a high-risk migration?
External review

Review this chapter.

Challenge a claim, boundary, missing failure mode, unclear term, or unsupported evidence statement.

  • Claim
  • Boundary
  • Failure
  • Evidence