$npx -y skills add muratcankoylan/Agent-Skills-for-Context-Engineering --skill context-degradationThis skill should be used for diagnosing and mitigating context degradation: lost-in-middle failures, context poisoning, context clash, context confusion, attention-pattern issues, and agent performance degradation caused by accumulated or conflicting context.
| 1 | # Context Degradation Patterns |
| 2 | |
| 3 | Diagnose and fix context failures before they cascade. Context degradation is not binary — it is a continuum that manifests through five distinct, predictable patterns: lost-in-middle, poisoning, distraction, confusion, and clash. Each pattern has specific detection signals and mitigation strategies. Treat degradation as an engineering problem with measurable thresholds, not an unpredictable failure mode. |
| 4 | |
| 5 | ## When to Activate |
| 6 | |
| 7 | Activate this skill when: |
| 8 | - Agent performance degrades unexpectedly during long conversations |
| 9 | - Debugging cases where agents produce incorrect or irrelevant outputs |
| 10 | - Designing systems that must handle large contexts reliably |
| 11 | - Evaluating context engineering choices for production systems |
| 12 | - Investigating "lost in middle" phenomena in agent outputs |
| 13 | - Analyzing context-related failures in agent behavior |
| 14 | |
| 15 | Do not activate this skill for adjacent work owned by other skills: |
| 16 | - Explaining foundational context mechanics without an active failure: `context-fundamentals`. |
| 17 | - Applying token-efficiency tactics after the failure pattern is known: `context-optimization`. |
| 18 | - Designing a compression or handoff summary strategy: `context-compression`. |
| 19 | - Persisting large outputs, logs, or scratch state outside the prompt: `filesystem-context`. |
| 20 | |
| 21 | ## Core Concepts |
| 22 | |
| 23 | Structure context placement around the attention U-curve: beginning and end positions receive reliable attention, while middle positions suffer materially reduced recall accuracy in long-context experiments (claim-context-degradation-lost-middle-ruler). This is not a model bug but a consequence of attention mechanics — the first token (often BOS) acts as an "attention sink" that absorbs disproportionate attention budget, leaving middle tokens under-attended as context grows. |
| 24 | |
| 25 | Treat context poisoning as a circuit breaker problem. Once a hallucination, tool error, or incorrect retrieved fact enters context, it compounds through repeated self-reference. A poisoned goals section causes every downstream decision to reinforce incorrect assumptions. Detection requires tracking claim provenance; recovery requires truncating to before the poisoning point or restarting with verified-only context. |
| 26 | |
| 27 | Filter aggressively before loading context — even a single irrelevant document measurably degrades performance on relevant tasks. Models cannot "skip" irrelevant context; they must attend to everything provided, creating attention competition between relevant and irrelevant content. Move information that might be needed but is not immediately relevant behind tool calls instead of pre-loading it. |
| 28 | |
| 29 | Isolate task contexts to prevent confusion. When context contains multiple task types or switches between objectives, models incorporate constraints from the wrong task, call tools appropriate for a different context, or blend requirements from multiple sources. Explicit task segmentation with separate context windows eliminates cross-contamination. |
| 30 | |
| 31 | Resolve context clash through priority rules, not accumulation. When multiple correct-but-contradictory sources appear in context (version conflicts, perspective conflicts, multi-source retrieval), models cannot determine which applies. Mark contradictions explicitly, establish source precedence, and filter outdated versions before they enter context. |
| 32 | |
| 33 | ## Detailed Topics |
| 34 | |
| 35 | ### Lost-in-Middle: Detection and Placement Strategy |
| 36 | |
| 37 | Place critical information at the beginning and end of context, never in the middle. The U-shaped attention curve means middle-positioned information suffers 10-40% reduced recall accuracy. For contexts over 4K tokens, this effect becomes significant. |
| 38 | |
| 39 | Use summary structures that surface key findings at attention-favored positions. Add explicit section headers and structural markers — these help models navigate long contexts by creating attention anchors. When a document must be included in full, prepend a summary of its key points and append the critical conclusions. |
| 40 | |
| 41 | Monitor for lost-in-middle symptoms: correct information exists in context but the model ignores it, responses contradict provided data, or the model "forgets" instructions given earlier in a long prompt. |
| 42 | |
| 43 | ### Context Poisoning: Prevention and Recovery |
| 44 | |
| 45 | Validate all external inputs before they enter context. Tool outputs, retrieved documents, and model-generated summaries are the three primary poisoning vectors. Each introduces unverified claims that subsequent reasoning treats as ground truth. |
| 46 | |
| 47 | Detect poisoning through these signals: degraded output quality on previously-successful tasks, tool misalignment (wrong tools or parameters), and hallucinations that persist despite explicit correction. When th |