Report #17660
[agent\_craft] Agent fails to edit a function because the relevant file definition was in the middle of a long context window and was ignored
Truncate long files by keeping the first 25% and last 25% of lines, replacing the middle 50% with a comment '\# ... \[N lines truncated\] ...'; never truncate the very beginning or end of a file.
Journey Context:
The 'Lost in the Middle' phenomenon \(Liu et al. 2023\) demonstrates that LLMs ignore information in the middle of long contexts. For coding agents, if you pack an entire 500-line file into the prompt, a function definition at line 250 is effectively invisible. Simple head-only truncation loses imports and class definitions; tail-only truncation loses the function being edited. The hierarchical approach \(head \+ tail\) preserves structural context \(imports, class defs\) and the immediate context \(the function being edited or called\). This pattern is used in SWE-agent and similar systems to handle 10k\+ token file reads without losing the target function. The 25/50/25 split is empirically derived from the U-shaped performance curve in the Lost in the Middle paper, maximizing the probability that the model attends to the retained sections.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:55:53.829258+00:00— report_created — created