Agent Development in Practice: Solving Context Bloat with a Skills Mechanism
This article explains how to combat context bloat in AI Agent development by replacing a monolithic system prompt with a layered, on-demand skills library. You will learn why effective information density matters more than raw token count, how progressive disclosure keeps context lean, how to structure and write skill files that models can execute reliably, and how to handle common failure modes such as trigger misses, over-triggering, skill sprawl, and conflicting rules. The article also covers integrating the skills mechanism into engineering workflows through version control, CI validation, monitoring, and continuous tuning based on evaluation data.
1. The Starting Point: The Real Limit of a System Prompt Is Effective Information Density
In Agent development, a common mistake is treating the system prompt as a warehouse that can be expanded indefinitely. Teams stuff in data access policies, code style conventions, domain glossaries, postmortems of past incidents, and business background material, assuming that “more is always safer.” The actual result is often the opposite: the model follows instructions less faithfully, and even simple tasks start to drift.
The reason is not mysterious. The constraint of a system prompt is not the token count but effective information density: the proportion of information in a given context that is genuinely relevant to the current task and can be reliably invoked by the model. As the share of irrelevant content rises, attention is diluted. This phenomenon is commonly called Context Rot. It does not show up as an error; instead, it is a slow quality degradation: formats are occasionally ignored, field definitions drift, boundary conditions are overlooked, and the same question gets two inconsistent answers.
The other end is equally bad. To cram in more content, teams compress their wording into telegraphic abbreviations and internal shorthand. The information looks preserved, but a great deal of semantics is lost, leaving the model to guess. The result is a two-sided squeeze: too much noise on one end, too little meaning on the other.
2. Separating “Knowledge” from “Instructions”: The Role of the Skill Library
The way out is to reshape the context from “one thick manual” into “a row of searchable drawers,” where each drawer is a skill description: it takes up no context in normal times and is loaded only when a task matches. A skill here is not a plugin, nor an external function call. It is essentially a collection of documents and scripts read on demand, used to carry reusable procedural knowledge.
A practical layered structure looks like this:
- Layer 1 (always resident): role definition, a few hard red lines, task boundaries, and output contracts. Keep it very short and aim for a high signal-to-noise ratio.
- Layer 2 (catalog level): the skill list, where each entry has only a name and a one-line “when to use” trigger description. Its job is to teach the model to “read the catalog.”
- Layer 3 (body level): the full description of a selected skill, including steps, constraints, counterexamples, and a validation checklist.
- Layer 4 (resource level): templates, field dictionaries, validation scripts, and sample data, read further only when needed.
The catalog contract can be expressed with an illustrative structure:
skills:- name: feature_pipelinewhen: need to add or modify feature processing logicbody: skills/feature_pipeline.mdresources: [templates/feature_spec.md, scripts/check_schema.py]- name: query_reviewwhen: need to write or review a data querybody: skills/query_review.md
The key is how the when field is written. It is not a summary but a routing condition. It should describe observable task characteristics rather than subjective judgments. Writing “need to handle feature definition changes and backfills” is better than writing “a powerful feature skill.”
3. Progressive Disclosure: Let Context Grow on Demand
The core of progressive disclosure is “give the index first, then the body, then the resources.” This mechanism brings three direct benefits.
First, density becomes controllable. The resident part stays lean, the noise ratio drops, and instruction following recovers. Second, maintainability improves. A specification change only requires editing the corresponding skill file, with no need to readjust the entire system prompt or worry that a change triggers unrelated behavior drift. Third, composability increases. Multiple skills can be loaded at the same time, but the total volume is determined by the task rather than by “just in case.”
Loading discipline deserves emphasis. Once a skill body enters the context, it should be explicitly “put away” when the task ends, to avoid old skills lingering across multi-turn tasks and conflicting with new ones. In engineering terms, you can rebuild the context skeleton at the start of each task turn, keeping only the resident layer and the currently matched skills.
4. How to Write Skill Files That Actually Work
The target reader of a skill document is the model, so the writing style should be close to “an executable standard operating procedure.”
- Step-based: break the process into ordered actions, each with its input, output, and completion criteria.
- Counterexamples first: explicitly list common wrong practices, which constrain behavior better than abstract requirements.
- Built-in validation: attach a checklist or a runnable validation script at the end so the Agent can self-check instead of relying on reminders.
- Single responsibility: one skill solves only one class of problem; avoid turning it into a mini encyclopedia.
- Boundary declaration: state clearly the “scenarios where it does not apply” to reduce false triggering.
Illustrative snippet:
# Skill: Feature Processing ChangeApplies to: adding/modifying features, or definition changes and historical backfillsSteps:1. Clarify the entity primary key and time semantics; output a granularity statement2. List dependent data sources and update frequency3. Write the processing logic; never introduce future information into offline features4. Run check_schema.py to ensure naming and types match the dictionaryCounterexamples:- Using the current time as a default fill value- Using different implementations for training and inferenceCompletion criteria: the validation script passes, and the granularity statement matches the requirement
5. Common Failure Modes and Tuning Approaches
The first is trigger failure: a skill should be used but is not. This usually happens because the when description is too abstract. The fix is to add concrete nouns and scenario words, plus a few “positive/negative” trigger examples.
The second is over-triggering: heavyweight skills get loaded even for small tasks. You can introduce lightweight and heavyweight versions and default to the lightweight path.
The third is skill sprawl: as the number grows, the catalog itself becomes noise. Set admission criteria, merge synonymous skills, and periodically retire low-frequency items.
The fourth is conflict: two skills give contradictory constraints. You need to declare priority rules in the resident layer, for example security red lines > output contracts > process suggestions.
Tuning should be based on evaluation rather than intuition. It is advisable to build a small regression set covering typical tasks and error-prone boundaries, then compare pass rates, format compliance rates, and human ratings across different context organizations, and let data decide the splitting granularity.
6. Connecting with the Engineering System
The skills mechanism is only stable when embedded in the engineering pipeline. You can put it under version control with change review; connect validation scripts to continuous integration; use logging services and monitoring alerts to observe the distribution of skill hits and where failures concentrate; and distill frequent manual corrections into new skills or counterexample entries. If file and template hosting is involved, you can use general capabilities such as object storage to carry the resource layer, container platforms to run validation tasks, and message queues to asynchronously decouple long-running checks.
In related practice at Baidu AI Cloud, this kind of layered context and skill library organization is typically used together with general cloud product capabilities such as logging, monitoring, and storage, forming a closed loop where “knowledge is versionable, behavior is evaluable, and problems are locatable.”
7. Conclusion
The stability of an Agent does not depend on how much the system prompt contains, but on whether the model can get exactly enough information at each step. Splitting the manual into skill drawers that can be browsed on demand, using the catalog for routing, the body for process, and scripts for validation, is what lets you hold the line on effective information density while features keep expanding. For developers, this is an engineering upgrade from “piling up prompts” to “designing a context architecture.”
