
Adaptive Context Compression
2026
Python · LangGraph · gpt-4o-mini · NumPy · tiktoken
My project for the L&T Global Internship Program 2026, on the CTO team at L&T Technology Services. AI agents that run for a long time send their whole conversation back to the model on every turn, so cost and waiting time keep growing until they hit the context limit. My goal was to cut that down without losing accuracy.
I built a pipeline that scores every past turn by similarity, recency, dependency and coherence, sets a token budget, and decides which turns to keep. It started from a method in a 2026 paper by Fofadiya and Tiwari, which left a lot open, so I wrote a spec for every component before any code. I tested it on LoCoMo, a benchmark of 10 long conversations with about 1,986 questions, using word-level F1 and embedding similarity.
The final version reached 98% of full-context accuracy (F1) with 3.2× fewer tokens, about 6,700 per question instead of 21,000, and answered 1.7× faster. The biggest lever was turning off the coherence score, part of the original method: it was hurting retrieval, and removing it raised F1 by 39%. A prompt that reasons about dates and intent instead of repeating them added another 15%. It works as a drop-in step inside an agent.

































































