The easiest way to make an AI agent feel more capable is to give it more context. Add the full ticket history. Add the policy manual. Add the tool logs. Add the last five attempts. Add a scratchpad. Add memory. Add the transcript from the approval conversation. Then add a bigger model because the prompt no longer fits.

For a demo, that feels like progress. The agent sees more, so it should understand more. In production, it often creates a quieter failure mode: the agent becomes a junk drawer with a reasoning loop attached.

Longer context windows are useful. Better memory is useful. Retrieval is useful. None of them answer the operational question that matters most: what is this agent allowed to carry forward right now, and when should that context be compressed, revalidated, or thrown away?

That is why production agents need context garbage collection.

I do not mean garbage collection as a clever metaphor for token trimming. I mean a runtime discipline for managing working context as state. Every long-running agent accumulates state: user instructions, retrieved documents, intermediate observations, tool results, approvals, errors, summaries, and assumptions. If that state is not governed, it becomes a blend of evidence, stale facts, prompt-injection surface, privacy exposure, and cost.

The industry is already moving in this direction, even if it does not always use this phrase. Anthropic's guidance on building effective agents emphasizes simple, composable workflows and clear patterns such as chaining, routing, parallelization, orchestrator-workers, and evaluator-optimizer loops. That guidance is a useful corrective to the idea that every hard problem should become one giant autonomous prompt. The more practical pattern is to break work into steps with explicit handoffs.

OpenAI's Agents SDK points in a similar direction from the framework side. Its public README describes a lightweight framework for multi-agent workflows, with agents, handoffs, guardrails, and tracing treated as first-class ideas. OpenTelemetry's GenAI semantic-convention work shows the observability ecosystem moving toward portable telemetry for AI operations. MCP's security best-practice guidance, meanwhile, reinforces that tools and resources sit behind trust boundaries, not inside a magical safe zone.

Put those together and the lesson is straightforward: context should be part of the control plane. Not just the prompt.

A useful context policy starts with admission. Before a document, transcript, tool output, or memory enters the live working set, the system should know why it is there. Was it retrieved because it matched the user's request? Was it carried over from a prior step? Was it supplied by the user? Was it produced by a tool? Was it approved by a human? Those origins matter because they determine how much the agent should trust the material and where it can be used.

Next comes scope. Not every piece of context should be visible to every subtask. A support agent may need a customer's issue history to draft a response, but a generic summarizer does not need billing details. A coding agent may need test output, but not the user's private notes. A workflow planner may need the goal and constraints, while an executor should receive only the specific action contract it is supposed to perform. Scoping context is one of the simplest ways to reduce accidental leakage and prompt-injection blast radius.

Then comes compression. Agents often need continuity without needing the full raw record. A twenty-message debugging exchange can become a short state summary plus links to the original evidence. A retrieved policy can become the specific clause that affected the decision, with a source handle attached. A failed tool call can become an error receipt: what was attempted, what failed, what retry policy applied, and what remains unresolved.

Compression is dangerous when it hides evidence. The point is not to replace facts with vibes. The point is to reduce the working set while preserving a path back to the source. A good summary says, in effect: here is the minimum useful state, here is what was dropped, and here is where the raw material lives if the agent or auditor needs it.

Retention is the next decision. Some context should stay for the whole run: the user goal, safety constraints, explicit approvals, and final decision receipts. Some context should expire quickly: search snippets, browser page observations, vendor API responses, and intermediate model guesses. Some context should never persist beyond the step that needed it. Treating all of those the same is how agents wake up tomorrow acting on yesterday's assumptions.

Expiration matters because agent work often spans time. A manager approves a draft in the morning. A vendor API fails at noon. A customer updates the ticket in the afternoon. If the agent resumes from a stale summary without rechecking the live system, it can be confidently wrong in a way that looks procedural. A context garbage collector should mark which facts need revalidation before action.

The fifth decision is disposal. Teams are often uncomfortable with deliberate forgetting because memory feels like intelligence. But production systems forget things all the time for good reasons: privacy, security, cost, relevance, and correctness. An agent that keeps every retrieved page, every user aside, every failed attempt, and every obsolete instruction is not more accountable. It is harder to audit.

Disposal should be explicit. The run record should be able to say: this raw page was summarized and dropped from the prompt; this user-provided secret-like string was not retained; this stale tool result expired before the final action; this retrieved document was ignored because a newer source superseded it. That is a stronger operational posture than hoping the model sorts the mess out internally.

Finally, context decisions need telemetry. If a team cannot see what entered the working set, what was summarized, what expired, and what affected the final answer, it cannot improve the agent with confidence. A final chat transcript is not enough. The trace should show the lifecycle of important context the same way it shows tool calls, model latency, errors, and handoffs.

This can start small. Add a context ledger to each agent run. For every important item, record source, reason for admission, scope, freshness, retention rule, and evidence handle. Add TTLs for volatile facts. Require summary receipts when raw material is compressed. Keep approval artifacts separate from ordinary conversation. Treat untrusted web content and tool output as data, not instructions. Emit telemetry when context is admitted, compacted, expired, or reused.

The payoff is practical. Support agents stop carrying stale customer state. Coding agents stop mixing old test failures with new ones. Compliance agents can show which rule text was actually used. Multi-agent systems can hand off the right state without handing off everything. Security reviews become less mystical because the risky material has a lifecycle.

Bigger prompts will keep getting cheaper and more impressive. Use them. But do not confuse capacity with governance. The best production agent memory is not the largest one. It is the one your team can explain, constrain, update, and safely forget.

Build AI Systems That Survive Contact With Real Work

We help teams turn AI research into practical automations, agent workflows, and operational systems that can be evaluated and improved.

Get the Field Guide — $10 →