Lecture 18 · Language-Model-Based Agents

Advanced Natural Language Processing · Lecture 18。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

Maps to: CMU 11-711 Spring 2026, Lecture 18 (03/19), “Language Model-Based Agents”, a guest lecture by Zora (Zhiruo) Wang; slides anlp-s2026-18-zora.pdf; no course code. Readings: T. Shi et al., World of Bits: An Open-Domain Platform for Web-Based Agents (ICML 2017); R. Nakano et al., WebGPT: Browser-Assisted Question-Answering with Human Feedback (2022). Additional: S. Yao et al., WebShop (NeurIPS 2022); J. Yang et al., SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering (2024); J. Koh et al., VisualWebArena (2024); T. Xie et al., OSWorld (2024); P. Aggarwal, S. Welleck, Programming with Pixels (2025). Sources: the public slides, the readings, and the papers cited in each section. The slides are a survey; numbers they quote are attributed to them. Every number labelled “measured” comes from code/lecture18/, run on the author’s machine (Apple M4 Pro, Python 3.13, PyTorch 2.14, one CPU thread). Code: code/lecture18/ — four demos, each under a minute. Reading time: ~80 minutes for the prose; ~20 more for the demos.


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Define an LM-based agent by its parts: environment, observation space, action space, internal state, and the LM backbone that maps them to actions. Say what is and is not an agent.
  2. Compare observation formats (HTML, accessibility trees, filtered trees, screenshots with marks), and reason about their cost in tokens and their risk of hiding what the agent needs.
  3. Explain why tools and induced skills help: fewer, larger actions mean fewer chances to err. Know when they do not help.
  4. Describe how agents keep memory (facts, preferences, procedures, reflections) and why it matters for partially observed tasks.
  5. Explain how agents are trained: demonstrations, DAgger, RL from outcome rewards, synthetic demonstrations from exploration and relabeling. Say what each data source can and cannot teach.
  6. Read an agent benchmark critically: task, environment, evaluation, partial vs full success, saturation, and the human in the loop.

0.2 Prerequisites and scope

  • Prerequisites:
    • Lectures 16–17: MDPs, policies, exposure bias, policy gradient, rewards.
    • Lecture 10: retrieval (an agent’s simplest tool).
    • Lecture 11: vision–language models (for screenshot agents).
    • Lecture 13: evaluation and benchmarks.
  • Scope: the slides’ survey (observation, action, internal state, building agents, human-centered agents), with the course readings’ web agents (World of Bits, WebShop, WebGPT) as the running thread.
  • Not in scope:
    • Multi-agent systems.
    • Agent safety and security (prompt injection is mentioned only as a pitfall).
    • Robotics beyond examples.
    • The prompting details of particular agent frameworks.

0.3 Section → code map

SectionIdeaDemo in code/lecture18/
§1.3the agent loop in a toy web shop01_observations.py Part A (+ shop_world.py)
§2observations: HTML vs accessibility tree vs filtering, context budgets01_observations.py Parts B–C
§3.2–3.3tools and APIs vs browsing; compounding errors03_actions_and_skills.py Parts A–B
§3.4inducing and verifying a skill03_actions_and_skills.py Part C
§4.1memory across attempts (Reflexion)04_memory_and_data.py Part A
§4.2–4.3behavior cloning, failures, exposure bias, DAgger, RL02_learned_agent.py
§4.4demonstrations from exploration + relabeling04_memory_and_data.py Part B

0.4 Notation

SymbolMeaning
xxthe task instruction (“i want a red linen t-shirt in size m, under 30 dollars”)
oto_t, ata_tobservation and action at step tt
ht=(x,o0,a0,…,ot)h_t = (x, o_0, a_0, \dots, o_t)the history; an LM agent’s context is built from it
π(at∣ht)\pi(a_t \mid h_t)the agent’s policy: the LM conditioned on the prompt built from hth_t
RRthe episode’s reward, computed by the environment’s evaluator

1. From language models to agents

1.1 What an agent is

A language model maps a prompt to text. An agent closes the loop with an environment:

                 ┌──────────────── environment ───────────────┐
                 │  web page / file system / OS / game world   │
                 └───────┬───────────────────────────▲─────────┘
            observation  │                           │  action
                 ┌───────▼───────────────────────────┴─────────┐
                 │  internal state (≈ the prompt: instruction,  │
                 │  history, memory)  ──►  LM backbone          │
                 └──────────────────────────────────────────────┘

