Keep the Agent in the Smart Zone
An agent does its best work while its context is mostly empty. Keep the always-on prompt small, load detail on demand, and hand off before quality drops.
Context is the plumbing of an agent: what flows into it on every turn, and what backs up when nobody drains it. Most of the agent failures I debug turn out to be plumbing.
The model I work with has a large context window. That number is misleading. A coding session does its best work while the window is mostly empty, and it gets measurably worse as the window fills. The point where returns start to drop sits somewhere around 40% of the window, or around 100k tokens, and a bigger window doesn't move it much. A bigger window helps the model find things. It does less for reasoning about code.
The benchmarks agree. On long-context tests built so the answer can't be found by matching words, accuracy falls from about 90% to about 50% by 32,000 tokens. That's a small fraction of what any current model can hold.
So I treat context as a budget, not a capacity. The question isn't how much fits. It's how much the agent can carry and still think clearly.
The always-on part has to be tiny
Some context loads on every turn whether the agent needs it or not: the system prompt, the rules file, the skill, the tool definitions, whatever a startup hook prints. That's the part that does the most damage, because it's paid for on every step and it pushes everything else toward the line.
My worst offender was my own. Po is one of the bots I run. It reads a channel of user signals every five minutes, dedups them into themes and files issues. Its skill file was 4,937 lines and about 438 KB, and the whole file entered context on every pass. At four characters per token, that's roughly 110,000 tokens before Po read a single signal. It started every pass past the line.
The file grew the way most of these do: by incident. Every time Po made a mistake, I or a session added a paragraph explaining what went wrong and what to do instead. The word "never" appears 310 times. One section, about verifying one kind of signal, runs 4,485 lines, which is 91% of the file. Everything else Po does fits in about 450 lines.
Each paragraph is a real lesson. Together they cost the model a full read of every past lesson on every pass, including the passes that only bump a counter on an existing issue.
Send an index, load the step
The fix is the same shape every time. The always-on part becomes a short loop with a table of contents. The detail moves into files the agent reads when it reaches the step that needs them.
For Po, the plan is:
- A skill file of about 300 lines. The loop, a table of lanes, and an index of rules by ID.
- One reference file per lane, read only when a signal lands in that lane.
- Scripts for the mechanical checks, each with a test, run instead of read.
- One small file per rule, with an ID and the inputs that prove it.
That last part matters more than it looks. A lot of the prose in Po's skill describes a procedure: page through all the issues, read the weight from the issue body, add one, write it back. The model was re-deriving that procedure from a paragraph on every pass, and sometimes getting it wrong. As code, it's a script that reads the body, adds one and prints the number, plus a test that replays the incident that taught me the rule. The line left in the skill is one sentence that names the script.
Code is cheaper than prose in two ways. It doesn't sit in context until it's needed, and it gives the same answer every time.
This is how skills are meant to work anyway. The model sees the name and description of each skill up front. It reads the body when it decides the skill applies, and it opens the other files in the folder only when a step calls for them. That's what lets dozens of skills coexist in one agent. A skill that puts everything in the body throws that away.
The same goes for tools. Every tool definition is always-on context. Ten MCP servers with forty tools each can put a session in the dumb zone before you've typed anything.
Hand off before the pipes back up
The always-on part is the floor. Everything a session does adds to it: files read, test output, the diff it wrote, the three approaches it tried before the fourth one worked.
Length isn't the only problem. The history itself steers the model. A thread full of mistakes and corrections tells the model that the likely next move is another mistake. By turn twenty, a lot of what's in the window is dead code from abandoned approaches and tests that were "fixed" by making them pass. Incorrect information is the most harmful thing in a context window, then missing information, then noise. A long, corrected session has all three.
So I'd rather restart than resteer. The rule I'm moving my sessions to: after the second correction on the same step, or once the session passes its budget, it writes a handoff and stops. A fresh session picks up from the handoff with a clean window.
The handoff is where this lives or dies. When I looked at mine, I had ten on disk, from 36 to 106 lines each. None of them pointed at a file and line. None stated what the session believed was true. Each one invented its own headings. A fresh session reading one had to re-research most of what the last session knew.
So the handoff gets a fixed shape:
- Task. The task it belongs to. It expires when the task closes.
- Done when. The acceptance check, copied from the task.
- Hypothesis. What the session believes right now, and the command or observation that would prove it wrong.
- Files. One line each:
path:lineand why it matters. - Ruled out. What was tried and what happened, so the next session doesn't try it again.
- State. Branch, open pull requests, uncommitted files, background jobs that die with the session.
- Next step. One action.
That's the compression step done on purpose. The session squeezes what it learned into a page, I can read the page, and the next session starts from it instead of from a transcript. Handoffs also expire with their task. A note about finished work that keeps getting served to new sessions is how stale context gets in.
Subagents are for context, not for roles
The other drain is the subagent. I used to set up teams of them with job titles: a researcher, an architect, a coder, a tester, a reviewer. That copies an org chart into a context problem. Every handoff between them loses detail, and none of them has the whole picture.
What subagents are good for is reading. A subagent can search fifty files in its own window and come back with three paths, the line numbers and a two-sentence answer. In one demo I watched, an exploring subagent spent about 94k tokens while the parent session's count barely moved. The parent kept its window for planning and editing, where the whole picture matters.
So my sessions search with subagents and decide in the parent.
Retrieval decides what comes through the tap
Everything above is about what's always in the pipes. Retrieval is the tap: what the agent pulls in when a step needs it. A small window only helps if what comes through the tap is the right few things.
Plain vector search returns the chunks that sound most like the question. That's often fine. It falls short when the answer depends on how things connect: which service calls this one, who owns the process that broke, what else changed in the same release. Similar text doesn't tell you any of that.
A knowledge graph on the retrieval path does. Vector search finds a few entry points, close to a primary-key lookup. The system walks the graph out from them to gather related context, ranks what it found by graph structure (PageRank works), and passes only the top few to the model. You get more relevant context in fewer tokens, and the graph is something a person can inspect when an answer goes wrong, which a vector index isn't.
Graphite Atlas, the knowledge graph I build, exposes those steps as separate tools: semantic search to find entry points, a neighborhood lookup and a traversal to walk out, and a ranking tool to keep the important nodes. An agent can do GraphRAG with them by hand today. The hard part is never the query. It's building the graph, especially from unstructured text, and keeping it current. A stale graph is a stale doc with better structure.
Docs drift too
One more source of bad water: old documents. A plan or a spec that was right when the work shipped gets found a month later, and the agent trusts it. Names have changed and files have moved, and the doc says otherwise with full confidence. Of all the sources of context, written docs drift furthest from the code.
When a plan is done, I close it, so the agent can see it's history. When an agent needs to understand how something works, I'd rather it read the code than a doc about the code. The wider version of this problem is in Context Rot.
How you know it's working
- The count is visible. Every session shows its token count in the status line, so both of us can see when it's near the line.
- The always-on part has a budget. A skill file over a few hundred lines fails a check. For Po the target is from about 110k tokens per pass to under 10k, with its outcomes holding steady on the same week of signals.
- Corrections lead to restarts. A session that's been corrected twice on one step stops and hands off. It doesn't push on.
- Handoffs are checkable. Every handoff names a task and at least one
path:line. One that doesn't is flagged as loose notes. - The prose shrinks. Every rule that becomes a script or a test is deleted from the skill. The always-on part should get shorter over time, not longer.
None of this is clever. It's plumbing. But an agent with clean pipes, a short prompt and a fresh window will out-think the same model dragging 110,000 tokens of old lessons into every step.