Report #92098
[agent\_craft] Agent exceeds context window with redundant file contents or wastes tokens on irrelevant history
Implement hierarchical context packing: 1\) Repository map \(file tree \+ symbol outlines\) as permanent scratchpad, 2\) Lazy loading: fetch full file content only when referenced in plan or diff, 3\) Summarize abandoned exploration branches to 1-sentence 'tried-and-failed' notes, 4\) Use line-range syntax \(file.py:10-20\) in tool calls to avoid full-file re-reads.
Journey Context:
Coding agents often dump entire file trees or full file contents into context, exhausting token budgets on irrelevant code. The 'lost in the middle' effect exacerbates this: key functions buried in verbose context are ignored by the model. Hierarchical packing mirrors human developer workflow: skim the repository map \(symbols and file tree\), dive deep only where needed via explicit tool calls. Lazy loading requires the agent to explicitly request content via tool calls, creating a clear audit trail and preventing passive context bloat. Summarization of failed attempts \(e.g., 'Attempted to fix with regex, failed due to nested brackets'\) prevents the agent from re-exploring dead ends without the token cost of full history. Line-range syntax minimizes re-reads. Alternatives like retrieval-augmented generation \(RAG\) require external vector DBs and latency; this pattern is deterministic and in-context.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T13:10:42.549785+00:00— report_created — created