AI Agent Context Cleanup: Fixing Over-Constrained Skills and AGENTS.md for Strong Instruction-Following Models

    As foundation models become better at following instructions, accumulated Skill descriptions, AGENTS.md rules, and subagent configurations can slow agents down instead of speeding them up. This article explains why broad triggers, mandatory full-document reads, and conflicting rules cause context bloat and task blocking, and shows how to fix them by turning triggers into concrete actions, adding a context routing table, and running a repeatable cleanup process.

    1. The Problem: More Constraints, Slower Agents

    As AI coding tools and code assistants iterate quickly, many teams have noticed a counterintuitive pattern: as the underlying model’s instruction-following ability improves significantly, the Skill descriptions, AGENTS.md rules, and subagent configurations accumulated in a repository do not deliver higher efficiency. Instead, they become a major source of task blocking, context bloat, and increased hallucination. The industry often calls this “negative optimization”—it consumes tokens while producing almost no positive value.

    The technical root cause is not mysterious. Early agents had limited proactive retrieval and autonomous judgment, so teams commonly adopted a “hard constraint” strategy: read the architecture document every time, run migration checks every time, and run deployment validation every time. This worked well with models that followed instructions weakly. But when a model can accurately, stably, and repeatedly execute natural-language constraints, vague and overly broad rules are taken literally, and the cost is multiplied.

    2. Root Causes: Three Types of Context Pollution

    1. Triggers that are too broad. A typical example is “enable this Skill when working with databases, queries, models, or persistence.” This kind of description covers many ordinary changes. Even modifying a single ORM field or fixing one query condition can be judged as relevant, pulling migration rules, checklists, and reference material into the context.

    2. Unconditional mandatory reads. For example, “you must read the architecture, database, and deployment documents before every edit.” Changing one string requires one read; changing it a second time requires another read. Progress slows down, context expands quickly, the model’s attention is diluted, and the probability of hallucination rises.

    3. Rules that conflict or overlap. When multiple Skills and multiple specification files give different requirements for the same scenario, a strong instruction-following model is more likely to pause early, repeatedly ask the user for confirmation, or even block the task outright.

    3. Fix One: Write Triggers as Concrete Tasks

    Change the trigger description from a “set of domain nouns” to a “decidable action.” For example, tighten a broad statement into “enable when adding or changing a migration script, or when reviewing its rollout plan.” The test is simple: can the sentence map to a clear action object and action type?

    1. # Bad example (too broad)
    2. Use when working with databases, queries, models, or persistence.
    3. # Recommended (decidable)
    4. Use when adding or changing a migration, or reviewing its rollout.

    4. Fix Two: Build a Context Routing Table

    Replace “read everything every time” with “load by task.” In essence, this creates a routing table for repository knowledge: the current task type determines which document is loaded.

    Current task Context to load
    Adjusting service boundaries Architecture document
    Changing table structure Database document
    Preparing a release Deployment document
    Ordinary UI bug fix No extra loading

    Example wording:

    1. Use architecture doc for service boundaries,
    2. database doc for schema changes,
    3. and deployment doc when preparing a deployment.

    The benefits are threefold: token consumption stays under control, the context window stays clean, and the model’s decision path becomes shorter.

    5. Governance Process: How to Run the Cleanup

    1. Inventory: List all Skills and specification files, noting trigger conditions, loaded content, and last update time.
    2. Deduplicate and merge: Keep only one authoritative rule per scenario and turn the rest into references.
    3. Tighten triggers: Rewrite each one as an action-based description and remove absolute words such as “always,” “every time,” and “all.”
    4. Conflict detection: Build a list of cases where two requirements apply to the same scenario, and define priority and a single source of truth for decisions.
    5. Measure and regress: Track average context length, repeated read counts, task interruption rate, and confirmation rounds, then use the data to validate the cleanup.
    6. Clean up regularly: Put specification files under version control and maintain them alongside code review to prevent them from piling up again.

    6. Common Mistakes

    • Treating “writing more” as “being more rigorous,” which actually increases the surface for false triggers.
    • Using absolute wording to pursue certainty, which instead makes strong models execute mechanically.
    • Changing Skills without changing specification files, so conflicts remain.
    • Lacking measurement, making it impossible to tell whether a rule still provides value.

    7. Conclusion

    Strong instruction-following models do not automatically improve efficiency; they simply amplify quality problems in specification files. Developers need to make a shift from “piling on constraints” to “routing context”: make triggers action-based, load context on demand, and keep rules unique and decidable. In engineering practice on platforms such as Baidu AI Cloud, this kind of context governance can also be measured and iterated continuously using common capabilities such as log services, monitoring and alerting, and configuration version management, so that specifications become a source of efficiency rather than a source of cost.