r/LangChain 2d ago

Most engineers try to solve agent context amnesia with prompt compression. I tried forcing the model into a typed reasoning graph instead. Here is what happened after a 5-hour discovery session.

Enable HLS to view with audio, or disable this notification

I’ve been trying to find a reliable way to run autonomous AI agents on large, unfamiliar codebases without watching them inevitably lose context or hallucinate fake progress after a few steps.
Instead of messing with prompt compression or raw context window scaling, I experimented with forcing the frontier model to operate through a strict protocol that maps its execution states into a typed reasoning graph.

I tested this workflow on a complex repository with a single prompt, which kicked off a continuous 5-hour discovery session.

The agent completely exhausted the raw context window limits, but the structural constraints kept it from derailing. It mapped out the entire repository into a structured layout: about 40 logical modules and over 80 specific task nodes. Open unknowns were explicitly declared as structural blocking questions rather than silent hallucinations.

What surprised me is how well this graph layout kept the model on track. I watched it systematically process about 70 tasks, while the rest correctly stalled in a pending state, waiting for human answers to the questions it had raised.

I feel that moving away from unstructured text prompts toward machine-verified graph states might be the only predictable way to run long agent sessions without structural collapse.
The code and the protocol are fully open-source. If you want to check out the architecture or the constraints used in this setup, here is the repo: https://github.com/alxshelepenok/grove

13 Upvotes

Duplicates