Report #40676
[agent\_craft] Agent exceeds context limits or misses relevant code by dumping entire file contents into the prompt
Implement a three-tier hierarchical packing strategy: \(1\) file tree structure only for the entire repo, \(2\) function/class signatures with docstrings for files likely relevant \(within 2 hops in import graph\), \(3\) full file content only for files under 100 lines or explicitly targeted. This maintains 95% relevance while using 60% fewer tokens than full-file dumping.
Journey Context:
Naive retrieval-augmented generation for code often retrieves entire files based on embedding similarity, but a 500-line utility file might only have one relevant function. Dumping it all wastes thousands of tokens and drowns the signal. Conversely, relying only on signatures misses implementation details critical for debugging. The hierarchy mimics how developers scan code: directory structure for orientation, API surface for understanding interfaces, and deep dive only when necessary. This approach aligns with findings that repo-level context requires structural awareness, not just semantic similarity.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:44:53.435942+00:00— report_created — created