Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Agent

Pattern

A reusable solution you can apply to your work.

Understand This First

  • Model – the agent’s intelligence comes from the model.
  • Tool – tools give the agent the ability to act.
  • Harness (Agentic) – the harness provides the loop and tool management.

Context

At the agentic level, an agent is a model placed in a loop: it inspects state, reasons about what to do, calls tools, observes results, and iterates until it reaches an outcome or gets stopped. An agent is more than a model answering questions. It’s a model acting in the world, changing things, and responding to what happens next.

This is the central pattern of agentic software construction. Everything else in this section (tools, harnesses, verification loops, approval policies) exists because agents exist. When people talk about “agentic coding,” they mean directing an agent to build, modify, test, and maintain software on your behalf. The term draws a deliberate line against “vibe coding,” where a developer prompts casually and accepts whatever comes back. Agentic coding implies structure: the agent operates inside a harness, follows constraints, and verifies its own output.

Problem

How do you take a model’s ability to generate text and code and turn it into the ability to accomplish real tasks that require multiple steps, decisions, and interactions with the outside world?

A model on its own can produce a single response to a single prompt. But real tasks (“fix this bug,” “refactor this module,” “add this feature”) require reading files, making changes, running tests, interpreting results, and trying again if something fails. A single prompt-response cycle isn’t enough. What you need is a loop.

Forces

  • A model produces one response per turn. Multi-step tasks need a loop.
  • Real work (reading files, running commands, checking test results) requires capabilities beyond text generation.
  • The first attempt rarely works. Iterative refinement is how complex tasks converge.
  • The more capable the agent, the more important it becomes to define its boundaries.

Solution

An agent is constructed by placing a model inside a loop with access to tools. The basic structure is:

  1. The agent receives a task (from a human or from another agent).
  2. It examines the current state by reading files, checking test results, or querying systems.
  3. It decides what to do next: write code, run a command, ask a clarifying question.
  4. It executes that action using a tool.
  5. It observes the result.
  6. It returns to step 2 until the task is complete or it needs human input.

The harness provides this loop structure, manages tool access, and enforces approval policies. The model provides the reasoning and decision-making within each iteration.

What makes an agent different from a simple automation script is judgment. A script follows a fixed sequence. An agent reads a test failure, reasons about the cause, considers multiple possible fixes, chooses one, and verifies it worked, adapting its approach based on what it finds. This judgment is powered by the model’s training but guided by the context you provide.

Note

A model with no tools is a chatbot. Give it file access, a shell, and a test runner and it becomes an agent that can build software. The tools define what the agent can do; the prompt and context define what it should do.

How It Plays Out

A developer tells an agent: “The login page shows a blank screen on Safari.” The agent reads the relevant component file, spots a CSS property that Safari handles differently, applies a fix, runs the browser test suite, and reports that it passes. The developer reviews the diff and approves it. A thirty-minute debugging session compressed into three minutes of agent work and one minute of human review.

A harder case: a developer asks an agent to migrate a database schema. The agent reads the current schema, generates a migration file, applies it to a test database, runs the application’s test suite, discovers two tests fail because of a renamed column, updates the application code to match, reruns the tests, and reports success. Each step informed the next. No single prompt-response could have done this.

Example Prompt

“The checkout flow is returning a 500 error when the cart has more than 50 items. Reproduce the bug by reading the relevant test, find the root cause, fix it, and run the test suite to confirm. Show me what you find before making changes.”

Consequences

Agents compress the time for well-defined tasks. Bug fixes, spec-driven features, refactors, test generation: anywhere the loop of try, check, iterate can converge on a verifiable outcome, agents deliver.

They struggle with ambiguity. Novel architectural decisions, tasks that hinge on business context absent from the context window, and situations where “correct” depends on stakeholder judgment all remain human territory. Agents can also cause real damage if given too much autonomy without appropriate approval policies and least privilege constraints. The skill you’re developing is knowing which tasks to delegate and which to keep, setting boundaries around what the agent can touch, and maintaining a verification loop backed by tests for everything the agent produces.

  • Depends on: Model – the agent’s intelligence comes from the model.
  • Depends on: Tool – tools give the agent the ability to act.
  • Depends on: Harness (Agentic) – the harness provides the loop and tool management.
  • Enables: Subagent – agents can delegate to more specialized agents.
  • Enables: Verification Loop – agents naturally work in verify-and-iterate cycles.
  • Refined by: Approval Policy – policies define the agent’s boundaries of autonomy.
  • Uses: Prompt – the prompt steers the agent’s behavior within the loop.
  • Constrained by: Least Privilege – agents should have only the permissions their current task requires.
  • Scoped by: Boundary – boundaries define where an agent’s work begins and ends.
  • Informed by: Test – tests provide the oracle an agent checks against in its verification loop.

Sources

  • Stuart Russell and Peter Norvig defined an agent as “anything that can be viewed as perceiving its environment through sensors and acting upon that environment through actuators” in Artificial Intelligence: A Modern Approach (1995). Their perceive-reason-act loop is the conceptual ancestor of the agentic loop described here.
  • Shunyu Yao and colleagues formalized the interleaving of reasoning and acting for language models in the ReAct paper (2022, published at ICLR 2023). ReAct demonstrated that models perform substantially better when they can reason about observations before choosing their next action — the same loop structure this pattern describes.
  • Timo Schick and colleagues showed that language models can learn to use external tools (calculators, search engines, APIs) in Toolformer (2023), establishing tool use as a practical capability rather than a theoretical one.
  • Andrew Ng popularized the term “agentic” in its current sense during 2024, helping the AI community converge on shared vocabulary for systems where models act autonomously within loops.
  • By 2026, agents had moved from research prototypes to production infrastructure. Gartner’s 2026 CIO Agenda found 64% of technology leaders planned to deploy agentic AI within 24 months, and LangChain’s survey reported over 57% of organizations already running agents in production.