Engineering AI Agents · Week 4

Skills, protocols,
and context engineering

Expertise on a shelf · sockets in the wall · deciding what lands on the desk

Slides CC BY 4.0 · from the teaching kit of AI Agents, Engineered by Enrique Gutiérrez · aiagentsengineered.com/teach/

A week of watching a well-equipped agent

“Every tool call succeeds, and the work is still wrong.”

Chapter 6, opening

By the end of today you can

Four objectives

  1. Say which layer a gap belongs to: tool, protocol or skill
  2. Compute the M×N → M+N collapse and state three costs of protocols
  3. Name the five context failure modes from their symptoms
  4. Apply write, select, compress, isolate to a mid-run desk

Part 1 · Chapter 6 (full book)

Skills, protocols, and interoperability

What a skill is

A named folder of know-how

main file: name + description, then the instructions references: a style guide, a schema, a lookup table templates: skeletons for the output scripts: the steps better done deterministically
“Building a skill for an agent is like putting together an onboarding guide for a new hire.”Quoted in Chapter 6, “What a Skill Is”

Files: versioned, reviewed, shared, fixed once for every agent that loads them

Before the next slide · do the arithmetic

A year of your team’s know-how: a hundred procedures, each a few pages, about a couple of thousand tokens.

Paste them all into the standing prompt. What does the agent carry on every call, to answer one customer email?

Chapter 6, “Progressive Disclosure” · sizes illustrative

Progressive disclosure · reveal in layers, each pulled in only when needed

A table of contents, then one chapter

  • L1, the menu: name + description of every skill; ~100 tokens a line
  • L2, the body: one skill, loaded when judged relevant
  • L3, the bundle: only the slice this branch needs
  • Scripts are executed, never read
Progressive disclosure: the skill library stays on disk in three levels. The menu of names and descriptions is always loaded onto the desk, one skill's instructions load when judged relevant, and only the needed slice of references, templates and scripts follows; scripts are executed, never read.
Figure from Chapter 6 · ~100 tokens per line: one guide’s illustration

At the moment of choosing, the menu line is all the agent has

The description decides whether it loads

The shape to imitate (vendor guidance quoted)

Extract text and tables from PDF files, fill forms, merge documents. Use when working with PDF files or when the user mentions PDFs, forms, or document extraction

Never fires

Helps with documents

Chapter 6 · “It is the highest-leverage sentence in the folder.”

The difference between the diagram and production

Three caveats

Triggering is probabilistic

Test on your host, both ways: tasks that should fire it, tasks that should not

The host must be capable

Navigate files, follow references, run code; smaller models wander

The menu is not free

Fifty skills: several thousand tokens before any fires

Quick run (3 min): open the skill token budget with 10 skills, then change it to 50. Write down the menu, one task’s total, and the reduction, for both.

Chapter 6 · “Curate the library like you curate the toolset: install what earns its line.” · fifty-skill figure: one implementation’s

Skills versus tools versus protocols

Three boxes on one baseline: tools, what it can do; protocols, how it connects; skills, in accent, how we do it.
Figure from Chapter 6

Chapter 6, “Skills versus Tools versus Protocols” · three layers, three questions

The diagnostic, once you have the triad

“What kind of thing is missing?”

The agent…The gap isThe fix
cannot reach the system at allconnectivityinstall or implement a server
reaches it, but has no safe, task-shaped actiona toolcut one (week 3)
has reach and actions, works like a talented strangerexpertisewrite the skill

Your turn: (a) it opens tickets but ignores your triage rules; (b) it has never heard of the new incident tracker; (c) it can read invoices but has no way to issue a refund

Chapter 6 · “the loop reasons, the runtime executes, the protocol connects, and the skills guide”

Why protocols exist · the M×N problem

A multiplication becomes an addition

Before: three agents each wired by hand to five systems (tickets, CRM, wiki, code, data), M times N adapters. After: the same agents and systems each connected once to one shared contract in the middle, M plus N implementations.
Figure from Chapter 6 · three agents, five systems

