[KongchangAI]
· 4 min read· 2,071 words

Andrew Ng's Agent Course Highlights: A Practical Path from Single Agents to Full Automation

Andrew Ng's Agent Course Highlights: A Practical Path from Single Agents to Full Automation

Andrew Ng's 2-hour course systematically breaks down agent design patterns from ReAct to LangGraph with hands-on examples.

Co-created by Andrew Ng, LangChain founder Harrison Chase, and Tavily founder Rotem Weiss, this course covers five core agent design patterns (planning, tool use, reflection, multi-agent, memory) and walks through building a ReAct agent from scratch before refactoring it with LangGraph. It details LangGraph's node-edge-state model, persistence, streaming, and advanced capabilities like state modification, time travel, and human-in-the-loop via checkpoints. The capstone project chains research, generation, critique, and re-research into a self-iterating multi-node graph, with a final overview of supervisor, plan-and-execute, and language agent tree search architectures.

Andrew Ng, together with LangChain founder Harrison Chase and Tavily founder Rotem Weiss, released the course AI Agents in LangGraph — a two-hour systematic breakdown of the core design patterns behind agentic workflows. The course starts with a deceptively simple question: why does iterative Agentic Workflow so often outperform asking a large model to "write everything in one shot"?

Why Agentic Workflow Is Worth the Excitement

Ng compares the typical LLM usage pattern to "asking someone to write an essay from the first word to the last without ever pressing backspace." That clearly doesn't reflect how humans actually create. Agentic Workflow takes the opposite approach — outline first, decide whether to search the web, write a draft, self-critique, and iteratively improve based on that critique.

He shared a story that he called an "Agentic AI moment" on par with the "ChatGPT moment": during a live demo at Stanford, he had an Agent do a web search before writing an article — but the Web Search API suddenly failed. Just as he braced for a public failure, the Agent autonomously switched to a Wikipedia search tool he had configured and long forgotten, completing the task without a hitch. That experience of "software autonomously executing complex sequences of actions" is at the root of his optimism about agents.

An interesting technical aside: Agentic Workflow can also feed back into foundation model training. Directly using LLM-generated text to train the next generation of models doesn't work well, but inserting an Agentic Workflow in the middle to produce high-quality data yields results that are genuinely useful for training the next generation.

Five Core Design Patterns for Agents

Ng uses the analogy of "three people co-writing a paper" to explain agent collaboration: one person plans and outlines, one does research and gathers documents, one writes the draft, and others review and suggest revisions in a loop. From this, he distills five key design patterns for Agentic Workflow:

  • Planning: Think through which steps to take — outline first, then decide on subsequent actions
  • Tool Use: Know which tools are available and how to use them, such as search tools
  • Reflection: Iteratively improve results; multiple LLMs can critique each other and suggest revisions
  • Multi-agent communication: Each role acts like an LLM with a unique prompt, taking on a distinct responsibility
  • Memory: Track progress and results across multiple steps

Harrison Chase highlighted two key improvements over the past year that have enabled agents to succeed in production: first, LLMs with function calling support have made tool use predictable and reliable; second, concrete tools like search have been redesigned to better suit agent needs — agents don't need a list of links, they need structured answers with citable sources.

Building a ReAct Agent from Scratch

The first step in the course is to build a ReAct (Reasoning + Acting) agent from scratch using only an LLM and Python — no frameworks. The loop works like this: the LLM first thinks (Thought), then decides on an action (Action), the action executes in the environment and returns an observation (Observation), and then the LLM continues the loop with that observation until it determines the task is complete.

In practice, the Agent class is parameterized with a system message and maintains a list of messages, appending new ones each turn. A carefully crafted system prompt constrains the model to output in Thought/Action/PAUSE/Observation format, and two toy tools are provided (a calculator and a dog average weight lookup). The course walks through the full journey from manually stepping through calls, to parsing actions with regex and wrapping everything into an automated query loop.

