How to Write and Use Agent Skills: A Practical Guide

    This guide explains how agent skills package reusable instructions, templates, and scripts to reduce repeated context setup. It covers common use cases, folder structure, progressive disclosure, writing rules, anti-patterns, a walkthrough from a requirements list to API documentation, and evaluation practices for team collaboration.

    1. Why Package Capabilities as Skills

    In real-world AI-assisted development, the biggest source of inefficiency is often not limited model capability but repeated context rebuilding. Every time a new session starts, users have to restate the tech stack, directory conventions, review standards, output formats, and background knowledge. This consumes the conversation window and tends to get diluted or forgotten during long workflows.

    The core value of a skill is to turn this tacit knowledge—the things you have to explain every time—into explicit instructions that can be loaded on demand.

    From an engineering perspective, a skill is a capability package carried by a folder. The folder usually contains an entry file describing the skill’s purpose, applicable scenarios, and invocation boundaries, along with optional scripts, templates, reference material, and sample data. It addresses three problems:

    • Knowledge reuse: document team conventions once.
    • Behavior constraints: keep outputs within the expected format.
    • Workflow orchestration: chain multi-step tasks into repeatable workflows.

    A skill is not a universal trigger. It works best for high-frequency, repetitive tasks with relatively clear boundaries. For one-off exploration or highly open-ended problems, direct conversation is often more flexible.

    2. Four High-Frequency Scenarios Suited to Skills

    The first is turning requirements into code. Once requirement documents, API contracts, and frontend implementation conventions are written into a skill, the model can produce code skeletons with a consistent layered structure and naming style, reducing style drift.

    The second is standardized research. Capturing the analysis framework, information verification steps, and conclusion template avoids designing an outline from scratch every time and makes it easier to compare the quality of different conclusions.

    The third is team documentation. For design notes, change records, or API descriptions, shared templates and a glossary can significantly lower review costs.

    The fourth is chaining complex multi-step workflows. Skills can work with basic capabilities such as code execution, document creation, and file reading and writing to turn “read input—validate—process—produce—self-check” into a closed loop. For developers integrating external tools, a skill adds a layer of reliability on top of raw tool access, turning error-prone direct calls into reusable business actions.

    3. Folder Structure and Progressive Disclosure

    The key design principle is loading on demand. The entry file should stay concise, stating only the purpose, trigger conditions, and an index of subsequent resources. Details should be split into separate files that the model reads when needed. This progressive disclosure saves context and reduces interference from irrelevant information.

    An example layout:

    1. my-skill/
    2. ├── SKILL.md # Entry: name, use cases, resource index
    3. ├── templates/ # Output templates
    4. ├── references/ # Specs, glossary, boundary conditions
    5. ├── scripts/ # Deterministic scripts for validation, conversion
    6. └── examples/ # Positive and negative examples

    The entry file should use structured metadata followed by a short body:

    1. ---
    2. name: api-doc-generator
    3. description: Generates standardized documentation from an API list, for version iterations and pre-review cleanup
    4. ---
    5. ## Workflow
    6. 1. Read references/spec.md for templates and terminology
    7. 2. Parse the input list and ask about missing fields first
    8. 3. Generate the document and run scripts/check.py for self-checking

    4. Writing Rules and Common Anti-Patterns

    A good skill description has four traits: clear actions, clear inputs, verifiable outputs, and fallbacks for exceptions. Use executable verbs and avoid vague qualifiers such as “try to” or “appropriately.” State required fields, format constraints, and failure handling explicitly.

    Common anti-patterns include:

    • Stuffing long background material into the entry file, which bloats context.
    • Describing only the goal and not the steps, leaving the model to improvise.
    • Missing negative examples, which leads to inconsistent handling of edge cases.
    • Assigning deterministic work to model reasoning instead of script execution.

    Any rule that can be checked by code should be pushed down to the script layer: the model handles judgment and generation, while scripts handle validation and blocking.

    5. Hands-On: From a Requirements List to API Documentation

    Suppose the goal is to turn an API list into standardized team documentation.

    1. Declare trigger conditions and resource paths in the entry file.
    2. Place a section skeleton in the templates folder to fix field order.
    3. Write the glossary and naming conventions in the references folder.
    4. Write a validation script to check required fields and formatting.
    5. Prepare one positive and one negative example that spell out “content that must not appear.”

    The recommended runtime flow is to parse the input and list missing items first, confirm them with the user, then generate. Run the script self-check immediately after generation. If validation fails, use the message to locate and fix the specific field instead of rewriting everything. This keeps output consistent and makes errors traceable.

    6. Debugging, Evaluation, and Team Collaboration

    Skills should be evaluated like code. Maintain a set of fixed inputs and expected outputs, and run regression checks after every change. Record failing cases and turn them into new negative examples. Label trigger boundaries to prevent a skill from being loaded in unsuitable scenarios.

    For team collaboration, keep skills under version control with a clear review owner and change log. Keep the entry description short and expand detail documents as needed. If the runtime provides common cloud capabilities such as container platforms, object storage, logging, and monitoring alerts, you can connect skill inputs, outputs, and execution traces to the logging and alerting system to track invocation success rates and locate anomalies. General product categories from Baidu AI Cloud can also serve as a reference for this kind of engineering workflow.

    7. Conclusion

    The essence of a skill is turning organizational knowledge into executable constraints. Its value comes not from longer prompts but from clearer structure, stricter boundaries, and more verifiable outputs. Start with high-frequency scenarios, solidify the workflow before refining details, and combine script validation with regression evaluation to make custom capabilities reliably reusable.