30 seconds: 4 agents and 12 systems. How many adapters without a standard, how many implementations with one, and what does a 13th system cost in each world?

Two kinds of protocol · what stands at the far end of the wire?

Agent ↔ tools and data

The far end is a capability

A server advertises what it offers; a client in the agent asks “what do you offer?” and calls it

Labeled example: the Model Context Protocol

Agent ↔ agent

The far end reasons too

A capability advertisement, a task with its own lifecycle, artifacts back from a black box

Labeled example: Agent2Agent

“Server” and “client” name roles, not places: a server may run on your laptop or be a stranger’s hosted service

Chapter 6, “Protocols and Interoperability” · each example one instance of a category that will keep evolving

Protocol adoption is an engineering decision, not a sacrament

Three costs, and a fourth unlike them

  1. Young and moving: specs revise, authorization matures unevenly; version your integrations
  2. Drift: the far end changes without asking; degrade gracefully when a tool vanishes
  3. Over-standardization: a lowest common denominator plus indirection; one tight integration you control is simpler as a direct call

And the fourth: “every socket is a door.”

Chapter 6 · protocols earn their ceremony with many connections and third-party reuse

Inside the folder · the format is the easy half

Five shapes for a skill’s contents

  • Tool wrapper: conventions for a system; start here
  • Generator: template fixes structure, style guide the bar
  • Reviewer: what in a checklist, how in the body
  • Inversion and pipeline: gates that stop the agent
Five skill patterns with their analogies: tool wrapper, a cheat sheet; generator, a form; reviewer, a rubric; inversion, an interview; and pipeline, in accent, a recipe with sign-offs.
Figure from Chapter 6 · a folk taxonomy, not a standard

Chapter 6, “Skill Design Patterns and Composition” · “The checklist drove the behavior, not the agent’s pre-training.” (source quoted there)

Where good skills come from

From failures, incrementally, with measurement

  • Start from observed gaps, not the encyclopedia you imagine needing
  • Keep each skill narrow: one job done reliably
  • Measure: the same tasks with and without the skill; the pass-rate delta

Skills that write skills

Curated skills can substantially improve success; self-generated ones may degrade it.

“let the agent draft the skill, and let something that is not the agent decide it is good”

Chapter 6 · survey finding (Jiang et al., 2026) as quoted there · a skill is a dependency that ships instructions

Part 2 · Chapter 7 (full book)

Managing the context window

Context engineering versus prompt engineering

One window, four authors

  • Scope: a prompt is one slice
  • Dynamic: assembled by code on every call
  • Never concludes: “A prompt is edited. A context is curated, and curation is a loop.”
One context window as a stack of slices with four authors: you write the standing instructions and the output shape, the user writes the request, the model writes the conversation so far, and the harness inserts memory, retrieved documents, tool definitions and tool results.
Figure from Chapter 7

Predict before the next slide

Ask a question with the one document it needs. Then ask it again, with the same document buried in two hundred pages of related, irrelevant material.

Nothing is wrong, everything fits. Same quality of answer?

Chapter 7, “A Scarce, Attention-Limited Resource”

The measured answer: no

Context rot and the attention budget

The attention budget as a fixed pool of lamplight on an ever-longer row of tokens: those in the circle are seen, those outside are present yet barely seen, and the desk keeps growing while the circle cannot.
Figure from Chapter 7

Chapter 7 · Hong, Troynikov and Huber (2025) · second quotation: a vendor essay quoted there

How much of the window can you actually use?

The soft limit and the dumb zone

Soft limit vs hard limit

“The advertised window size is a fact about storage: how much fits. It promises nothing about attention.”

Retrieval vs reasoning

Finding a needle is the easy case; reasoning over a pile degrades sooner

Chapter 7 · “Treat the number as an illustration; treat the practice as sound” · “The emptier the desk, the sharper the model.”

