context-degradation – skill Khác cho agent AI
Các mô hình ngôn ngữ có những kiểu suy giảm chất lượng có thể dự đoán khi độ dài ngữ cảnh tăng. Hiểu các kiểu này là điều cần thiết để chẩn đoán lỗi và thiết kế hệ thống có khả năng chịu lỗi.
Cài skill context-degradation bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/context-degradation-b600f.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /context-degradation – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/context-degradation-b600f.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $context-degradation – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/context-degradation-b600f.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /context-degradation – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/context-degradation-b600f.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /context-degradation – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Context Degradation Patterns
Language models exhibit predictable degradation patterns as context length increases. Understanding these patterns is essential for diagnosing failures and designing resilient systems. Context degradation is not a binary state but a continuum of performance degradation that manifests in several distinct ways.
When to Use
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
Core Concepts
Context degradation manifests through several distinct patterns. The lost-in-middle phenomenon causes information in the center of context to receive less attention. Context poisoning occurs when errors compound through repeated reference. Context distraction happens when irrelevant information overwhelms relevant content. Context confusion arises when the model cannot determine which context applies. Context clash develops when accumulated information directly conflicts.
These patterns are predictable and can be mitigated through architectural patterns like compaction, masking, partitioning, and isolation.
Detailed Topics
The Lost-in-Middle Phenomenon
The most well-documented degradation pattern is the "lost-in-middle" effect, where evaluated models can show U-shaped task-performance curves. Information at the beginning and end of context receives reliable attention, while information buried in the middle suffers from dramatically reduced recall accuracy.
Empirical Evidence
The Lost in the Middle paper reports position-sensitive performance on its evaluated retrieval/question-answering tasks. The magnitude depends on the model/task; it does not establish a universal 10–40% loss or a single causal mechanism.
Models allocate massive attention to the first token (often the BOS token) to stabilize internal states. This creates an "attention sink" that soaks up attention budget. As context grows, the limited budget is stretched thinner, and middle tokens fail to garner sufficient attention weight for reliable retrieval.
Practical Implications
Design context placement with attention patterns in mind. Place critical information at the beginning or end of context. Consider whether information will be queried directly or needs to support reasoning—if the latter, placement matters less but overall signal quality matters more.
For long documents or conversations, use summary structures that surface key information at attention-favored positions. Use explicit section headers and transitions to help models navigate structure.
Context Poisoning
Context poisoning occurs when hallucinations, errors, or incorrect information enters context and compounds through repeated reference. Once poisoned, context creates feedback loops that reinforce incorrect beliefs.
How Poisoning Occurs
Poisoning typically enters through three pathways. First, tool outputs may contain errors or unexpected formats that models accept as ground truth. Second, retrieved documents may contain incorrect or outdated information that models incorporate into reasoning. Third, model-generated summaries or intermediate outputs may introduce hallucinations that persist in context.
The compounding effect is severe. If an agent's goals section becomes poisoned, it develops strategies that take substantial effort to undo. Each subsequent decision references the poisoned content, reinforcing incorrect assumptions.
Detection and Recovery
Watch for symptoms including degraded output quality on tasks that previously succeeded, tool misalignment where agents call wrong tools or parameters, and hallucinations that persist despite correction attempts. When these symptoms appear, consider context poisoning.
Recovery requires removing or replacing poisoned content. This may involve truncating context to before the poisoning point, explicitly noting the poisoning in context and asking for re-evaluation, or restarting with clean context and preserving only verified information.
Context Distraction
Context distraction emerges when context grows so long that models over-focus on provided information at the expense of their training knowledge. The model attends to everything in context regardless of relevance, and this creates pressure to use provided information even when internal knowledge is more accurate.
The Distractor Effect
Research shows that even a single irrelevant document in context reduces performance on tasks involving relevant documents. Multiple distractors compound degradation. The effect is not about noise in absolute terms but about attention allocation—irrelevant information competes with relevant information for limited attention budget.
Irrelevant tokens can interfere with retrieval and reasoning, but the extent depends on architecture and inference implementation; do not infer a mandatory equal allocation of attention to every token.
Mitigation Strategies
Mitigate distraction through careful curation of what enters context. Apply relevance filtering before loading retrieved documents. Use namespacing and organization to make irrelevant sections easy to ignore structurally. Consider whether information truly needs to be in context or can be accessed through tool calls instead.
Context Confusion
Context confusion arises when irrelevant information influences responses in ways that degrade quality. This is related to distraction but distinct—confusion concerns the influence of context on model behavior rather than attention allocation.
If you put something in context, the model has to pay attention to it. The model may incorporate irrelevant information, use inappropriate tool definitions, or apply constraints that came from different contexts. Confusion is especially problematic when context contains multiple task types or when switching between tasks within a single session.
Signs of Confusion
Watch for responses that address the wrong aspect of a query, tool calls that seem appropriate for a different task, or outputs that mix requirements from multiple sources. These indicate confusion about what context applies to the current situation.
Architectural Solutions
Architectural solutions include explicit task segmentation where different tasks get different context windows, clear transitions between task contexts, and state management that isolates context for different objectives.
Context Clash
Context clash develops when accumulated information directly conflicts, creating contradictory guidance that derails reasoning. This differs from poisoning where one piece of information is incorrect—in clash, multiple correct pieces of information contradict each other.
Sources of Clash
Clash commonly arises from multi-source retrieval where different sources have contradictory information, version conflicts where outdated and current information both appear in context, and perspective conflicts where different viewpoints are valid but incompatible.
Resolution Approaches
Resolution approaches include explicit conflict marking that identifies contradictions and requests clarification, priority rules that establish which source takes precedence, and version filtering that excludes outdated information from context.
Empirical Benchmarks and Thresholds
Research provides concrete data on degradation patterns that inform design decisions.
RULER Benchmark Findings
The RULER benchmark delivers sobering findings: only 50% of models claiming 32K+ context maintain satisfactory performance at 32K tokens. This is a result for the paper’s 2024 evaluated models/tasks, not a ranking of current models. Near-perfect scores on simple needle-in-haystack tests do not translate to real long-context understanding.
Measure the deployed model and workload
Do not use uncited universal onset thresholds or vendor leaderboard scores as long-context evidence. Sweep input length, relevant-fact position, distractor count and task complexity while holding the prompt, model snapshot, decoding settings and ground truth fixed. Record accuracy, refusal/error rate, latency and billed tokens; repeat enough cases to expose variation. Select an operational limit from the acceptable error budget, not the advertised context maximum.
Counterintuitive Findings
Research reveals several counterintuitive patterns that challenge assumptions about context management.
Shuffled Haystacks Outperform Coherent Ones
Studies found that shuffled (incoherent) haystacks produce better performance than logically coherent ones. This suggests that coherent context may create false associations that confuse retrieval, while incoherent context forces models to rel
… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- saml-sso-attack – Tấn công SAML SSO qua XSW, gỡ chữ ký, trích xuất metadata.
- rdkit – Bộ công cụ tin học hóa học để kiểm soát chi tiết phân tử. Phân tích SMILES/SDF…
- context-fundamentals – Ngữ cảnh là toàn bộ trạng thái mà mô hình ngôn ngữ có thể truy cập tại thời điểm suy…
- context-guardian – Vệ sĩ ngữ cảnh bảo toàn dữ liệu quan trọng trước khi nén tự động. Snapshot, kiểm tra…
- context-management-context-restore – Tiếp tục công việc dự án bị gián đoạn từ handoff và bằng chứng từ checkout hiện tại; đối…
- context-management-context-save – Dùng khi làm việc với lưu ngữ cảnh (context save) trong quản lý ngữ cảnh.
- context-optimization – Tối ưu ngữ cảnh mở rộng dung lượng hiệu dụng của cửa sổ ngữ cảnh hạn chế thông qua nén…
- ma-playbook – Chiến lược M&A để mua lại công ty hoặc được mua lại. Thẩm định (due diligence), định…