# Chapter 9 — Sources and adaptations

## Central definitions and supporting figures

[Anthropic, Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents), 2025-09-29, supplies the central definitions of context and context engineering. The chapter follows the course's chapter opening: the limits of the model's input, the settings where they matter, the definition, a running example, and then selection, structuring, compression, and the repeated input loop.

Two original figures are reproduced unchanged, with student-visible attribution and full-size links:

- Part 3, collapsed “Going further” box, “Calibrating the system prompt”: `figures/context/anthropic-prompt-altitude.png`. [Original image](https://www-cdn.anthropic.com/images/4zrzovbb/website/0442fe138158e84ffce92bed1624dd09f37ac46f-2292x1288.png). It supports a short note on how detailed instructions should be; prompt specificity is not a main section of the chapter.
- §1.4, “Prompt engineering vs. context engineering”: `figures/context/anthropic-prompt-vs-context.png`. [Original image](https://www-cdn.anthropic.com/images/4zrzovbb/website/faa261102e46c7f090a2402a49000ffae18c5dd6-2292x1290.png). It contrasts a single prompt with an agent that curates candidate information into the window at every call.

[LangChain, Context Engineering](https://www.langchain.com/blog/context-engineering-for-agents), 2025-07-02, supports the distinction between summarizing and trimming, selection of information for model calls, and inspection and evaluation of context policies. The chapter's selection/structuring/compression grouping is a teaching organization of basic operations, not a claim that all sources use the same taxonomy.

## Research

- Liu et al., [Lost in the Middle: How Language Models Use Long Contexts](https://arxiv.org/abs/2307.03172), TACL 2024. §1.2 reproduces Figure 1 from the locally held arXiv v3 PDF (2023-11-20), cropped to the plot. Labels and data are unchanged. The model, document count, approximate input length, axes, and experimental manipulation are stated beside the figure. The text also notes that the 20-document input nearly fills the model's 4K window and that longer-window models showed the same pattern. It is a historical reported result, not a new course experiment or a universal placement rule.
- Jiang et al., [LLMLingua: Compressing Prompts for Accelerated Inference of Large Language Models](https://aclanthology.org/2023.emnlp-main.825/), EMNLP 2023. Part 4 briefly connects compression to this particular method. Algorithm details, distribution alignment, and experimental trade-offs belong to the paper presentation. The lab does not implement LLMLingua.

## Teaching illustrations

The running example continues the reading-list assistant and toy corpus D1–D4 of Chapter 8: an eight-turn conversation in which turn 1 sets a rule (two sentences, cite the documents) and turn 4 pastes a slide draft whose template line ("Write one paragraph per slide.") looks like an instruction. Its token counts are illustrative, not measured, and no model output is presented as recorded.

Course-authored SVGs, generated by `scripts/build_w10_context_figures.py`:

| File | Section | Purpose |
|---|---|---|
| `token-growth.svg` | 1.2 | Input tokens per call with and without a budget; illustrative T₀ = 2,000, Δ = 1,500, W = 16,000. |
| `stored-vs-sent.svg` | Part 2 | Trimming keeps turns 5–7 and turn 8; turn 1 stays in storage but is not sent. |
| `summary-quality.svg` | Part 4 | A good and a weak summary of turns 1–4; the weak one loses the rule. |
| `context-loop.svg` | 5.1 | Collect, build, call, and store, repeated for every call. |

The policy comparison in 5.2 uses the input selector in `reading-input-demo.html` (styles in `reading-context.html`).

The lab retains its separately identified fictional policy corpus to compare conversation treatment with retrieved evidence held fixed. Its source adaptations and execution scope are described in the notebook and weekly README.

## Lab implementation sources

- [LangGraph Graph API](https://docs.langchain.com/oss/python/langgraph/graph-api).
- [LangGraph persistence](https://docs.langchain.com/oss/python/langgraph/persistence).
- [Message management](https://docs.langchain.com/oss/python/langgraph/add-memory).
- [LangChain Academy, commit fa15bec4a51c541c40c261586b037c9d134977b1](https://github.com/langchain-ai/langchain-academy/tree/fa15bec4a51c541c40c261586b037c9d134977b1). The lab names its source notebooks and adaptations in its opening cells. The source repository's license accompanies the notebook as `ACADEMY-LICENSE`.

## Authoring

The editable lecture source is kept locally as `notes.en.md`; the student publication is `notes.html`. Styles and the input selector are in `reading-context.html` and `reading-input-demo.html`. `scripts/build_reading_chapters.py --weeks 10` renders the lecture. `scripts/build_w10_context_materials.py` generates the lab and the paper-figure crop and is not needed for theory-only edits.