At each step the agent:

  1. observes (a page, a file, a screenshot);
  2. updates its internal state, which for an LM agent is mostly the prompt: instruction, recent observations and actions, retrieved memories;
  3. asks the LM for the next action: LM(· | prompt).

The action changes the environment, and the loop repeats until the task is done or a step limit is reached.

Russell & Norvig’s classic definition fits: an agent is “anything that can be viewed as perceiving its environment through sensors and acting upon that environment through actuators.”

Examples from the slides:

  • digital agents: software engineering (SWE-agent, OpenHands), web navigation and computer use (WebArena, OSWorld);
  • embodied agents: a Minecraft agent that writes its own skill library (Voyager); text-based household tasks (ALFWorld);
  • physical agents: robots learning locomotion by imitation;
  • social agents: simulated people in a town (Generative Agents).

What is probably not an agent:

  • a RAG system: it observes (retrieves) but takes no actions that change the world;
  • a reasoning model: it computes, but has no environment;
  • program-of-thought: it may be, if the executed code acts on something.

The slides’ survey of tools (Wang et al., 2024) separates three activities: perception (collect observations), action (change the environment’s state) and computation (general computing, like a calculator or a code interpreter). Agents act; the others are tools an agent may use.

1.2 Why this is hard for language models

Agents inherit every LM weakness and add their own:

  • long, noisy inputs: a web page is thousands of tokens of markup;
  • many sequential decisions: errors compound, and one wrong click can derail the episode;
  • partial observability: what is not on the current screen must be remembered;
  • exposure bias (Lecture 16): an imitating agent has never practiced recovering from its own mistakes;
  • evaluation: success must be checked in the environment, often only at the end.

1.3 A laboratory: Shop World

The demos use Shop World (shop_world.py), a small text web shop in the style of WebShop (Yao et al., 2022):

  • 480 products in 6 categories, each with a brand, color, material, price and options (sizes, capacities, light tones). About 30% of titles use a synonym (“tee”, “cup”, “rucksack”).
  • Tasks are instructions generated from real products: “find me a white linen t-shirt in size xl, under 20 dollars”.
  • Pages: a search page, a results page (5 products per page, ranked by word overlap with the query), and product pages with option buttons and “buy now”.
  • Reward (WebShop’s idea): when the agent buys, the share of the 5 requirements met (category, color, material, option, price within budget); 0 if it does not buy within 15 steps. Success means all 5.

A reference policy (“the expert”) knows what the instruction means, including that a tee is a t-shirt. It sees only what it is shown, so it learns a product’s sizes only by opening its page.

One episode (demo 01):

instruction: find me a white linen t-shirt in size xl, under 20 dollars
search   -> search[white linen t-shirt xl]
results  -> click[acme white linen t-shirt $16.99]
item     -> click[xl]
item     -> click[buy now]
bought 'acme white linen t-shirt' (t-shirt), option xl: reward 1.0

2. Observation space

2.1 Text: files and web pages

Files. SWE-agent (Yang et al., 2024) showed that how a coding agent reads files matters. Its agent-computer interface (ACI) shows 100 lines at a time with line numbers, search commands that summarize matches, and a linter on edits. These interface choices, not a better LM, raised the solve rate substantially over a raw shell.

Web pages. A browser receives HTML: content buried in navigation bars, scripts, styling and nested <div>s. WebArena (Zhou et al., 2023) instead gives agents the accessibility tree, the browser’s structured list of interactive elements, each with a role, a name and an id:

[1] link 'acme white linen t-shirt' text '$16.99'
[2] link 'acme white linen t-shirt' text '$37.99'
...
[6] button 'next >'

Even accessibility trees of real sites run to thousands of lines, so agents often filter: a model ranks elements by relevance to the task and keeps the top few. Mind2Web (Deng et al., 2023) uses a small LM ranker. The slides note that it misses all relevant elements 47% of the time, in which case the agent cannot possibly act correctly.

2.2 Images: screenshots, marks and grounding

Some interfaces (desktop apps, canvas-based pages) have no usable tree, so agents read screenshots with a vision–language model (Lecture 11). Two techniques help:

  • Set-of-marks prompting: draw numbered boxes over interactive elements, so the model can say “click 12” instead of producing pixel coordinates (used by tools like browser-use).
  • Visual grounding models trained to map a description (“the search button”) to coordinates (UGround, Gou et al., 2024; Jedi, Xie et al., 2025), so a general model plans and a grounding model points.

VisualWebArena (Koh et al., 2024) and OSWorld (Xie et al., 2024) benchmark agents on visually grounded web and desktop tasks.

2.3 Measured: what the agent cannot see, it cannot click

Demo 01 renders the same Shop World results page three ways:

renderingtokens (this results page)tokens per page, averaged over episodes
HTML1,470 (first product at token 321)826
accessibility tree12369
filtered tree (top 3 products + controls)7438

To isolate the effect of the observation, the agent here is the perfect reference policy, allowed to act only on elements that appear within the first WW tokens of what it reads (500 tasks):

observationbudget WWtask success
HTML5120.0%
HTML1,02495.0%
HTMLall100.0%
accessibility tree6445.6%
accessibility tree128100.0%
filtered, top 5 / 3 / 1all100.0% / 98.0% / 83.2%
  • Format decides cost. The accessibility tree is 12× shorter than HTML for the same content. With a 512-token window, the HTML reader never even reaches the products, because navigation and scripts fill the window.
  • Filtering trades length for recall. On 591 results pages that listed a fitting product, it survived the filter 92.7% of the time with top-1, 98.0% with top-3 and 100% with top-5. Failures follow recall. Every filter is a model that can be wrong, and an agent behind a filter inherits its errors.

3. Action space

3.1 Default and specialized actions

Computer-use agents share a common set of primitive actions: click, type, scroll, key press, open a URL, send a message to the user. On top of these, applications offer specialized actions: a code agent’s edit and run_tests, a spreadsheet’s formula functions, a site’s API. In the slides’ framing, specialized actions are tools.

3.2 Tools beat primitive actions, where they exist

The slides’ example: checking the weather by browsing takes about 20 primitive steps (click, fill, press Enter, read, …). With an API it is one call, check_weather("Pittsburgh").

Song et al. (2024), “Beyond Browsing”, compared agents on WebArena that browse, that call the sites’ APIs, and that do both:

  • whether APIs or browsing work better depends on the website (how complete its API is);
  • hybrid agents get the benefits of both.

3.3 Measured: browse vs API vs hybrid

Demo 03 builds three versions of the shop:

  • browse only;
  • API only: a buy_product[category, color, material, option, max price] call that finds and buys in one step;
  • hybrid: the API covers only t-shirts, hoodies and mugs, and the rest needs browsing.

A learned agent (§4.2) is trained by imitation on each version and tested on 300 new tasks:

shopexpert stepssuccess, 25 demossuccess, 100 demos
browse only4.4651.7%89.0%
hybrid2.7475.7%93.7%
API only1.0076.3%100.0%

Why fewer steps help. The 25-demonstration agents have similar step accuracy, the share of the expert’s decisions they would also make: 76.4%, 80.9% and 76.3%. But browsing needs 4.46 decisions per task and the API one. Errors compound with every decision. The naive estimate accuracy^decisions (30.1% / 56.0% / 76.3%) is too pessimistic for browsing, because decisions differ in difficulty (the search step is always right), but the ordering is the measured one.

An API only helps where it exists: the hybrid site lands between the two.

3.4 Skills the agent induces itself

Human-engineered APIs are scarce. Can agents build their own tools?

  • TroVE (Wang, Fried & Neubig, 2024): for programmatic tasks (math, table QA, visual reasoning), the agent writes reusable functions while solving tasks and keeps those that verify. The result is a small toolbox that makes solutions shorter and easier for humans to check. The slides show a one-line calc_rate_of_change(...) replacing ten lines of pandas: higher accuracy, faster verification.
  • ASI (agent skill induction; Wang et al., 2025): a web agent turns successful action sequences into programmatic skills, e.g. search_reviews(search_box_id, search_button_id, term) from a sequence of clicks and fills. Skills are verified by re-executing them, then used as single actions. The slides report gains in both accuracy and efficiency on WebArena tasks, and skills adapt to new websites.
  • Agent Workflow Memory (Wang et al., 2025) stores induced workflows as text in memory rather than code (§4.1).

3.5 Measured: inducing and verifying a skill

Demo 03 (Part C) counts consecutive action pairs in 300 successful expert episodes:

paircountsharesame page?
item → option30028.7%no
option → buy30028.7%yes
search → item28527.3%no

The most frequent pair that acts on one page (no new observation needed in between) becomes the skill select_and_buy[option]. Verification by execution: replaying the 300 tasks with the skill gives the same purchase in all 300.

Effect:

shopexpert stepssuccess, 25 demossuccess, 100 demos
browse only4.4651.7%89.0%
browse + skill3.4651.0%88.7%
hybrid + skill2.2377.3%93.7%

The skill saves a step per task but does not raise success, because the two actions it bundles were rarely the ones that went wrong (§4.2’s failure taxonomy: wrong products, missing sizes). Skills pay off when they bundle decisions that are hard or repeated many times, as in ASI’s multi-step web workflows. A skill is a bet that its parts are reliable together.

3.6 Teaching LMs to use tools

  • Prompting with demonstrations: describe the tools in the prompt and show examples (most frameworks).
  • Self-supervised tool use: Toolformer (Schick et al., 2023) lets the model insert API calls into text and keeps the calls that lower the loss on the following tokens.
  • Tool tokens: ToolkenGPT (Hao et al., 2023) gives each tool its own token embedding, so calling a tool is predicting a token. New tools can be added without retraining the LM.

4. Internal state, and how agents learn

4.1 Memory

An LM’s weights are fixed during an episode; what changes is its context. Memory systems decide what goes into it:

  • Factual and preferential knowledge: MemGPT (Packer et al., 2023) manages memory like an operating system, paging facts between the context and external storage. Products such as Mem0 and Letta make “memory layers” a service. The slides note that memory has become something users carry between assistants (ChatGPT → Claude).
  • Procedural knowledge:
    • Reflexion (Shinn et al., 2023): after a failure, the agent writes a verbal lesson (“the size must be selected before buying”) and reads it on the next attempt;
    • Agent Workflow Memory (Wang et al., 2025): reusable workflows induced from past successes and retrieved for new tasks.

Lecture 16 showed why memory matters: when the observation hides part of the state (the inventory in Key Quest), the best memoryless policy fell from 0.995 to 0.114. Here it is “which products did I already open?”, which the expert and the learned agent both read from their history.

Measured: retrying with memory (demo 04, Part A; the 25-demonstration agent, 300 tasks, up to 3 attempts):

strategysuccess within 1 attempt23
retry, greedy, no memory51.7%51.7%51.7%
retry, sampling, no memory51.0%58.0%62.0%
retry, greedy, with memory of failures51.7%63.7%65.0%

A deterministic agent without memory makes the same mistake again. Sampling makes retries differ, and remembering what failed is better still. An example memory entry, written from the environment’s feedback:

bought ‘acme red cotton hoodie’ (l): option did not match — avoid this option

4.2 Learning from demonstrations

The most direct way to train an agent is behavior cloning: collect expert trajectories and train the policy to predict the expert’s action given the history.

  • World of Bits (Shi et al., 2017) introduced MiniWoB, web tasks with crowd-sourced demonstrations, and found behavior cloning plus RL necessary.
  • WebShop (Yao et al., 2022) trained a BERT “choice model” on human demonstrations, then fine-tuned it with RL. The paper reports about 29% success against 50% for average humans on its real-product site.
  • WebGPT (Nakano et al., 2021) cloned human browsing for question answering, trained a reward model on human comparisons, and used best-of-N rejection sampling. Its answers were preferred to its human demonstrators’ a majority of the time.

Our learned agent (agent.py) follows WebShop’s design at toy scale:

  • a small neural choice model scores each available action from word embeddings of the action and the instruction;
  • it has two little “tools”: a price comparison (computation) and a check of its own history (memory).

It is not a large LM; the conclusions below concern data, errors and recovery, not reasoning.

Measured (demo 02, 300 new tasks):

demonstrations251004001,000
success51.7%89.0%98.3%100.0%
partial reward0.8710.9530.9861.000
  • Report success, not only the partial reward. An average score of 0.871 sounds good; it hides that only 51.7% of purchases are right (Lecture 13’s metric lesson).
  • A failure taxonomy shows what to fix. With 25 demonstrations, 74 of 145 failures are a wrong option and 12 forgot the option. These are errors of checking, which more data fixes first.
  • The agent learns what keyword matching cannot. Offered two titles with the same color and material words, one a synonym (“tee”) and one another category, it picks the synonym 42.3% of the time after 25 demonstrations and 85.2% after 400. A keyword matcher would be at 50%.

A demonstrator with privileged information cannot be imitated. Our first expert chose products already knowing their sizes, which the results page does not show. Behavior cloning plateaued near 85%, with mostly option errors: the agent could not see what the expert used. Human demonstrations have the same problem whenever people use knowledge that is not on the screen.

4.3 Exposure bias: DAgger and RL

Imitation trains on the expert’s states. The agent’s mistakes take it to states the expert never visited, where it has no idea what to do (Lecture 16’s exposure bias). Demo 02 splits the test tasks:

  • direct (238): the first fitting product has the requested size;
  • needing recovery (62): going back or to the next page.
agent (from 100 demonstrations)direct tasksneeding recoveryallextra supervision
behavior cloning92.4%75.8%89.0%—
+ DAgger (3 rounds × 100 tasks)98.3%95.2%97.7%300 expert-labelled episodes
+ RL from the outcome reward (100 updates)95.8%69.4%90.3%3,200 rewarded episodes
  • DAgger (Ross et al., 2011) runs the agent, asks the expert what it would have done in every state the agent visited, adds those labels and retrains. It is told exactly how to recover, and the recovery tasks jump to 95.2%.
  • RL from the outcome reward (REINFORCE with a leave-one-out baseline, Lectures 16–17) improved the direct tasks but not recovery. Its sampled episodes rarely contain a successful recovery to reinforce: the same sparse-reward problem as Key Quest’s random agent, at a smaller scale.

At LLM scale both ideas are used. Agents are fine-tuned on corrected trajectories, and trained with outcome rewards on many attempts per task, the RLVR recipe of Lecture 17 applied to multi-step episodes.

4.4 Where do demonstrations come from?

Human demonstrations are expensive. The slides survey three alternatives:

  • Synatra (Ou et al., 2024) turns indirect knowledge, such as online how-to tutorials, into synthetic direct demonstrations at scale.
  • BAGEL (Murty et al., 2024) and NNetNav (Murty et al., 2025) let an agent explore a website freely, then relabel each trajectory with an instruction it happens to accomplish. This is the idea of hindsight experience replay (Andrychowicz et al., 2017): every trajectory succeeds at something.
  • OpenCUA (Wang et al., 2025) collects human computer-use demonstrations with an annotation tool, at scale.

Measured: exploration + relabeling vs an expert (demo 04, Part B). A random explorer searches with random catalog words, opens a random result, picks a random option and buys. Each episode is relabeled with an instruction describing that purchase.

training datasuccesswrong option‘back’ actions in the data
expert, 25 episodes51.7%74—
expert, 100 episodes89.0%6—
expert, 400 episodes98.3%061 of 1,768 decisions
explorer + relabeling, 400 episodes80.7%24—
explorer + relabeling, 1,000 episodes81.3%230 of 4,000
expert 25 + explorer 1,00083.7%25—
  • Relabeled exploration gets most of the way (80.7% from 400 episodes) without any instruction-following expert.
  • Coverage decides what can be learned. The explorer only ever buys products it opened, so its data contains no “back” actions. The agent never learns to leave a product that lacks the requested size, and “wrong option” failures stay at 23 however much data is added. Synthetic data teaches what its generator does, and nothing else.

5. Building and evaluating real-world agents

5.1 Benchmarks

An agent benchmark has three parts (the slides, with TheAgentCompany, Xu et al., 2024, as example):

  • a task: a natural-language instruction;
  • an environment: files, websites, simulated users or colleagues, an execution sandbox;
  • an evaluation: rule-based checks of the final state (did the file change? was the order placed?), or LLM-based judgments, often with partial credit for checkpoints.

The landscape spans:

  • web navigation (MiniWoB, WebShop, WebArena, VisualWebArena, Mind2Web);
  • computer use (OSWorld);
  • software engineering (SWE-bench, and “Programming with Pixels”, where coding agents must work through the same screen interface as people);
  • workplace tasks (TheAgentCompany);
  • embodied and game worlds.

A recent analysis in the slides (Wang et al., 2026) asks how well benchmark tasks reflect the distribution of real work. Many cluster in a few occupations.

Pitfalls (Lecture 13 applies in full):

  • Partial vs full success. Demo 02’s partial reward of 0.871 hid a 51.7% success rate. Report both, and say what the partial credit counts.
  • Saturation. The slides cite a February 2026 analysis, “Why SWE-bench Verified no longer measures frontier coding capabilities”. Once top agents solve most tasks, the remaining failures are dominated by flawed or underspecified tasks, and the benchmark stops separating systems.
  • Contamination and environment drift. Live websites change; tasks leak into training data.
  • Evaluation by the environment can be gamed. An agent that edits the test, or finds a shortcut the checker does not catch, scores without solving the task: reward hacking (Lecture 17) in agent form.

5.2 Frameworks and agent foundation models

An agent framework wraps an LM with the pieces of this lecture: an observation interface, a tool and function-calling layer, memory, and skills. Examples:

  • general agents (Manus, ChatGPT Agent);
  • coding-oriented agents (OpenHands, Claude Code), whose skills can be packaged instructions and scripts the agent loads when relevant.

Training agent foundation models means improving the LM itself for these loops:

  • synthetic demonstrations (Synatra, BAGEL, NNetNav);
  • human computer-use data (OpenCUA);
  • RL on environments with checkable outcomes (§4.3).

5.3 From solo agents to human-centered agents

The slides close with where agents fall short in practice:

  • Agents do work differently from people. Comparing AI and human workflows across occupations (Wang et al., 2025), agents tend to take programmatic routes even for visual or open-ended tasks, and they sometimes fabricate results to appear done.
  • Humans are missing from coding-agent research (a 2026 position paper by Wang, Yang, Lieret et al.). Real software engineering involves clarifying intent, reviewing and maintaining code with people, which autonomous benchmarks do not measure.

How to close the gap:

  • scale the modeling of human behavior and preferences;
  • enable efficient oversight: readable skills and verifiable steps, as TroVE’s toolboxes are faster to check;
  • define measures of interaction quality;
  • go beyond software engineering.

From autonomous to collaborative agents:

  • CowPilot (Huq et al., 2025) lets the agent drive web sessions while a human verifies and intervenes, improving success over either alone;
  • Collaborative Gym (Shao et al., 2024) evaluates asynchronous human–agent collaboration.

6. Summary

  1. An LM agent = an LM in a loop with an environment: observation → internal state (the prompt) → action. RAG systems and pure reasoners are not agents; their tools are.
  2. Observation space: HTML is mostly noise; accessibility trees are compact; filters trade recall for length.
    • Measured: a perfect agent reading HTML through a 512-token window succeeds 0% of the time.
    • The tree fits in 128 tokens (100%).
    • Filtering to the top 1 product costs 17 points of success.
  3. Action space: tools and APIs collapse many primitive steps into one, and errors compound per decision.
    • Measured: 25 demonstrations give 51.7% by browsing, 75.7% on a hybrid site and 76.3% with an API.
    • An induced, verified skill saved a step but not errors.
  4. Internal state: memory decides what a fixed LM sees.
    • Measured: retries with a memory of failures reach 65.0% vs 51.7% for a greedy agent without memory.
  5. Learning: behavior cloning needs data and cannot copy privileged knowledge. Measured:
    • DAgger fixes the recovery that imitation misses (75.8% → 95.2%); outcome-reward RL did not;
    • relabeled exploration reaches 80.7% without an expert, but never learns behavior its explorer never shows.
  6. Evaluation: task, environment, evaluator. Report full success next to partial credit, watch for saturation and reward hacking, and keep humans in the loop.

Common pitfalls

  • Feeding raw HTML (or whole files) to a fixed context. What falls outside the window does not exist for the agent.
  • Trusting an element filter or retriever blindly. Measure its recall on your tasks; the agent cannot click what was filtered out.
  • Many small actions where one tool would do. Each step is a chance to fail; prefer APIs and verified skills for routine sub-tasks.
  • Imitating demonstrators who used information the agent cannot see. The agent learns to guess.
  • Evaluating only on the expert’s states. An agent’s own mistakes take it elsewhere; test, and train, on its own trajectories (DAgger, RL).
  • Synthetic data without coverage checks. Count which behaviors appear in it (here: zero “back” actions).
  • Reporting average partial reward alone. It can hide that half the tasks fail.
  • Letting the agent reach the evaluator. Agents that can edit tests or checkers will, eventually.

Exercises

  1. Is it an agent? Classify, with a reason: (a) a RAG chatbot over company documents; (b) a code assistant that runs the test suite and edits files until the tests pass; (c) a reasoning model solving a math problem; (d) a model that writes a SQL query that a human then runs.

    Answer(a) No: it observes (retrieves) but takes no action on the environment. (b) Yes: it observes files and test output and acts (edits, runs) in a loop. (c) No: computation only, no environment. (d) Borderline: the model proposes an action, but the human executes it. It becomes an agent if it runs the query and reacts to the result; as described it is a tool for a human agent.
  2. Context budgets. A results page has 300 tokens of navigation, then 10 products at 120 tokens each as HTML, or 12 tokens each in an accessibility tree with 20 tokens of header. With a budget of 1,000 tokens, how many products can an agent see in each format? What does a top-3 filter change?

    AnswerHTML: (1,000 − 300)/120 = 5.8, so 5 products. Tree: (1,000 − 20)/12 ≈ 81, so all 10. A top-3 filter shows only 3 products in either format, but the right 3 only if the ranker is right: recall replaces truncation as the failure mode. Demo 01 measured 92.7% recall for top-1 and 98.0% for top-3.
  3. Compounding errors. An agent picks the right action with probability 0.9 at every step and cannot recover. What is its success rate on a 5-step task and a 20-step task? An API reduces the 20-step task to 2 calls with the same per-call accuracy. Why might the real gain be smaller?

    Answer$0.9^5 = 59\%$, $0.9^{20} = 12\%$; with 2 calls, $0.9^2 = 81\%$. The real gain may be smaller because API calls are harder decisions: more arguments, any one of which can be wrong. The API may also not cover the task, or fail in ways the agent cannot see. Conversely, recovery (going back) makes browsing better than $p^n$, which is why demo 03's naive estimate was too pessimistic.
  4. Privileged demonstrators. A demonstrator sees each product’s sizes on the results page; the agent does not. Explain why behavior cloning plateaus, and give two fixes.

    AnswerThe demonstrator's choice depends on information outside the agent's observation. For the agent, identical observations are followed by different actions, so the best it can learn is a guess (its policy averages over the hidden variable). Fixes: (1) make the demonstrator act only on what the agent sees: open the product, check the size, go back (what demo 02 does); (2) add the missing information to the agent's observation (show sizes on the results page). A third option is to let the agent learn with DAgger, where an expert labels the agent's own states.
  5. DAgger vs RL. Why did DAgger fix the recovery tasks while RL from the outcome reward did not, with ten times as many episodes?

    AnswerDAgger gets a *label* in exactly the states where the agent goes wrong: "here, go back". RL gets only the episode's reward. To learn "go back" it must first *sample* a recovery that ends in success, and the cloned policy rarely tries "back" (it never saw it). Most of its recovery episodes fail with no signal about which step was wrong: a sparse-reward credit-assignment problem. RL helped the direct tasks, where successful episodes are common.
  6. Relabeling. An explorer’s trajectory searches “nova cup”, opens “nova green glass cup $14.99”, chooses 12oz and buys. Write the relabeled instruction. Name one behavior such data can never teach, and how to add it.

    Answer"i want a green glass mug in 12oz, under 20 dollars" (the purchase described in task form; the budget rounded up). Never taught: leaving a product that does not fit (no "back"), using the next page, or fixing a wrong option, because the explorer always buys what it opened. Add exploration that sometimes opens a product and goes back, relabel those with instructions the product does *not* meet, or mix in a few expert demonstrations of recovery.
  7. Benchmarks. An agent benchmark reports a mean score of 0.87 using partial credit for 5 requirements. What else would you want to know before comparing two agents?

    AnswerThe full-success rate (demo 02: 0.871 mean with only 51.7% fully right); the failure taxonomy; the number of tasks and a confidence interval (Lecture 14); variance over seeds and environment states; whether tasks or answers could have leaked into training data; whether the evaluator can be gamed; how many steps and how much compute each agent used; and how close top systems are to the ceiling set by flawed tasks (saturation).
  • Assignments 3–4: agent projects are popular and easy to get wrong. If your project builds or evaluates an agent:

    • measure the observation pipeline’s recall;
    • count steps and failures by type, not just success;
    • test on the agent’s own trajectories;
    • report full success with error bars.

    These notes do not provide assignment code.

Further reading

  • T. Shi et al., “World of Bits: An Open-Domain Platform for Web-Based Agents”, ICML 2017 (course reading); R. Nakano et al., “WebGPT: Browser-Assisted Question-Answering with Human Feedback”, 2022 (course reading).
  • S. Yao et al., “WebShop: Towards Scalable Real-World Web Interaction with Grounded Language Agents”, NeurIPS 2022; S. Zhou et al., “WebArena”, ICLR 2024; X. Deng et al., “Mind2Web”, NeurIPS 2023; J. Koh et al., “VisualWebArena”, ACL 2024; T. Xie et al., “OSWorld”, NeurIPS 2024.
  • J. Yang et al., “SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering”, NeurIPS 2024; P. Aggarwal, S. Welleck, “Programming with Pixels”, 2025; F. Xu et al., “TheAgentCompany”, 2024.
  • S. Yao et al., “ReAct: Synergizing Reasoning and Acting in Language Models”, ICLR 2023; T. Schick et al., “Toolformer”, NeurIPS 2023; S. Hao et al., “ToolkenGPT”, NeurIPS 2023; Z. Wang et al., “What Are Tools Anyway? A Survey from the Language Model Perspective”, COLM 2024.
  • Y. Song et al., “Beyond Browsing: API-Based Web Agents”, 2024; Z. Wang, D. Fried, G. Neubig, “TroVE: Inducing Verifiable and Efficient Toolboxes for Solving Programmatic Tasks”, ICML 2024; Z. Wang et al., “Inducing Programmatic Skills for Agentic Tasks” (ASI), 2025; Z. Wang et al., “Agent Workflow Memory”, ICML 2025.
  • C. Packer et al., “MemGPT: Towards LLMs as Operating Systems”, 2023; N. Shinn et al., “Reflexion: Language Agents with Verbal Reinforcement Learning”, NeurIPS 2023; G. Wang et al., “Voyager”, 2023; J. Park et al., “Generative Agents”, UIST 2023.
  • T. Ou et al., “Synatra”, NeurIPS 2024; S. Murty et al., “BAGEL”, 2024, and “NNetNav”, 2025; X. Wang et al., “OpenCUA”, 2025; S. Ross, G. Gordon, D. Bagnell, “A Reduction of Imitation Learning and Structured Prediction to No-Regret Online Learning” (DAgger), AISTATS 2011; M. Andrychowicz et al., “Hindsight Experience Replay”, NeurIPS 2017.
  • F. Huq et al., “CowPilot”, 2025; Y. Shao et al., “Collaborative Gym”, 2024.

Preview of Lecture 19 — Quantization

The next block is about making models cheaper. Every agent step above is a forward pass of an LM, and long-running agents multiply that cost. Lecture 19 starts with quantization:

  • number formats; absmax and zero-point quantization;
  • why outlier features break naive int8 (LLM.int8());
  • 4-bit NormalFloat and QLoRA.

Measured on the course’s own Transformer: planted outlier features, and facts recalled against bits per weight.


术语表 (Glossary, English → 中文)

English中文
language-model-based agent基于语言模型的智能体
environment / observation / action / internal state环境 / 观测 / 动作 / 内部状态
perception / action / computation感知 / 行动 / 计算
digital / embodied / physical / social agent数字 / 具身 / 物理 / 社会智能体
HTML / DOM / accessibility tree网页源码 / 文档对象模型 / 无障碍树
element filtering / ranking / recall元素过滤 / 排序 / 召回率
screenshot / set-of-marks / visual grounding截图 / 标记集提示 / 视觉定位
agent-computer interface (ACI)智能体-计算机接口
context budget / context window上下文预算 / 上下文窗口
primitive action / tool / API / function calling原子动作 / 工具 / 接口 / 函数调用
hybrid agent混合智能体
skill induction / programmatic skill / verification by execution技能归纳 / 程序化技能 / 执行验证
toolbox / tool token工具箱 / 工具词元
memory / reflection / workflow memory记忆 / 反思 / 工作流记忆
behavior cloning / demonstration / choice model行为克隆 / 示范 / 选择模型
privileged information特权信息
exposure bias / compounding error / recovery暴露偏差 / 误差累积 / 纠错恢复
DAgger (dataset aggregation)数据集聚合
outcome reward / partial reward / task success结果奖励 / 部分奖励 / 任务成功率
failure taxonomy失败分类
exploration / hindsight relabeling / synthetic demonstrations / coverage探索 / 事后重标注 / 合成示范 / 覆盖度
benchmark saturation / environment drift基准饱和 / 环境漂移
human-in-the-loop / oversight / collaborative agent人在回路 / 监督 / 协作式智能体
← 返回课程目录