How to Write and Use Agent Skills: A Practical Guide
This guide explains how to package reusable instructions, reference files, and optional scripts into an agent skill that can be invoked automatically for specific tasks. It covers the three-level progressive disclosure structure, how to define trigger boundaries and input/output contracts before writing instructions, how to write executable and verifiable workflows, how to combine standalone skills with external tool access, and how to test, version, and distribute skills across a team. Readers will also find common anti-patterns to avoid and a clear path to building a first working skill in 15 to 30 minutes.
1. Why “Skillify”? From Repeated Explanations to a One-Time Investment
A frequent pain point when working with AI coding tools or conversational agents is that every new session forces you to restate the background, your preferences, the required output format, and the process constraints. A context window can hold information, but it is inherently volatile and scoped to a single session. Passing stable knowledge along “verbally” over and over wastes tokens and amplifies inconsistency in results.
A skill is essentially a folder that bundles a set of reusable instructions, reference material, and optional scripts so the agent can invoke them automatically when facing a specific task or workflow. It is not a one-off prompt but an evolving capability asset. Typical use cases include generating frontend code from a requirements document, producing research conclusions under a unified analysis framework, writing documents that follow team standards, and chaining multi-step build and validation processes. For developers already connected to external toolchains, a skill adds a layer of orchestration and constraints on top of raw tool access, turning “able to call” into “reliably completes the work to spec.”
This article is written for three audiences: developers who want an agent to consistently follow an established workflow; advanced users who want to lock in personal preferences and processes; and teams that need to standardize agent behavior across an organization. The goal is that after reading and doing the exercises, you can independently build a skill that runs, can be tested, and can be distributed.
2. Core Design Principle: The Three Levels of Progressive Disclosure
The most important architectural idea behind a skill is progressive disclosure: load information in layers by relevance instead of pushing everything into the context at once. It typically has three levels:
- Level 1: YAML frontmatter. Always present at the system prompt level, holding only the name and a description of the purpose. Its job is to let the model decide “does the current task need this skill.” This layer must be minimal and semantically clear.
- Level 2: The skill body (usually a Markdown instruction file). Loaded only when the model judges it relevant; it carries the complete workflow, constraints, input/output contract, and examples.
- Level 3: Linked additional files, such as templates, validation rules, reference material, and executable scripts. The model reads them on demand, sometimes opening them only when actually needed.
This structure yields three direct benefits: controlled context usage, clear behavioral boundaries, and low maintenance cost. When designing, follow the division of labor “metadata only routes, the body only describes the process, attachments only hold details,” and avoid stuffing long documents into Level 1; otherwise it degrades into an always-on mega-prompt and loses the point of layering.
A schematic directory and metadata shape looks like this (structure only, not a specific product interface):
my-skill/├── SKILL.md # Level 2: full instructions├── references/ # Level 3: consulted on demand│ ├── schema.md│ └── checklist.md└── scripts/ # Level 3: optional executable logic└── validate.py
---name: doc-standardizerdescription: Use when the user asks to generate or tidy up documents according to team standards; handles structure validation, terminology unification, and format normalization.---
3. Planning: Define the Contract Before Writing Instructions
A high-quality skill does not start with “writing a prompt”; it starts with defining a contract. Before you begin, make four things explicit:
- Trigger boundaries: which tasks should use it and which should not. Blurry boundaries cause false triggers, especially when multiple skills coexist.
- Input contract: what information is required, and how to ask follow-up questions or degrade gracefully when something is missing.
- Output contract: structure, fields, format, length, language, and acceptance criteria.
- Failure strategy: when facing uncertainty, conflicting instructions, or unavailable tools, does it stop and ask, or return a conservative result with annotations?
A practical technique is a “negative list”: explicitly state what not to do, for example, do not fabricate data sources, do not skip validation steps, and do not modify unauthorized files. Negative constraints often stabilize behavior better than positive descriptions.
4. Writing: Instructions Must Be Executable and Verifiable
The body should read like an SOP handed to a new colleague, not like prose. Recommended practices:
- Describe the process in numbered steps, giving the input, action, and output for each step;
- Write judgment criteria as checkable conditions, for example, “if the missing-field rate exceeds the threshold, output a list of issues first”;
- Provide at least one complete example and one counter-example to help the model align on style;
- For steps requiring precise calculation or format conversion, state explicitly “call a script/tool to do it” rather than letting the model compute in its head.
Example (excerpt):
## Workflow1. Read the requirements document and extract a list of feature points.2. Annotate each feature point with: page, component, API dependencies, acceptance criteria.3. If any item is undefined, output a "to-be-confirmed list" first and pause generation.4. Generate the code skeleton according to the team component standards; do not introduce unregistered dependencies.5. Run the validation script; on failure, go back to step 4 and fix, for at most two rounds.
5. Combining Standalone Skills with Tool-Enhanced Workflows
There are two common evolution paths for skills. The first is a standalone skill: it relies on no external system and completes text generation, transformation, and review tasks through instructions and attachments. It has the lowest adoption cost and is a good way to get an end-to-end loop working first. The second is a skill layered on external tool access: bring general cloud capabilities such as message queues, object storage, container platforms, logging services, and monitoring/alerting, or query and write actions against internal systems, into the process, with the skill responsible for orchestration, retries, and result validation.
The recommended combination principle is “tools perform atomic actions, the skill governs the process.” Atomic actions keep a single responsibility, while the skill layer handles ordering, branching, idempotency, and rollback guidance. Schematic:
Skill: release check├─ Step 1: pull build artifact metadata (Tool A)├─ Step 2: validate version number and changelog (script)├─ Step 3: write the check report to storage (Tool B)└─ Step 4: on failure, output diagnosis suggestions; do not roll back automatically
6. Testing and Iteration: Govern Skills Like Code
Skills need versioning and regression tests. Prepare a fixed set of cases covering the happy path, boundary inputs, missing parameters, conflicting instructions, and tool failures; rerun them after every change to the metadata description or process steps, and watch trigger accuracy and output consistency. When iterating, adjust the “trigger description” and the “negative list” first; these two have the greatest impact on stability. Also keep a changelog explaining why each change was made, so the team does not repeat the same mistakes.
7. Distribution and Team Collaboration
When distributing a skill, include a purpose statement, applicable and non-applicable scenarios, input/output examples, a dependency list, and known limitations. In a team setting, set up a shared repository and a review mechanism, treating skills as an executable carrier of internal standards; in a Baidu AI Cloud environment, you can combine permission and audit requirements to make explicit which steps may run automatically and which require human confirmation, ensuring control and traceability.
8. Common Anti-Patterns
- Writing the metadata as a long background section, so it always occupies context;
- A process with no failure strategy, producing output that looks plausible but is unusable when something goes wrong;
- Over-relying on the model’s mental math or memory instead of handing deterministic work to scripts;
- Missing negative constraints, leading to behavior drift;
- No test cases, so after a change you cannot tell whether it is an improvement or a regression.
Master these principles and this process, and you can build your first working skill in 15 to 30 minutes, gradually accumulating team-level capability assets.
