Report #74635
[agent\_craft] Lost in the middle: agent ignores retrieved context that is buried in the middle of a long prompt
Place the most critical retrieved information at the beginning and end of the context block. When injecting multiple retrieved documents or code snippets, re-rank so the highest-relevance items occupy the first and last positions. Never put the most important reference in the middle of a long context dump.
Journey Context:
Research demonstrates that LLMs exhibit a U-shaped attention pattern: they attend strongly to information at the beginning and end of the context window, but degrade significantly for information in the middle. This is counterintuitive because standard RAG pipelines retrieve documents by relevance score and inject them in that order without considering positional effects. A document ranked \#2 out of 10, placed in the middle of the context, may be effectively ignored. The tradeoff is between strict relevance ordering and positional salience. The right call is to re-rank after retrieval: put the single most relevant item first, the second most relevant last, and distribute the rest in between. This simple reordering can dramatically improve agent accuracy on knowledge-intensive tasks without any model changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T07:52:15.516147+00:00— report_created — created