How Long Contexts Fail

How to Fix Your Context

Long context is your friend… when we are talking about summarization and retrieval. For agentic workflow it is often detrimental due to reasons such as:

  1. Context poisoning, where the model hallucinates and messes with its own context. The ripples are powerful and they die slowly;

  2. Context distraction, where the model starts to repeat itself instead of trying new strategies;

  3. Context confusion, which happens when one gives the model too many tools (sometimes 2 is too many);

  4. Context clash, where the model cannot let go of its initial wrong assumptions. And it assumes something each turn of the conversation, be it a tool call, file read, or user’s request.

Those problems become especially emphasized when the context starts getting too long.

Fortunately, there are some methods to minimize the impact of those issues:

  1. RAG. Rumors about its death are greatly exaggerated. It is still a very powerful tool to control the context length;

  2. Tool loadout. Give the model only the tools it needs. A task changed? Select another set of tools. Or let a RAG system or another LLM do that.

  3. Context quarantine. You can delegate, then why the agent shouldn’t be able to? Split tasks into subtasks with their own contexts, consume the results.

  4. Context pruning. Trim the context mercilessly. The model doesn’t need to remember its reasoning traces or tool calls results from 10 turns back. And keeping everything in some structured format lets you efficiently develop strategies for pruning.

  5. Context summarization. When context gets too long, summarize it and throw away. Don’t forget to reinitialize the agent after that. If you have files with instructions, add them to the resulting summary.

  6. Context offloading. Give the model a scratchpad. Or, better yet, several. Let it write down, forget, consult, repeat.

All of that will make the agent system not only more reliable, but also cheaper.