Twenty minutes into a good run · name each failure

  1. It re-runs a test it has already run three times
  2. It searches the docs for an answer sitting forty lines up the transcript
  3. It builds its next three actions on a “fact” it invented an hour ago

The weights did not change. Only the desk did.

Chapter 7, “How Context Fails” · the scene opens the section

Five ways a context fails: a bedside chart

  • Poisoning: a later correction doesn’t remove it
  • Distraction: the log drowns the training
  • Confusion: 46 tools failed, the 19 relevant passed
  • Clash: sharded requests, ~39% worse
  • Fighting the weights: survives a clean desk
A bedside chart mapping symptoms to modes: repeats its own history, distraction; calls pointless tools, confusion; cites an invented fact, poisoning; clings to an early answer, clash; and, set apart in accent, stubborn on a clean desk, fighting the weights.
Figure from Chapter 7

Chapter 7 · names: Breunig (2025) · numbers from studies cited there, illustrative · the fifth mode has less measurement yet

Every remedy is one of four verbs, or a combination

Write, select, compress, isolate

  • Write: the filing cabinet and the sticky note
  • Select: the one folder today needs
  • Compress: the one-page summary
  • Isolate: a colleague’s memo, not their drafts
The four operations around the context window: write parks material in an external store of files, notes, memory and corpus; select brings in only what this step needs; compress keeps the same facts in fewer tokens by compacting, pruning and trimming; isolate delegates a messy subtask to a sub-agent's own window and takes back a distilled summary.
Figure from Chapter 7

Chapter 7 · grouping from Lance Martin (2025) · “I have yet to meet a context remedy that is not some combination of these.”

The four operations at the grain you will build

OperationFormsBuysCosts
Writescratchpad, progress file (offloading); memory storessurvival past compaction or resetextra reads and writes; a store to manage
Selectretrieval; tool loadout; just-in-time identifiersonly this step’s slicelatency; an agent may wander
Compresscompaction (summarization), pruning, tool-result trimmingsame facts, fewer tokenslossy, silently
Isolatea subagent in quarantinethe mess stays sealedtokens multiply, several-fold by common report

Chapter 7 · italics: the six-tactic vocabulary (Breunig, 2025) · weeks 5 and 6 go deeper

A hypothetical coding agent, a multi-hour migration

All four in one run

small rules file at launch · select→search, open on demand · select→progress file · write→drop applied file contents · compress→compact near the soft limit · compress→dependency study to a subagent · isolate

“Most tasks need only the two cheap moves—trim the tool results, write the plan to a file.”

Chapter 7 · the over-curation caution: “The trade is always recall against focus; there is no universal setting”

In class · teams of three · 20 minutes

Context rot, then budget a desk

  1. Watch the explainer: Context rot and the four operations (about 4 min)
  2. Open the budget planner with Chapter 2’s desk and growth of 1,000 tokens per step
  3. Window 200,000, then 100,000 (hypothetical): utilization, steps to the 40% ceiling, steps to the hard limit
  4. One operation per component, with a concrete move
  5. One sentence: what did doubling the window buy, and what not?
instructions 500history 8,000two documents 40,000tool result 3,000

Chapter 2’s sketch: “made-up but realistic numbers” · 40% ceiling illustrative · after class, with Lab 3: your revised desk and what it could lose

Before next week

Lab 3 and reading

Lab 3 · extend Lab 2

  • A skill folder: name + description, a lean body, one reference, one script
  • Loaded in levels; the script run, never read
  • Trim tool results once acted on
  • A progress file the agent writes
  • Scripted test: 30 steps, history stops growing

Reading for week 5

This week’s reading: Ch. 6 · Ch. 7 (full book) · no paid API needed for the lab

Recap

Five things to keep

Engineering AI Agents · Week 4

Is everything in this context earning its keep?

Slides from the teaching kit of AI Agents, Engineered by Enrique Gutiérrez, CC BY 4.0 · aiagentsengineered.com/teach/

Reuse, adapt and translate with attribution · creativecommons.org/licenses/by/4.0/