Building Reusable Agent Workflows with Declarative Instruction Files

    As AI agents move from demos into production, teams repeatedly re-explain the same task conventions—code review order, release note formats, bug fix standards—across sessions and projects. This article explains how a declarative instruction layer solves the problem: designing instruction files, multi-level directory discovery, minimal templates, trigger and loading strategies, and team-level reuse and governance practices. Learn how to standardize high-frequency agent workflows without writing runtime code.

    Building Reusable Agent Workflows with Declarative Instruction Files

    As agent applications move from demos toward production engineering, a recurring pain point keeps surfacing: the same class of task gets described verbally over and over across different sessions, team members, and projects. In what order should a code review be conducted? Which fields should release notes include? What standards should a bug fix follow? This knowledge ends up scattered across documents, chat logs, and personal experience, and it has to be re-taught to the model every time. The result is unstable output quality, team conventions that never accumulate, and maintenance costs that grow linearly with the number of projects.

    A common solution is to add a declarative instruction layer on top of the model and tools:固化”一类任务应该按什么步骤完成”为一份框架能够发现、解析并按需加载的本地文件。以通用代理编排框架的设计模式为背景,本指南详细介绍了此类指令文件的设计原则、目录发现机制、最小可行模板、触发和加载策略,以及团队层面的复用与治理实践。

    1. First, Clarify the Boundary: Instructions and Plugins Solve Different Problems

    Before designing any reuse mechanism, answer a basic question: should this capability be an instruction or a plugin?

    The instruction layer answers “in what steps should a task be completed.” It uses primarily natural language, supported by structured metadata, to describe workflows, checklists, output formats, and boundary conditions. It requires no runtime code and does not register new tools. Once loaded, it enters the current conversation context as instruction text, guiding the agent to invoke capabilities that already exist—file read/write, command execution, code search, or external tools.

    The plugin layer answers “what capability to add at runtime.” It typically requires writing code, registering tools, and declaring permissions, solving the problem of “something the agent cannot do today.”

    The division of labor can be summed up in one sentence: plugins extend capability boundaries; instructions converge execution paths. A team can standardize high-frequency tasks—code review workflows, release note templates, incident retrospective formats, API change checklists—purely through instruction files, without writing any runtime code. This is the core value of a declarative instruction layer: low barrier to entry, easy to review, versionable, and decoupled from any specific model.

    One important caveat: instruction files should not try to replace the tools themselves. They are closer to a “work instruction document” that tells the agent, under what conditions, which existing capabilities to use, in what order, and producing what kind of output. Writing instructions as tool-calling scripts would lose the flexibility of cross-model, cross-tool reuse.

    2. Directory Tiering and Discovery Order: Let Conventions Follow the Project

    Where an instruction file lives determines its visibility scope and priority. Mature frameworks typically adopt a multi-level directory discovery strategy, organized by “project-level → custom-level → user-level,” with a rank value resolving name conflicts.

    A typical tiered design looks like this:

    • Project-level framework-specific directory (e.g., a skills subdirectory inside the dot-prefixed framework directory at the project root): smallest rank value, highest priority—well suited to conventions committed with the project and evolving alongside the code.
    • Project-level generic agent directory (e.g., a skills subdirectory inside the dot-prefixed generic agents directory at the project root): next rank value, suitable for instructions shared across multiple agent tools.
    • Custom directories: explicitly specified via configuration, next rank value—well suited to a team’s private convention library or a cross-project sharing pool.
    • User-level framework-specific directory and user-level generic directory: larger rank values, lowest priority—suited to general-purpose workflows an individual accumulates over time.

    When instructions share a name, the source with the smaller rank value (higher priority) wins. This means project-level instructions can override user-level versions with the same name, guaranteeing that “project conventions take precedence over personal habits.” The mechanism seems simple, but it solves a key problem in engineering practice: the proximity principle for conventions. When team members switch between projects, they don’t need to manually switch instruction sets—the framework automatically selects the version closest to the current context based on directory hierarchy.

    Two practical recommendations for implementation: first, workflows tightly bound to a project (such as the project’s release note format or code layering constraints) belong in the project-level directory under version control; second, personal cross-project helper workflows (such as generic commit message polishing or document summarization formats) belong in the user-level directory to avoid polluting project repositories. Teams that need to maintain a set of cross-project conventions centrally can manage them through a custom directory and reference them via configuration in each project.

    3. A Minimal Viable Instruction File: Structure, Fields, and Body Writing

    An instruction file that can be correctly discovered and loaded typically consists of two parts: YAML frontmatter metadata and Markdown body instructions. The metadata is responsible for “being found” and “being judged applicable”; the body is responsible for “how to execute once loaded.”

    Below is a minimal viable example for a “release note generation” scenario. The filename matches the name in the metadata, using lowercase kebab-case naming:

    1. ---
    2. name: release-note
    3. description: Generate user-facing release notes from version diffs, covering changes, impact, and upgrade steps
    4. whenToUse: Use when the user asks to organize a changelog, release notes, or an announcement
    5. ---
    6. # Release Note Workflow
    7. 1. Read the code diff between the current branch and the previous release tag.
    8. 2. Categorize content into four groups: new features, bug fixes, compatibility changes, and upgrade actions.
    9. 3. Remove internal implementation details, temporary branch names, credentials, and ticket numbers.
    10. 4. Mark items with uncertain impact as "pending maintainer confirmation"—do not infer on your own.
    11. 5. Output a roughly 300-word summary, followed by the complete categorized list.
    12. 6. If the diff is empty, explicitly state "no user-visible changes in this version"—do not fabricate content.

    This template illustrates several design points worth reusing.

    First, write the description for “retrieval,” not for humans. It enters the conversation’s instruction catalog during the discovery phase, and the agent uses it to judge whether the current task matches. So the description should include the task object, the deliverable, and key constraints—avoid vague phrasing like “helps with release notes.”

    Second, write whenToUse as trigger conditions, not a restatement of the description. It answers “what signals should cause this instruction to load”—for example, an explicit user request, a matching task type, or modification of certain file types. The more specific the trigger conditions, the fewer false loads and missed loads.

    Third, write the body as an executable sequence of steps, not a statement of principles. “Ensure quality” has no operational meaning; “categorize into four groups, remove three types of information, mark uncertain items as pending confirmation” are executable constraints. Each step should have clear input, action, and output, with an output template provided where necessary.

    Fourth, write negative constraints explicitly. The value of an instruction file lies not only in telling the agent what to do, but also what not to do: don’t infer, don’t fabricate, don’t leak internal information, don’t modify files beyond authorization. Negative constraints should be as specific and verifiable as possible.

    4. Triggering and Loading: Spend Context Cost Where It Matters

    The lifecycle of an instruction file typically has three phases: discovery, catalog, and loading.

    In the discovery phase, the framework scans each directory tier, parses the frontmatter, and validates that the name and description are complete. In the catalog phase, names and brief descriptions are merged into the available instruction list for the current conversation. In the loading phase, the full body is injected into context only when a task matches the trigger conditions or the user explicitly invokes it.

    This “catalog resident, body on demand” design centers on context economy. If all instruction bodies were injected at the start of a conversation, long instructions would eat up the precious context window and could mislead the agent on unrelated tasks. Keeping only a brief catalog means the fixed overhead for everyday requests is small, and the full workflow loads only when actually needed—controlling cost while reducing interference between instructions.

    For triggering, two paths are typically used in combination:

    • Explicit invocation: the user names a specific instruction in the request—well suited to scenarios requiring strong process control, such as pre-release checks.
    • Semantic matching: the framework automatically loads an instruction based on the match between the task description and the instruction’s description and trigger conditions—well suited to seamless reuse of everyday high-frequency tasks.

    In practice, design clear trigger words and applicability boundaries for high-frequency instructions, and avoid heavy overlap between multiple instructions’ descriptions. If two instructions could both match the same request, specify priority or mutual exclusion conditions in the body to reduce runtime ambiguity.

    5. From a Single Template to Team Workflows: Reuse and Governance Practices

    When instruction files evolve from personal experiments into team assets, governance needs to catch up. Four practices are broadly applicable.

    First, review instruction files like code. Changes to instructions directly affect agent output, so they should go through the code review process—checking whether trigger conditions are too broad, negative constraints are sufficient, and output formats are backward compatible. Commit messages in version control should explain “why this workflow changed,” not just “the wording changed.”

    Second, control the responsibility boundary of each instruction. One instruction should solve one class of task. Mixing code review, release notes, and incident retrospectives into a single file makes trigger conditions hard to converge and the body hard to maintain. If multiple workflows share common constraints, extract them into a separate constraint document referenced by each instruction, rather than copy-pasting.

    Third, design verifiable structures for output. The more structured the output template in the instruction body, the easier subsequent manual review and automated validation become. For example, release notes fixed to four categories, code reviews fixed to four fields: “issue—location—recommendation—severity.” Structured output also makes instruction effectiveness sampleable for evaluation.

    Fourth, build a lightweight effectiveness feedback loop. Track how often instructions are triggered, the proportion of outputs manually modified, and common misuse scenarios; periodically feed these back into adjustments of trigger conditions or negative constraints. Instruction files are not static documents written once—they are process assets that evolve continuously with team practice.

    A final reminder: be honest about the capability boundaries of a declarative instruction layer. It is good at solidifying workflows and formats, not at replacing domain tools or runtime extensions. It relies on the model’s understanding of natural language instructions, so the precision of the wording directly affects stability. Placing the instruction layer in the right position—above the model and tools, below team conventions—is what makes “write once, reuse everywhere” a truly sustainable engineering habit.