Part 2: Agents · Chapter 2 of 5
What the agent sees: context, memory and plug-ins
The model only knows what the harness puts in front of it: how the context fills up, what product "memory" really is, how tools plug in, and where agent code should run.
After this chapter you can
- Explain why an agent only knows what its harness puts in front of it
- Say what product memory is, and why it goes stale
- Compare the places agent code can run, from your laptop to an isolated machine
The last chapter showed that an agent is a model asked again and again, with the whole transcript each time. That makes one question decisive: what exactly is in that transcript? The model can’t look anything up on its own. Everything it knows about your task, your files and your past conversations is text that the harness chose to put in front of it.
A desk with limits
The desk has grown fast. Every current Claude model now offers a context window of a million tokensNov 2026, roughly the length of several novels. But a bigger desk doesn’t mean everything on it gets read well. Performance drops as inputs get longer, especially when distracting material is present and when the relevant passage resembles the question less closely; older models also used the middle of a long input worst ("lost in the middle", 2023)Nov 2026. The strengths and limits chapter explains why. For agents the practical lesson is that the context is a budget to spend carefully, not a bin to fill.
Choosing what goes on the desk at each step now has a name, context engineering, and it is most of what separates a good harness from a bad one. When the desk fills up anyway, the harness falls back on compaction: it summarises the conversation so far and starts again from the summary. Try it:
Early on, the user mentions one detail: the customer is still on version 1 of the API. Keep working and watch what happens to it.
Simplified. Real harnesses compact at a set threshold, often by asking the model itself to write the summary. What survives depends on what the summary happens to keep.
Summaries keep the gist and drop the details nobody flagged as important, which is exactly the kind of detail that matters three hours into a task. That’s why good harnesses combine compaction with other tricks: clearing old tool results that are no longer needed, having the agent write key facts to a notes file, and loading files only when they’re needed instead of up front.
What “memory” really is
The model itself remembers nothing between calls. Its weights are frozen. What products call memory is a harness feature: it writes text somewhere, a list of saved facts or an index of old chats, and pastes the relevant parts back into the context later. Since April 2025, ChatGPT's memory references all your past conversations, not just the facts it savedNov 2026.
It works less well than the name suggests. A 2025 benchmark found commercial assistants and long-context models lost about 30% accuracy when they had to remember information across long interactionsNov 2026. Memories also go stale: a fact saved in March may be wrong in November, and the model can’t tell. Retrieval-based search over documents and memory end the same way: as text on the desk, subject to the same limits.
Where experts disagree checked Nov 2026
Should agents rely on ever-larger context windows, or on keeping the context small and focused?
Windows grew from thousands to a million tokens, yet quality still drops as the context fills.
Bigger windows make agents simpler and better
Anthropic and Google, which now ship million-token windows
- A larger window means fewer summaries, so fewer details get lost along the way.
- Whole codebases or document sets fit at once, without a retrieval system that might fetch the wrong part.
- Vendors report large gains on long-context retrieval tests (self-reported).
Sources: claude.com · platform.claude.com
Less, well-chosen context works better
Chroma's context-rot study; the NoLiMa authors; Anthropic's own context-engineering guidance; Letta
- Quality falls as input grows, even on simple tasks, and distracting material makes it worse.
- Independent tests find usable length far below advertised length when the answer isn't a literal match.
- Focused prompts beat full ones on memory tests, and a plain file-based agent matched specialised memory systems.
Sources: trychroma.com · arxiv.org · anthropic.com · letta.com
What would settle it: Independent tests of million-token models on realistic agent work, not needle searches, compared with the same agents using curated context.
How tools and know-how plug in
Agents need tools and data to work with. Instead of every product wiring up every service by hand, a few shared formats have emerged:
- MCP (Model Context Protocol) is a standard plug for tools and data: a mail server, a database or a ticketing system describes its tools once, and any agent that speaks MCP can use them.
- Instruction files such as AGENTS.md are a README for agents: the harness pastes them into the context at the start of a session.
- Skills package know-how. Agent Skills, which Anthropic donated to the same foundation in October 2026, are folders with a SKILL.md file that teach an agent a specific taskNov 2026. The harness loads a skill only when a task calls for it, which keeps the desk clear.
All three are ways of getting text into the context: tool descriptions, instructions, results. That text steers the agent. It’s also why the same model can do very differently in different products. A 2026 study (Han and Sun, ICML) found that picking the best harness gains about as much as picking the best modelNov 2026. A benchmark score belongs to a model and its harness, tools and settings, never to the model alone.
Engineer depthBuilding the context, and choosing the sandbox
The context is assembled fresh for every call, so every design choice in a harness is a choice about tokens.
Keep the prefix stable. Caching only applies to an identical beginning, so put stable content first (system prompt, tool definitions in a fixed order, instruction files) and append everything else. Removing or reordering tools mid-run invalidates the cache; production harnesses mask tools they want to hide instead of deleting them.
Compact deliberately. Clear stale tool results first, the cheapest win. Then summarise, with an instruction to keep decisions, file paths, open problems and failed approaches. Pair it with a notes file the agent maintains and the harness reloads, so critical facts don’t depend on the summary. Watch for loops where a context refills straight after compaction.
Isolate subtasks. A sub-agent with a clean context can read a hundred files and return a one-paragraph answer. It costs more tokens overall but keeps the main context focused.
Treat memory as data with provenance. Record where each memory came from and when. Let users see and delete it, and don’t let untrusted content write to it without a check.
Choose the sandbox by threat, not by habit. OS-level sandboxes (Seatbelt, bubblewrap, Landlock with seccomp) are fine against an agent that makes mistakes on your own machine, provided they cover every tool, including file tools and MCP servers, and the unsandboxed escape hatch is disabled. Containers share the host kernel; treat them as packaging, not a security boundary, for untrusted code. For code from untrusted input or from many users, use gVisor or a microVM per session, ideally on hosts that run nothing else.
The network and the credentials are the real perimeter. Route all traffic through a proxy outside the sandbox with a default-deny allowlist, keep secrets out of the sandbox (inject them at the proxy or use a credential broker), give each agent its own short-lived identity, and log every request. Allowed services are attack surface too: a package cache or internal API the sandbox may reach is where escapes have actually happened. Professional evaluators have been caught out too: in July 2026 the UK AI Security Institute found that agents in one of its own cyber tests, run with open internet access, had taken 19 unsanctioned actions against real people and projects, including an attempt to slip malicious code into an open-source project; it found no resulting harmNov 2026. How fast long contexts degrade. In a 2025 test that hid the answer without reusing the question's words, 11 of 13 models fell below half their short-context score at just 32,000 tokensNov 2026. Anthropic's engineers describe the context as a budget that must be treated as a finite resource with diminishing returnssource.
Where MCP stands. In December 2025 MCP moved to the Linux Foundation's new Agentic AI Foundation, together with OpenAI's AGENTS.md and Block's gooseNov 2026. Its July 2026 revision turned MCP into a stateless request-and-response protocol, much like an ordinary web APINov 2026. Anthropic notes that tool descriptions are loaded into the agent's context and can collectively steer how it uses toolssource.
The isolation numbers. Firecracker, the microVM technology behind AWS Lambda, starts a virtual machine in under 125 milliseconds with less than 5 MB of memory overheadsource. gVisor is the main alternative, and its makers are clear about its limits: gVisor's own documentation says it does not protect against hardware side channelsNov 2026.
Recall. An agent forgot a detail you mentioned at the start of a long session. What is the most likely reason?
Apply it. You start a long agent session with one hard rule, for example a folder that must never be changed. How do you make the rule survive the whole task?
Spot the mistake. Which statement is wrong?
Remember this
- The model only knows what is in its context. A bigger window doesn't mean everything in it is used well.
- Product memory is saved text that gets pasted back in later. It can be stale or wrong, and the model can't tell.
- Tool descriptions, instruction files and skills are all text that steers the agent. Treat them like code from a stranger.
Further reading
- Effective context engineering for AI agentsno background neededAnthropic, 2025 · anthropic.comThe working vocabulary: compaction, notes, sub-agents, just-in-time retrieval.
- Context Engineering for AI Agents: Lessons from Building ManusYichao Ji (Manus), 2025 · manus.imA production team on caching, files as memory and keeping mistakes visible.
- Context Rotno background neededChroma, 2025 · trychroma.comWhy more context can make answers worse.
- MCP specification and changelogModel Context Protocol, 2026 · modelcontextprotocol.ioWhat changed in the stateless redesign.
- Managing the cyber risk of agentic AIno background neededUK NCSC, 2026 · ncsc.gov.ukConcrete official guidance on sandboxes, network and credentials.
- Firecracker: Lightweight Virtualization for Serverless ApplicationsAgache et al. (AWS), 2020 · usenix.orgThe microVM design most agent sandboxes now build on.
Chapter complete
Spotted a mistake? Report it on GitHub. Every fix is listed in the monthly field notes.