A Practical Guide to Writing and Reusing Agent Skills
This article explains how agent skills work and how to write them well. It covers why skills have become a mainstream way to extend AI agents, four core principles for high-quality skill authoring, progressive disclosure for controlling context cost, advanced directory and configuration patterns, team collaboration and reuse mechanisms, and common anti-patterns with optimization suggestions. Readers will learn how to define trigger boundaries, offload deterministic work to scripts, and manage skills as evolving engineering assets.
1. Why Skills Have Become the Mainstream Way to Extend Agents
As large language models are increasingly adopted in coding, analysis, and automation, the central question for engineering teams has shifted from “can the model do it?” to “how do we make the model do it correctly and consistently?” Agent skills are widely adopted because they offer a low-coupling way to inject capabilities: they package domain knowledge, operational procedures, validation rules, and supporting resources into an extension unit that an agent can discover, load on demand, and execute on demand.
A common misconception is to treat a skill as “a prompt” or “a documentation file.” A more accurate definition is that a skill is an extension package with a directory structure. It can contain documentation, executable scripts, templates, configuration samples, and test data. At runtime, the agent first reads lightweight metadata and a description to decide whether the current task matches. Once matched, it loads the detailed content and, when necessary, invokes the scripts inside to perform deterministic operations. This layered mechanism of “discover first, load next, execute last” is the key to keeping the skill system lightweight.
In related engineering practice at Baidu AI Cloud, teams typically combine skills with general cloud capabilities such as log services, monitoring and alerting, and object storage: the skill describes the workflow and constraints, while the cloud services provide the runtime environment and observability, forming a traceable and rollback-capable automation loop.
2. Four Core Principles for Writing High-Quality Skills
2.1 Do Not State the Obvious
Models already possess a large amount of general coding and design knowledge, and repeatedly emphasizing basic concepts in a skill only dilutes attention. A truly valuable skill should carry information that the model cannot easily infer on its own: internal conventions, lessons learned from past failures, trade-off criteria for specific scenarios, and verified lists of anti-patterns.
Take a UI design skill as an example. A low-quality version reminds the model to “pay attention to alignment and whitespace.” A high-quality version explicitly lists the formulaic approaches to avoid—such as overusing a certain generic font, applying high-saturation gradients by default, or stacking card shadows—and provides alternative strategies and the reasoning behind them. Such information is effective because it changes the model’s default tendencies rather than repeating what it already knows.
A simple self-check applies while writing: if you delete this sentence, will the model’s behavior change? If not, delete it.
2.2 Define Trigger Boundaries and Applicability Conditions
The most common cause of skill failure is not content quality but incorrect triggering. A description that is too broad causes false triggers, while a description that is too obscure causes missed triggers. It is recommended to state both “applicable scenarios” and “non-applicable scenarios” in the skill metadata, and to use observable task characteristics as criteria wherever possible.
A sample structure is shown below:
skill-name/├── SKILL.md # Name, description, applicable/non-applicable boundaries├── reference/ # Detailed knowledge, loaded on demand├── scripts/ # Scripts for deterministic operations└── assets/ # Templates, samples, test data
In the description field, the recommended pattern is “action + object + constraint,” for example: “Use this skill to generate a phased strategy and a rollback validation checklist when the user asks to add a canary release process for a containerized service; not applicable to single-machine script changes.” This pattern significantly reduces ambiguity.
2.3 Use Progressive Disclosure to Control Context Cost
The context window is a scarce resource. Skill design should follow a three-layer loading approach: the first layer is the name and a short description, which stays visible at all times; the second layer is the main body, loaded after the task matches; the third layer is the detailed documents and data in the reference directory, read only when needed. Putting large sections of reference material directly into the main document causes the context to expand rapidly and actually degrades output quality.
In engineering terms, keep the main document at a size that can be scanned quickly, move long tables, case libraries, and change logs into the reference directory, and point to them from the main document as an index. This preserves information completeness while maintaining runtime efficiency.
2.4 Let Scripts Handle Deterministic Work
Models are good at understanding and generation but not at precise calculation or stable repetition. Any operation whose result must be deterministic and reproducible—format validation, batch renaming, dependency scanning, configuration comparison—should be handled by scripts, with the skill only explaining when to call them and how to interpret the results. This division of labor noticeably reduces “plausible but actually wrong” outputs.
3. Advanced Use of Directory Structure and Configuration
The real flexibility of a skill comes from combining directories with configuration. In addition to Markdown documentation, you can register lifecycle hooks to run environment checks, prepare dependencies, or archive results before and after a skill loads. Some mature teams make “environment self-check” a standalone skill that other skills reuse, avoiding duplicate implementations.
Recommended directory organization habits include: split skills by capability domain rather than by project; keep a minimal runnable sample for each skill; and put volatile rules into configuration or data files so that adjusting rules does not require changing the main document. If cloud execution is involved, artifacts can be written uniformly to object storage, with logs and monitoring services collecting execution traces to make problem diagnosis easier.
4. Team Collaboration and Reuse Mechanisms
The value of skills is amplified through reuse. At the team level, three things are needed: first, naming and metadata conventions to ensure consistent retrieval and triggering; second, a review mechanism that focuses on trigger boundaries, whether obvious content is stated, and whether scripts include failure handling; third, versioning and canary strategies, where a new skill is first tried in a restricted scope before expanding its usage.
When distributing a skill, include a minimal example and a description of known limitations to lower the adoption cost for others. For general capabilities accumulated internally, maintain a shared directory with a change log so that knowledge continues to grow with each iteration.
5. Common Anti-Patterns and Optimization Suggestions
- All-in-one: a single skill carries too many responsibilities, making triggering ambiguous. Split it by capability boundary.
- Textbook-style: restating general knowledge wastes context. Keep only differentiating information.
- No scripts: all work is left to model inference, resulting in poor stability. Push deterministic logic down into scripts.
- No rollback: the automation flow lacks failure handling. Explicitly define validation and fallback steps.
- No metrics: it is impossible to tell whether a skill is effective. Use logs and monitoring to evaluate trigger accuracy and task success rate.
6. Conclusion
The core of writing agent skills is not piling up text but precisely filling the model’s capability gaps: use clear boundaries to solve triggering, use directories and hooks to extend execution capability, use scripts to guarantee determinism, and use layered loading to control cost. Solidify this method into the team workflow and rely on the general cloud services provided by Baidu AI Cloud for execution, observation, and governance, and agent extensibility can be upgraded from an individual technique into a sustainable engineering asset.
