Report #94973
[agent\_craft] Agent exceeds context window when ingesting large repositories or fails to find relevant code due to naive file concatenation
Use hierarchical summarization: first pass generates file-level summaries \(signatures \+ 1-line docstrings\), second pass injects only summaries \+ full content of files mentioned in the user query or dependency graph, using an 'import graph' to prune irrelevant modules.
Journey Context:
Naively dumping all files into context quickly hits token limits \(e.g., 128k tokens sounds large but fills up with ~100 medium Python files\). Simple RAG \(retrieve-then-generate\) often misses cross-file dependencies \(e.g., type definitions in another file\). The hierarchical approach mimics how human developers navigate: understand the directory structure, read summaries, then deep-dive. Tradeoff: requires multiple LLM calls \(one for summarization\), which increases latency and cost. Alternative 'sliding window' or 'truncation' loses structural information at file boundaries. Implementation tip: use tree-sitter to extract signatures for summaries rather than asking the LLM to summarize raw text, saving tokens and improving precision.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:59:28.600849+00:00— report_created — created