How to Write Agent Skills: From Core Principles to Production Implementation
This guide explains why a long persona prompt is not enough to build a reliable agent skill, and how to structure one for real production use. It covers the minimal single-file format, layered directory structures for loading context on demand, and a step-by-step example of building a job-search competitiveness diagnosis skill. You will also learn how to validate skills with typical, boundary, distraction, and stress test cases, plus common pitfalls and engineering practices such as keeping the entry file thin, pushing domain knowledge into references, and enforcing deterministic logic with scripts.
1. Why a Persona Prompt Is Not a Skill
Many teams build agents by stacking long background descriptions, role definitions, and tone requirements together, expecting the model to produce professional results consistently. This often works in demos, but three problems appear in real business scenarios: context bloat dilutes key information, vague task boundaries let the model improvise, and the lack of executable actions makes conclusions impossible to act on.
An ad-hoc prompt is essentially an instruction for a single session, and it expires when the session ends. A skill is a complete set of working habits attached to an agent. It defines not only how to answer, but also how to judge whether a task is applicable, which materials to consult, which scripts to call, which constraints to follow, and what criteria to use for accepting the result. The differences can be summarized as follows:
| Dimension | Ad-hoc Prompt | Skill |
|---|---|---|
| Lifecycle | Single session | Long-term reuse, versionable |
| Trigger | Manual paste | Automatic matching based on description |
| Content organization | Single block of text | Layered files, loaded on demand |
| Execution capability | Text generation only | Can call scripts and external resources |
| Quality assurance | Relies on manual review | Built-in acceptance criteria |
2. Minimal Viable Structure: A Single File Is Enough
The minimal form of a skill requires only one instruction file, with the following directory layout:
my-skill/└── SKILL.md
This file usually consists of two parts. The first part is the metadata section, which declares the name and description in YAML format. The description must clearly state “when this skill should be used,” which is the key basis for automatic triggering:
---name: career-diagnosisdescription: Use when a user needs to diagnose job-search competitiveness, identify resume problems, or create an improvement plan---
The second part is the body, which contains the operating instructions the agent reads once it starts working. The body generally includes four types of information: applicable and non-applicable scenarios, execution steps, constraints and prohibitions, and result acceptance criteria. The division is not mysterious; the key is to make sure the model always knows “what to do next and what it must not do” at every step.
3. Advanced Structure: Layered Loading and Resource Fallback
As task complexity grows, a single file expands quickly. At this point, you should introduce directory layering:
my-skill/├── SKILL.md # Entry: trigger conditions and main workflow├── agents/ # Profile: adaptation notes for different runtime environments├── references/ # Knowledge base: specs, templates, domain materials├── scripts/ # Tool layer: executable deterministic logic└── assets/ # Asset layer: template files, sample outputs
The responsibilities of each layer must be strictly separated. The entry file stays concise and only decides “whether it applies” and “in what order to proceed.” Adaptation notes declare behavioral differences across runtime environments, acting as the skill’s profile. Knowledge materials are large and updated frequently, so they belong in the references directory and should be read on demand to avoid occupying context all at once. Deterministic logic (such as format validation, data statistics, and batch renaming) is handed to scripts; models are not good at precise computation but are good at orchestration and explanation. The assets directory stores reusable templates to keep output style consistent.
This layering brings three direct benefits: first, context cost stays controllable because the model loads only the relevant fragment when needed; second, maintenance cost drops because changing domain materials does not require touching the main workflow; third, reliability improves because key steps are backed by scripts, leaving less room for hallucination.
4. Example: Building a Job-Search Competitiveness Diagnosis Skill
Take “AI application role job-search diagnosis” as an example to illustrate the full implementation process.
Step 1: Define the boundary. The skill only handles “diagnosis and planning” and does not take on tasks beyond its capability, such as job recommendations or salary prediction. When input is missing, ask first instead of guessing.
Step 2: Design the main workflow. It is recommended to split it into five stages: information collection (resume, project experience, target role) → capability modeling (scoring across general role competency dimensions) → gap identification (finding key weaknesses) → solution design (scheduling learning and practice tasks) → result acceptance (self-check against a checklist).
Step 3: Build up reference materials. Put the scoring dimensions, a checklist of common resume problems, and a project review template into the references directory. The body only states “which file to read and how to use it,” avoiding stuffing long text into the entry.
Step 4: Use scripts as a fallback. For example, counting resume word count, checking whether project descriptions contain quantifiable results, and generating a progress table can all be handled by scripts:
# Example: check whether project descriptions contain quantitative informationimport re, sysdef has_metric(text: str) -> bool:return bool(re.search(r"\d+\s*(%|ms|万|人|次)", text))if __name__ == "__main__":content = open(sys.argv[1], encoding="utf-8").read()print("Number of paragraphs missing quantitative results:", sum(not has_metric(p) for p in content.split("\n\n")))
Step 5: Define acceptance criteria. The output must include a capability score, three key weaknesses, and an executable two-week plan, with every recommendation pointing to a specific action. Otherwise, it is considered unqualified and must be redone.
5. How to Verify Whether a Skill Is Reliable
Verification should cover four types of cases rather than only the “happy path.” The first type is typical cases, confirming the main workflow runs through. The second type is boundary cases, such as severely insufficient information or a vague target role description. The third type is distraction cases, where the user makes a request unrelated to the skill, testing whether it is wrongly triggered. The fourth type is stress cases, with overly long or messy input, testing whether layered loading and script fallback work.
Three metrics are recommended and should stay fixed: trigger accuracy (used when it should be, not used when it should not), workflow completeness (whether it proceeds through the defined steps and produces acceptance items), and manual rework rate (the proportion of results that need manual modification). After each skill change, regress all cases to form comparable version records.
6. Common Pitfalls and Engineering Recommendations
First, writing a skill as an encyclopedia: the entry file runs to thousands of words, drowning key constraints. Second, missing negative descriptions, so the model cannot tell when it should not intervene. Third, handing deterministic work to the model, producing unstable results. Fourth, writing only “be professional” without verifiable acceptance items. Fifth, ignoring version management, mixing the skill with reference materials so problems cannot be traced.
Three engineering principles can be followed: thin entry, thick references, hard scripts. The entry keeps only trigger conditions and the workflow skeleton; domain knowledge sinks into the references; any logic that can be determined by code is scripted. Also establish a change log and a case set for the skill so it can be reviewed, tested, and iterated like ordinary code.
Once you master these methods, a skill is no longer “a longer prompt” but a capability unit with clear boundaries, layered resources, executable actions, and verifiable results. This is also the key step for an agent to move from demo to production.
