context-degradation

Diagnose and mitigate context degradation patterns in LLM agent systems.

Updated Feb 20, 2026
One-click install
npx skills add https://github.com/gtbauke/bj-utils --skill context-degradation-gtbauke
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: context-degradation
Source: https://github.com/gtbauke/bj-utils/tree/main/.agent/skills/context-degradation
Command: npx skills add https://github.com/gtbauke/bj-utils --skill context-degradation-gtbauke

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Long-running LLM agents silently degrade as context grows: critical instructions get lost in the middle of the window, hallucinated facts poison downstream reasoning, and contradictory retrieved documents produce unpredictable outputs. This Skill provides detection patterns, mitigation frameworks, and Python tooling to identify and fix these failures before they cascade. ## Core Features & Use Cases - Five Degradation Patterns: Recognize and mitigate lost-in-middle, context poisoning, distraction, confusion, and clash with specific detection signals and recovery procedures for each. - Health Analysis Toolkit: Run composite context health checks combining attention distribution, poisoning detection, and utilization metrics via the included Python scripts. - Four-Bucket Mitigation Framework: Apply Write, Select, Compress, and Isolate strategies matched to the active degradation pattern. - Use Case: An agent's output quality drops after 40K tokens of conversation. Use this Skill to measure attention distribution, detect that key instructions sit in the degraded middle region, and restructure context placement before compaction triggers. ## Quick Start Ask the agent to analyze the current conversation context for degradation symptoms and recommend mitigation strategies using the context-degradation skill.

Frequently Asked Questions about context-degradation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I detect lost-in-middle problems in LLM context?▼

Measure attention distribution across context positions and check whether critical information falls in the middle region, which suffers 10-40% reduced recall. The included detect_lost_in_middle function flags at-risk positions and recommends moving key content to the beginning or end.

What is context poisoning and how do I fix it?▼

Context poisoning occurs when hallucinations, tool errors, or incorrect retrieved facts enter context and compound through self-reference. Recover by truncating to before the poisoning point or restarting with verified-only context rather than layering corrections on top.

At what context length does LLM performance degrade?▼

Degradation typically begins at 60-70% of the advertised context window, with meaningful drops often starting at 8K-16K tokens for complex tasks. The decline is non-linear with a cliff edge, so set compaction triggers around 70% of the known onset threshold.

Does a larger context window solve long-context problems?▼

No. Larger windows delay but do not eliminate U-shaped attention degradation, and processing cost grows non-linearly with token count. For multi-task workloads, splitting tasks across sub-agents with isolated contexts is more effective than expanding a single context.

Why does my agent ignore instructions in long prompts?▼

Instructions placed in the middle of long contexts receive reduced attention due to the U-shaped attention curve. Move critical instructions to the beginning or end, add explicit section headers as attention anchors, and verify the prompt works at low token counts to rule out prompt quality issues.

How accurate is the degradation detection script?▼

The script simulates U-shaped attention curves and uses pattern matching for poisoning detection as demonstration proxies. Production systems should extract actual attention weights via tools like TransformerLens and use model-specific tokenizers for accurate token counts.