Skip to content

The Deska blog

Managing Context: What to Keep, Drop and Summarize

Master context window management in agent engineering. Learn when to keep, drop, or summarize data to optimize LLM performance and token usage.

10 min read

Effective context window management is the cornerstone of building reliable AI systems, especially when dealing with complex agent engineering tasks that involve thousands of lines of code. As Large Language Models (LLMs) evolve, the temptation is to flood them with every available byte of data. However, performance often degrades as the prompt grows, leading to the "lost in the middle" phenomenon where models ignore crucial information buried in long contexts. Strategic management involves a conscious decision process to keep essential logic, drop redundant noise, and summarize historical interactions to maintain a high signal to noise ratio.

The Limits of Infinite Context

While modern models boast context windows reaching millions of tokens, developers must distinguish between capacity and capability. Just because a model can ingest a massive file does not mean it will process every line with equal attention. Latency increases linearly or even quadratically with context size, and API costs scale alongside it.

In agent engineering, the context window serves as the short term memory of your assistant. If the memory is cluttered with irrelevant log files or build artifacts, the agent is more likely to hallucinate or miss the specific function definition it needs to solve a bug.

The Signal to Noise Ratio

Every token added to the prompt should earn its place. High signal information includes:

  • Explicit error messages and stack traces.
  • Function signatures and interface definitions.
  • Current cursor position and recently modified files.
  • The specific goal or task provided by the user.

Low signal information that should typically be dropped includes:

  • Large binary files or images not relevant to the task.
  • Repetitive boilerplate code.
  • Extensive library internals that are not being modified.

Strategies for Context Selection

When building agents, you generally follow one of three patterns to handle data that exceeds the immediate window.

Selective Inclusion (Keep)

This is the most direct approach. You provide the model with the exact files it asks for. In sophisticated environments, this is often powered by a local-first index of the codebase. By keeping only the relevant modules, you ensure the model has high precision. For example, if an agent is debugging a React component, it needs that component and its direct imports, but not the entire node_modules folder.

Aggressive Pruning (Drop)

Pruning is the act of removing data that was previously in the context but is no longer relevant. In long running agent threads, earlier turns of the conversation may lose relevance. If a developer moves from fixing a CSS layout to optimizing a database query, the CSS rules should be dropped from the active window to make room for schema definitions.

Intelligent Distillation (Summarize)

Summarization is a middle ground. Instead of keeping every raw terminal output, an agent can summarize the result of a failed build. This preserves the "intent" and "outcome" without consuming thousands of tokens for repetitive compiler warnings.

Context Management in the Workspace

The physical layout of your development environment influences how you manage context. In traditional IDEs, context is often hidden behind tabs. A developer might have twenty files open, but the AI agent only "sees" the one currently active.

Deska takes a different approach by using an infinite canvas where multiple panels can be active simultaneously. This visual hierarchy translates into how Ask Deska and other coding agents interact with your work.

StrategyWhen to UseProsCons
Full FileSmall scriptsPerfect accuracyHigh token cost
RAGLarge reposScalableMay miss deep logic
SummarizationLong historySaves spaceRisk of losing detail
Manual PinningCritical contextUser controlledRequires effort

Tools for Agent Engineering

Several tools handle context window management differently. CLI tools like Claude Code or OpenCode often use a "search and retrieve" loop. They search the file system, read a few files, and then decide what to do next. This is effective but can feel opaque to the developer.

Other tools integrate directly into the editor. Deska allows you to run terminals and agents side by side. Because it is a free desktop app, it can access your local files directly without exposing your code to a third party cloud storage. This local access is vital for context management because it allows for rapid indexing and retrieval without network latency.

Using Ask Deska for Context Control

The Ask Deska assistant can drive the workspace by opening panels or checking sessions. This provides a unique way to manage context: you can visually organize your workspace, and the agent can use that organization to prioritize what it reads. If you place a notes panel next to a code editor, the agent understands the relationship between your requirements and the implementation.

Security and Privacy in Context

Managing context is not just about performance; it is also about security. Sending entire codebases to a managed inference provider can be a compliance risk for many companies.

By using a BYOK (Bring Your Own Key) model or local-first tools, developers can maintain tighter control over what data leaves their machine. When you summarize a file locally before sending the summary to an LLM, you are effectively performing a form of data masking. You keep the sensitive implementation details on your machine and only share the high level logic needed for the AI to assist you.

Best Practices for Developers

To optimize your workflow with AI agents, consider these habits:

  • Use clear, descriptive naming conventions. This helps the agent "guess" context even when it hasn't read the whole file.
  • Break large files into smaller, modular components. Smaller files are easier for agents to ingest and modify without hitting token limits.
  • Periodically clear your agent history. If an agent starts getting confused, it is often because the agent threads have become too long and contradictory.
  • Utilize the mobile app for monitoring. You can check the status of long running agent tasks and intervene if you see the context drifting away from the goal.

FAQ

How to increase context window for agents?

Increasing the window size is usually a matter of switching to a different model, but a better approach is often improving your retrieval strategy. Instead of a larger window, use RAG or vector embeddings to find the most relevant snippets so you stay within the model's high performance zone.

What is the best way to summarize code for LLMs?

The best way is to generate "skeleton" files. Remove the implementation bodies of functions and keep only the signatures and docstrings. This allows the model to understand the API surface area of your project without wasting tokens on the actual logic.

Why does my AI agent forget previous instructions?

This usually happens when the conversation exceeds the context window and the oldest messages are "pushed out" to make room for new ones. To fix this, you should manually pin important instructions or use a tool that supports persistent system prompts that never leave the window.

Experience Infinite Context Management

Effective engineering requires a balance between what the human sees and what the machine processes. By using an expansive workspace, you can better organize the data that fuels your AI tools.

Deska provides the infrastructure to run multiple agents like Claude Code and OpenCode side by side, giving you a bird's eye view of your entire development process. You can download the app for Mac, Windows, and Linux to start building with a more organized approach to context.

Download Deska

Managing Context: What to Keep, Drop and Summarize | Deska