Still a bit manual at this stage

The value of this section lies in clearly distinguishing "what work the LLM handles vs. what the surrounding runtime code handles" — the agent's intelligence comes from the LLM, while control flow, tool execution, and loop logic are all managed by external code.

ReAct (Reasoning + Acting) is an agent reasoning framework jointly proposed by Google and Princeton University in 2022, in a paper titled ReAct: Synergizing Reasoning and Acting in Language Models. Its core idea is to interleave chain-of-thought reasoning with external tool actions, rather than having the model reason purely internally or execute actions without reasoning. Traditional Chain-of-Thought (CoT) only reasons internally and cannot access up-to-date external information; pure action execution lacks reasoning steps and struggles with complex tasks requiring multi-step decomposition. ReAct's Thought → Action → Observation cycle allows the model to incorporate external observations into each subsequent reasoning step, effectively reducing hallucinations and improving performance on long-horizon tasks. This is also why the implementation requires a carefully designed system prompt to strictly constrain output format — the model must pause at each PAUSE node and wait for real tool execution results, rather than fabricating observations.

Refactoring with LangGraph: Nodes, Edges, and State

The large loop function in the hand-written agent is exactly the problem LangGraph is designed to solve. LangGraph is an extension of LangChain built specifically for agent and multi-agent workflows, with a core capability of describing and orchestrating control flow — particularly for building cyclic graphs.

LangGraph has three core concepts: Nodes are agents or functions, Edges connect nodes, and Conditional Edges determine which node to go to next. The course refactors the hand-written agent into: a node that runs the LLM, a conditional edge that checks whether there's a pending action, and a node that executes the action — which then loops back to the LLM node, forming a closed cycle.

Another key concept is State management. Agent State is accessible across all nodes and edges in the graph and can be persisted to a storage layer. The course specifically covers two behaviors for state updates: fields annotated with operator.add (like message lists) are appended rather than overwritten on update; unannotated fields are replaced with the new value. This design directly determines how an agent accumulates conversation history and intermediate steps.

In practice, when faced with a question like "What is the GDP of the state where the 2024 Super Bowl champion is located?", the agent demonstrates sequential tool calling — it must first learn that the champion is the Kansas City Chiefs and confirm the state is Missouri before issuing the second query. This contrasts with parallel tool calling, such as simultaneously querying "weather in San Francisco and Los Angeles."

LangGraph is built on a directed graph computational paradigm, which is fundamentally different from the chain-based design at the core of early LangChain. Chain-based calls form a directed acyclic graph (DAG) where data flows in one direction and cycles are not supported by design. But real-world agent tasks often require repeated iterations of "complete a step, evaluate the result, decide the next step" — which requires a directed cyclic graph (Cyclic Graph). LangGraph's State management borrows the "Reducer" concept from functional programming: each node doesn't directly modify global state but instead returns a partial update, which the framework applies to the global state according to pre-defined merge rules (such as append or overwrite). This design makes state changes predictable and traceable, and is the foundation for persistence and time-travel features — each state change can be independently recorded as a Checkpoint snapshot.

The course dedicates a full section to the difference between Agentic Search and traditional search. Ordinary search returns a list of links that a user still needs to click, fetch, parse HTML, and clean — the course demonstrates this cumbersome process live using DuckDuckGo and BeautifulSoup.

Agentic search tools like Tavily, by contrast, first understand the question, optionally decompose it into sub-questions, select the best data source for each sub-question (e.g., a weather API for weather questions), extract relevant information from the source, chunk it and use vector retrieval to pull the most relevant segments, and finally score and filter results. What gets returned is structured JSON.

Ng's team surfaces a key insight: this JSON is hard for humans to read, but "that's exactly what an agent wants — structured data." Humans need an intuitive interface with temperature, humidity, and wind speed icons; agents need data in a format that can be precisely parsed by code.

Persistence, Streaming, and Human-in-the-Loop

