context-degradation
This skill should be used for diagnosing and mitigating context degradation: lost-in-middle failures, context poisoning, context clash, context confusion…
Skill by Muratcan Koylan — Agent-Skills-for-Context-Engineering (MIT), vendored
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/rahulgupta2018-context-degradation
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: agent-building
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions: not checked yet.
What's inside
- Skill name
context-degradation- Description
- This 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.
- License
- MIT
- Metadata
- author: Muratcan Koylan — Agent-Skills-for-Context-Engineering (MIT), vendored · version: 0.1.0 · category: agent · last_updated: 2026-08-11
- Instructions
- 233 lines in SKILL.md · view on GitHub
Before installing
- Ships executable scripts
Files (3)
- SKILL.md
- patterns.md · references/
- degradation_detector.py · scripts/
SKILL.md (first lines)
# Context Degradation Patterns 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. ## When to Activate Activate this skill when: - Agent performance degrades unexpectedly during long conversations - Debugging cases where agents produce incorrect or irrelevant outputs - Designing systems that must handle large contexts reliably - Evaluating context engineering choices for production systems - Investigating "lost in middle" phenomena in agent outputs - Analyzing context-related failures in agent behavior Do not activate this skill for adjacent work owned by other skills: - Explaining foundational context mechanics without an active failure: `context-fundamentals`. - Applying token-efficiency tactics after the failure pattern is known: `context-optimization`. - Designing a compression or handoff summary strategy: `context-compression`. - Persisting large outputs, logs, or scratch state outside the prompt: `filesystem-context`. ## Core Concepts 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. 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. 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. 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. 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. ## Detailed Topics ### Lost-in-Middle: Detection and Placement Strategy 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. 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. 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. ### Context Poisoning: Prevention and Recovery 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. 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 these cluster, suspect poisoning rather than model capability issues. Recover by removing poisoned content, not by adding corrections on top. Truncate to before the poisoning point, restart with clean context preserving only verified information, or explicitly mark the poisoned section and request re-evaluation from scratch. Layering corrections over poisoned context rarely works — the original errors retain attention weight. ### Context Distraction: Curation Over Accumulation Curate what enters context rather than relying on models to ignore irrelevant content. Research shows even a single distractor document triggers measurable performance degradation — the effect follows a step function, not a linear curve. Multiple distractors compound the problem. Apply relevance filtering before loading retrieved documents. Use namespacing and structural organization to make section boundaries clear. Prefer tool-call-based access over pre-loading: store reference material behind retrieval tools so it enters context only when directly relevant to the current reasoning step. ### Context Confusion: Task Isolation Segment different tasks into separate context windows. Context confusion is distinct from distraction — it concerns the model applying wrong-context constraints to the current task, not just attention dilution. Signs include responses addressing the wrong aspect of a query, tool calls appropriate for a different task, and outputs mixing requirements from multiple sources. Implement clear transitions between task contexts. Use state management that isolates objectives, constraints, and tool definitions per task. When task-switching within a single session is unavoidable, use explicit "context reset" markers that signal which constraints apply to the current segment. ### Context Clash: Conflict Resolution Protocols Establish source priority rules before conflicts arise. Context clash differs from poisoning — multiple pieces of information are individually correct but mutually contradictory (version conflicts, perspective differences, multi-source retrieval with divergent facts). Implement version filtering to exclude outdated information before it enters context. When contradictions are unavoidable, mark them explicitly with structured conflict annotations: state what conflicts, which source each claim comes from, and which source takes precedence. Without explicit priority rules, models resolve contradictions unpredictably. ### Empirical Benchmarks and Thresholds Use these benchmarks to set design constraints — not as universal truths. RULER-style evidence shows advertised long-context support does not guarantee satisfactory task performance at that length (claim-context-degradation-lost-middle-ruler). Near-perfect needle-in-haystack scores do not predict real-world long-context performance. **Model-Specific Degradation Thresholds** Degradation onset varies significantly by model family and task type. As a general rule, expect degradation to begin at 60-70% of the advertised context window for complex retrieval tasks (RULER benchmark found only 50% of models claiming 32K+ context maintain satisfactory performance at that length). Key patterns: - **Models with extended thinking** reduce hallucination through step-by-step verification but at higher latency and token cost - **Models optimized for agents/coding** tend to have better attention management for tool-output-heavy contexts - **Models with very large context windows (1M+)** handle more raw context but still follow U-shaped degradation curves — bigger windows do not eliminate the problem, they delay it Always benchmark degradation thresholds with your specific workload rather than relying on published benchmarks. Model-specific thresholds go stale with each model update (see Gotcha 2). ### Counterintuitive Findings Account for these research-backed surprises when designing context strategies: **Shuffled context can outperform coherent context.** Studies found incoherent (shuffled) haystacks can outperform logically ordered ones for some retrieval tasks (claim-context-degradation-distractor-shuffled). Coherent context may create false associations that confuse retrieval; incoherent context can force exact matching. Do not assume that better-organized context always yields better results — test both arrangements. **Single distractors have outsized impact.** The performance hit from one irrelevant document is disproportionately large compared to adding more distractors after the first. Treat distractor prevention as binary: either keep context clean or accept significant degradation. **Low needle-question similarity accelerates degradation.** Tasks requiring inference across dissimilar content degrade faster with context length than tasks with high surface-level similarity. Design retrieval to maximize semantic overlap between queries and retrieved content. ### When Larger Contexts Hurt Do not assume larger context windows improve performance. Performance remains stable up to a model-specific threshold, then degrades rapidly — the curve is non-linear with a cliff edge, not a gentle slope. For many models, meaningful degradation begins at 8K-16K tokens even when windows support much larger sizes. Factor in cost: processing a 400K token context costs exponentially more than 200K in both time and compute, not linearly more. For many applications, this makes large-context processing economically impractical. Recognize the cognitive bottleneck: even with infinite context, asking a single model to maintain quality across dozens of independent tasks creates degradation that more context cannot solve. Split tasks across sub-agents instead of expanding context. ## Practical Guidance ### The Four-Bucket Mitigation Framework Apply these four strategies based on which degradation pattern is active: **Write** — Save context outside the window using scratchpads, file systems, or external storage. Use when context utilization exceeds 70% of the window. This keeps active context lean while preserving information access through tool calls. **Select** — Pull only relevant context into the window through retrieval, filtering, and prioritization. Use when distraction or confusion symptoms appear. Apply relevance scoring before loading; exclude anything below threshold rather than including everything available. **Compress** — Reduce tokens while preserving information through summarization, abstraction, and observation masking. Use when context is growing but all content is relevant. Replace verbose tool outputs with compact structured summaries; abstract repeated patterns into single references. **Isolate** — Split context across sub-agents or sessions to prevent any single context from growing past its degradation threshold. Use when confusion or clash symptoms appear, or when tasks are independent. This is the most aggressive strategy but often the most effective for complex multi-task systems. ### Architectural Patterns for Resilience Implement just-in-time context loading: retrieve information only when the current reasoning step needs it, not preemptively. Use observation masking to replace verbose tool outputs with compact references after processing. Deploy sub-agent architectures where each agent holds only task-relevant context. Trigger compaction before context exceeds the model-specific degradation onset threshold — not after symptoms appear. ## Examples
From rahulgupta2018/agent-skills, MIT.
More from rahulgupta2018/agent-skills
- 0.552score
code-reviewer
awesome-llm-apps (adapted for this library)
Reviews code changes (frontend, backend/API, and agent/workflow code) for security, performance, correctness, and maintainability, and returns a prioritised…
SkillBFreshness: B★ 1Claude Code +9 - 0.548score
cloud-architecture-patterns
AI Software Factory (fundamentals distilled from the cloud-agnostic architecture canon)
The distributed/cloud application architecture fundamentals: choose an architecture STYLE (N-tier, web-queue-worker, microservices, event-driven, big-data…
SkillBFreshness: B★ 1Claude Code +9 - 0.497score
adk-architecture
rahulgupta2018
ADK architectural knowledge — graph orchestration, resumption, execution flow, node contracts, observability, and LLM context orchestration.
SkillCFreshness: C★ 1Claude Code +9 - 0.497score
adk-agent-builder
rahulgupta2018
Central hub for building, testing, and iterating on ADK agents.
SkillCFreshness: C★ 1Claude Code +9 - 0.497score
agent-discovery
rahulgupta2018
Analyse an existing agent, agent prompt, or AGENT.md to inventory responsibilities, tool usage, reusable procedures, context-heavy sections, failure points…
SkillCFreshness: C★ 1Claude Code +9 - 0.492score
adk-sample-creator
rahulgupta2018
Author new samples for the ADK Python repository.
SkillCFreshness: C★ 1Claude Code +9 - 0.492score
adk-debug
rahulgupta2018
Use when debugging ADK agents, inspecting sessions, testing agent behavior, troubleshooting tool calls, event flow issues, or diagnosing LLM/model problems.
SkillCFreshness: C★ 1Claude Code +9 - 0.492score
adk-review
rahulgupta2018
Reviews all local changes in the repository for errors, styling compliance, unintended outcomes, and necessary documentation/test/sample updates.
SkillCFreshness: C★ 1Claude Code +9 - 0.492score
adk-setup
rahulgupta2018
Set up a local development environment for the ADK Python project.
SkillCFreshness: C★ 1Claude Code +9 - 0.492score
adk-style
rahulgupta2018
ADK development style guide for routine nits — Python idioms, codebase conventions, imports, typing, Pydantic patterns, formatting, logging…
SkillCFreshness: C★ 1Claude Code +9 - 0.490score
skill-name-in-kebab-case
Social Housing AI
Third-person, present-tense description written for discovery.
SkillCFreshness: C★ 1Claude Code +9 - 0.489score
adk-git
rahulgupta2018
Use for any git operation (commit, push, pull, rebase, branch, PR, cherry-pick, etc.).
SkillCFreshness: C★ 1Claude Code +9
Signals
- Stars
- 1
- Forks
- 0
- Open issues
- 0
- Last commit (this folder)
- Aug 12, 2026 (2 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- Version
- 0.1.0
- License
- MIT
- Repository
- github.com/rahulgupta2018/agent-skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
Same skill elsewhere
Copies of this SKILL.md published by others; search shows only one of them.
- 0.761score
context-degradation
muratcankoylan
This skill should be used for diagnosing and mitigating context degradation: lost-in-middle failures, context poisoning, context clash, context confusion…
SkillCFreshness: C★ 18.2KClaude Code +9 - 0.337score
context-degradation
guanyang
This skill should be used for diagnosing and mitigating context degradation: lost-in-middle failures, context poisoning, context clash, context confusion…
SkillCFreshness: C★ 980Claude Code +9 - 0.313score
context-degradation
pretty998
This skill should be used for diagnosing and mitigating context degradation: lost-in-middle failures, context poisoning, context clash, context confusion…
SkillBFreshness: BClaude Code +9
Cite this page
context-degradation skill. Agent Mart. https://agentmart.dev/skills/rahulgupta2018-context-degradation (last updated 2026-10-24)