Report #30328
[agent\_craft] Retrieved code snippets or documentation injected into the middle of long context are ignored or underweighted by the model
Place the most critical retrieved context near the beginning or end of the prompt. When injecting multiple retrieved items, rank by relevance and position the top-ranked at the edges. Keep individual retrieval results small and targeted so no single result spans the attention dead zone. Use iterative retrieval with narrow queries rather than one broad dump.
Journey Context:
LLMs exhibit a U-shaped attention pattern: strong attention at the beginning and end of context, with a significant dead zone in the middle. This was rigorously demonstrated in the Lost in the Middle study. For coding agents, if you retrieve 5 code snippets and place them between the system prompt and the user query, the middle snippets effectively vanish. The naive fix—just put everything at the edges—doesn't scale. The real fix is two-fold: position matters, and size matters. Keep each retrieved chunk small enough that it doesn't span the dead zone, and put the most important chunks at the edges. Iterative retrieval \(query then small result then reason then query again\) is strictly better than one-shot retrieval with a large context dump because each result stays small and attended.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T05:17:31.547729+00:00— report_created — created