Chapter 0 – Introduction to Agentic Programming

What Is an AI Agent?

The term “agent” has been used across computer science for decades, but in the context of modern AI, it has taken on a very specific meaning. An AI agent is a system built around a large language model (LLM) that can autonomously perceive its environment, make decisions, take actions, and adapt based on feedback — all in pursuit of a goal defined by a human.

Unlike a traditional chatbot that produces a single response to a single prompt, an agent operates in a loop: it reasons about what to do next, executes an action (such as calling a tool, writing code, or searching the web), observes the result, and decides whether to continue, adjust its plan, or return a final answer.

Workflows vs. Agents

Anthropic draws an important architectural distinction between two types of agentic systems:

In practice, most production systems fall on a spectrum between these two extremes. A customer service bot might follow a mostly deterministic workflow (greet → classify → route → respond) but allow the model to choose which knowledge base article to cite. A coding agent, on the other hand, might be almost entirely autonomous, deciding which files to read, what changes to make, and how to test its work.

                    Workflows                          Agents
                ┌─────────────────┐           ┌─────────────────────┐
  Control:      │  Developer      │           │  LLM                │
  Flexibility:  │  Low            │           │  High               │
  Predictability│  High           │           │  Lower              │
  Complexity:   │  Lower          │           │  Higher             │
                └─────────────────┘           └─────────────────────┘

Why Agentic Programming Matters

The shift from single-turn LLM calls to agentic architectures is driven by a simple observation: iterative refinement dramatically improves output quality.

Andrew Ng’s research at DeepLearning.AI demonstrated this powerfully. On the HumanEval coding benchmark:

The improvement from adding an agentic workflow to GPT-3.5 far exceeded the improvement from upgrading to GPT-4 in zero-shot mode. This is a fundamental insight: how you use the model often matters more than which model you use.

The Four Core Design Patterns

Andrew Ng identified four key agentic design patterns that drive this improvement:

  1. Reflection — The LLM examines its own work to find ways to improve it
  2. Tool Use — The LLM is given tools (web search, code execution, APIs) to gather information or take action
  3. Planning — The LLM creates and executes a multi-step plan to achieve a goal
  4. Multi-Agent Collaboration — Multiple specialized agents work together, splitting tasks and debating solutions

These four patterns form the conceptual foundation of this book. We will explore each in depth, along with several workflow patterns that provide additional structure and control.

The Five Workflow Patterns

Anthropic’s guide to building effective agents identifies five workflow patterns commonly seen in production:

  1. Prompt Chaining — A task is decomposed into a sequence of LLM calls, where each processes the output of the previous one
  2. Routing — An input is classified and directed to a specialized handler
  3. Parallelization — Multiple LLM calls run simultaneously and their outputs are aggregated
  4. Orchestrator-Workers — A central LLM breaks down a task dynamically and delegates subtasks to worker LLMs
  5. Evaluator-Optimizer — One LLM generates a response while another evaluates and provides feedback in a loop

When (and When Not) to Use Agents

A critical principle runs through all expert guidance on agentic systems: start with the simplest solution that works.

“When building applications with LLMs, we recommend finding the simplest solution possible, and only increasing complexity when needed.” — Anthropic

Agentic systems trade latency and cost for better task performance. Before building an agent, consider:

Use workflows when:

Use agents when:

The Road Ahead

This book will take you from foundational concepts to production-ready patterns:

Each chapter includes Python code examples demonstrating the pattern, discussion of when to use (and not use) the pattern, and practical tips from production deployments.

Let’s begin.


Navigation: