Lecture 7: LLM Agents and Harness Engineering

How do you turn a good model into something that actually gets work done? Put it in a loop, give it planning, tools, memory and actions, and engineer everything around it — the harness. Watch the lecture in ten short chapters with English and Chinese subtitles, follow the lecture map below, then build a small agent yourself in Colab.

📅 Nov. 6th, 2026 🎥 chapters · min 🖼 slides 💬 EN + 中文 subtitles 🧭 Lecture map 💻 Colab notebooks ⬇ Slides (PDF)
Transcript follows the video · click a sentence to jump · Shift + ←/→ jumps between slides

1The lecture map

Agent = Model + Harness: what should we build around an LLM, and what should we leave to the model?

Five acts, ten chapters. Prompting tricks grow into a loop; the loop gets four elements — planning, tools, memory and action; then the second half engineers the harness around the model, takes agents into the wild and its benchmarks, and ends with whole societies of agents. Click a chapter to watch it.

IFrom prompts to a loop
One call with imagined feedback becomes a loop with real feedback
IIThe four elements
Planning, tools, memory and action
IIIHarness engineering
Everything in an agent except the model
IVIn the wild
Where agents work, and how we measure them
VSocieties
When the environment is made of other agents
Chapter by chapter what each chapter covers, and the question it leaves for the next
  1. IFrom prompts to a loopOne call with imagined feedback becomes a loop with real feedback
  2. 1

    From Prompts to Agents: ICL, CoT and Self-Refine

    2026 is the race for the personal agent. The road there starts with tricks inside one model call — in-context examples, chain of thought, sampling and voting, self-critique — which later become planning, tools, memory and sensors.

    → If an agent is these tricks running in a loop, what exactly is an agent?
  3. 2

    What Is an Agent? From ELIZA to the Agent Loop

    A system that acts in an environment and learns from feedback. The idea runs from Minsky's Society of Mind through ELIZA and RL agents to LLM agents, and fits in a five-line loop: think, act, observe.

    → The loop is simple — what makes it useful?
  4. IIThe four elementsPlanning, tools, memory and action
  5. 3

    Planning and Reflection: ToT, LLM+P and ReAct

    Decompose with least-to-most, search over thoughts with Tree of Thoughts, hand planning to a classical planner with LLM+P, reflect on real feedback, and interleave reasoning with acting in ReAct.

    → Plans need hands — how does a model act?
  6. 4

    Tools: From Program of Thoughts to MCP

    Let code do the math, let expert models and robot skills do the work, then see a tool call step by step: the model only writes a request, the harness decides whether to run it. MCP standardizes the connection.

    → Every call adds tokens to a finite window — what does the agent remember?
  7. 5

    Memory and Action: Embeddings, RAG and Robots

    Short-term memory is the context window; long-term memory is retrieval, built on text embeddings, or simply files with an index. Then action leaves the screen: PaLM-E, vision-language-action models and π0.

    → We have all four elements — why does the same model make a mediocre agent in one system and an excellent one in another?
  8. IIIHarness engineeringEverything in an agent except the model
  9. 6

    Harness Engineering: Context, Skills, Guides and Sensors

    Prompt, then context, then harness engineering. The harness alone moves scores by 10–20 points. Manage the finite attention budget, package know-how as skills, connect tools through MCP, and steer with guides and sensors.

    → How do real products apply these principles?
  10. 7

    Harnesses in Practice: Claude Code, Codex and Multi-Agent

    Three products, one loop: Claude Code bets on a simple single loop, Codex on one core for many surfaces, OpenClaw on being always on. When one agent is not enough, A2A lets agents hire agents — but more agents often hurt.

    → Agents run for hours and crash — how do we keep them running, and prove they work?
  11. 8

    Fault Tolerance, Evaluation and the Bitter Lesson

    Retries, checkpoints and durable execution; sessions that outlive the context window; safety for agents that touch real systems; evals graded on outcomes with pass@k and pass^k — and why the best harness gets thinner as models improve.

    → Where do agents already work, and how do we know?
  12. IVIn the wildWhere agents work, and how we measure them
  13. 9

    Agents in the Wild and How We Benchmark Them

    Single agents (Devin), open worlds (Minecraft), multi-agent games and markets, and science (ChemCrow). Benchmarks moved from WebShop and SWE-bench to finishing whole jobs: fast kernels, unknown games, companies and AI research.

    → What happens when the environment itself is made of agents?
  14. VSocietiesWhen the environment is made of other agents
  15. 10

    Agent Societies and Economic World Models

    Planets don't react to predictions; people do. Economic world models simulate the economy through the beliefs and actions of many LLM agents, as in WonderEcon, and double as training gyms and safety tests. The lecture closes with five takeaways.

2Try it in Colab

Three short notebooks turn the lecture into experiments. Click Open in Colab, then Runtime → Run all. Each ends with exercises. All three run on a free CPU runtime; a T4 GPU only makes Notebook 1 faster and lets you try bigger models.

Notebook 1 · Chapters 2–4 · ~15 min on CPU, ~5 on GPU

A ReAct agent loop in 40 lines

  • Declare tools with JSON schemas and write the five-line loop
  • Watch a real 0.5B model (Qwen2.5) write its own tool calls
  • Add a permission gate, errors that teach and a step budget
  • Measure the same model in two harnesses
Open in Colab .ipynb · CPU or GPU
Notebook 2 · Chapter 8 · ~2 min

pass@k vs. pass^k

  • Reproduce slide 125: 75% per try gives 98% pass@3 but 42% pass^3
  • Estimate both from a finite number of trials
  • See why retries need a grader, and test whether a harness fix really helped
Open in Colab .ipynb · CPU, no model
Notebook 3 · Chapter 5 · ~3 min

Agent memory: files vs. embeddings

  • Embed English and Chinese sentences and see meaning as geometry
  • Build a MEMORY.md file memory and search it with grep
  • Compare grep and a vector index on paraphrases, Chinese queries and updated facts
  • Compute the InfoNCE loss with in-batch negatives
Open in Colab .ipynb · CPU

3Concept index

Key terms of the lecture. Each link opens the video at the slide where the idea is explained.

5Quotes & reading

"What magical trick makes us intelligent? The trick is that there is no trick. The power of intelligence stems from our vast diversity, not from any single, perfect principle."

Marvin Minsky, The Society of Mind (1986), quoted on slide 21
Agents are not new — and the multi-agent societies of Chapter 10 are Minsky's question with LLMs as the agents.

"Consistently, the most successful implementations weren't using complex frameworks or specialized libraries. Instead, they were building with simple, composable patterns."

Why Claude Code is a deliberately simple single loop (Chapter 7), and principle 1: start with one loop.

"Good context engineering means finding the smallest possible set of high-signal tokens that maximize the likelihood of some desired outcome."

The principle behind slide 83: context is a finite attention budget.

"The biggest lesson that can be read from 70 years of AI research is that general methods that leverage computation are ultimately the most effective, and by a large margin."

Why the best harness gets thinner as models get stronger — and principle 10: delete regularly.

Further reading

6About this video

This is an AI-narrated version of the lecture. The slides are the ones used in class. The spoken script was written from the slides with AI assistance and is read in an AI clone of Prof. Benyou Wang's voice (MiniMax speech synthesis); the picture in the corner is a still photo. The red dot points at what is being discussed. When the narration and the slides disagree, trust the slides and the in-class lecture — and please tell us, so we can fix it.
CSC5051/CSC6052/MDS5110 Natural Language Processing · CUHK-Shenzhen · Fall 2026 · Back to the course page