Long-running agent tasks depend on two key concepts: Persistence lets you save an agent's state at any point and restore it later; Streaming lets you see in real time what the agent is doing. LangGraph saves state snapshots between each node via a Checkpointer (such as SQLite Saver), distinguishing different sessions by thread ID to support concurrent multi-user deployments in production.

Real-time streaming output

Persistence also unlocks powerful Human-in-the-loop capabilities. By setting interrupt_before=action when compiling the graph, execution can be paused before a tool runs, waiting for human approval. The course further demonstrates several advanced patterns:

  • State modification: Correcting the agent's misinterpretation of "Los Angeles" to "Louisiana"
  • Time travel: Using get_state_history to return to any historical checkpoint and re-run from there
  • Branch editing: Returning to a past state, modifying it, and diverging into a new branch
  • Manual result injection: Using the as_node=action parameter to masquerade as the action node and feed the agent a simulated tool return value without actually calling the tool

Custom reduce messages function

One technical detail here: in human-in-the-loop scenarios, messages need to be replaced rather than appended, so a custom reduce_messages function is needed that uses message IDs to determine whether to replace or append.

"Human-in-the-loop (HITL)" is a core concept in reliability engineering for production-grade AI systems — it means preserving human approval or correction capability at critical decision points in an automated workflow. In agent scenarios, HITL is especially important because LLMs are susceptible to hallucinations, and some tool calls (like sending emails, executing database writes, or triggering payments) have irreversible side effects. LangGraph's interrupt_before mechanism suspends graph execution before a specified node, essentially turning what would be a continuous computation into a coroutine-style "pauseable and resumable" process. Combined with the persistence capabilities of the Checkpointer, even if the server restarts after an agent interruption, context can be precisely restored from the checkpoint without re-executing completed steps. The "time travel" feature further turns the agent's execution history into a branchable version tree — this has significant engineering value when debugging complex agent behavior or when trying different strategies on the same task.

Capstone Project: A Self-Critiquing Essay-Writing Agent

The course's final project is an "AI researcher / essay-writing agent" that ties all the previous concepts together into a complex multi-node graph: generate a writing plan → conduct research based on the plan (call Tavily to retrieve documents) → generate a draft → check if it's complete → if not, enter a Reflect node to generate critique → conduct another round of research based on the critique → return to the generation node to rewrite — looping until the max_revisions condition is met.

Project broken down into multiple sub-steps

This agent's state is considerably more complex than before, tracking the task, plan, draft, critique, research content list, revision count, and maximum revision count. The course also includes a GUI that lets you pause after each node, inspect memory state snapshots, and manually modify the plan (such as absurdly changing "pizza shop" to "the importance of jelly donuts in pizza-making"), giving an intuitive view of how state evolves and how time travel works.

More Advanced Agent Architectures

The course closes with an overview of several advanced architectures that weren't implemented in the course but are worth knowing:

  • Multi-agent architectures: Multiple agents collaborating on the same shared state
  • Supervisor architecture: A powerful LLM acting as a supervisor, responsible for routing and coordinating sub-agents, each of which can have its own independent state
  • Flow Engineering: Sourced from the Alpha Codium paper, placing loops at key nodes to achieve SOTA coding performance
  • Plan-and-Execute: Explicitly plan first, then execute step by step, with the ability to re-plan as needed along the way
  • Language Agent Tree Search: Tree search over possible action states, with the ability to backtrack and update parent node information — which also highlights the importance of persistence

Harrison Chase emphasized that LangGraph's biggest differentiator from other frameworks is a high degree of controllability — every arrow in the graph explicitly defines how state flows, and that controllability is exactly what's needed to build agents that actually work in production.

#Andrew Ng AI Agents#LangGraph tutorial#ReAct agent#agentic workflow#human-in-the-loop#LangChain agents#multi-agent architecture#AI agent design patterns
Share:

Related articles