AgentSkillsCN

prompt-engineering

提示工程模式,用于编写代理提示与技能文件——约束预算、注册切换、HARD GATE 模式、反人格。在编写或审核 agents/*.md 或 skills/*/SKILL.md 时使用。触发条件:代理提示、技能文件、提示工程、模型层级补偿、HARD GATE、提示质量。不触发条件:面向用户的文档、README、CHANGELOG、配置文件。

SKILL.md
--- frontmatter
name: prompt-engineering
description: "Prompt engineering patterns for writing agent prompts and skill files — constraint budgets, register shifting, HARD GATE patterns, anti-personas. Use when writing or reviewing agents/*.md or skills/*/SKILL.md. TRIGGER when: agent prompt, skill file, prompt engineering, model-tier compensation, HARD GATE, prompt quality. DO NOT TRIGGER when: user-facing docs, README, CHANGELOG, config files."
allowed-tools: [Read, Grep, Glob]

Prompt Engineering Patterns

Compact, actionable patterns for writing agent prompts and skill files. See docs/PROMPT-ENGINEERING.md for full rationale and academic citations.


Constraint Budget (MOSAIC finding)

RangeCompliance
1–6Reliable
7–15Unpredictable
>15Degraded

Rule: Max 6 hard constraints per section. Hard gates at the END of sections (Claude recency effect).


Register Shifting Checklist

Before finalizing any hard gate or enforcement directive, verify the verbs:

  • Tier 1 (deep): audit, verify, critically analyse, enumerate — use for HARD GATEs
  • Tier 2 (balanced): review, check, describe — use for standard task instructions
  • Tier 3 (minimal): look at, mention, note — advisory only; never in enforcement

FORBIDDEN: Tier 3 verbs in REQUIRED or FORBIDDEN lists.


Persona Anti-Pattern

FORBIDDEN for analytical agents (reviewers, auditors, analysts, planners):

  • You are a [role]... persona prefixes
  • Act as an expert in... framing
  • Imagine you are... setups

Source: PRISM (arxiv:2603.18507) — expert personas reduce knowledge-retrieval accuracy for analytical tasks.

Correct pattern: Role description + behavioral directive.

code
# BAD
You are a senior security engineer. Review this code.

# GOOD
Perform a security audit. Enumerate all CWE categories present.

HARD GATE Pattern Template

markdown
### HARD GATE: [Topic]

**[One-sentence scope statement]**

**REQUIRED** (all must be met):
- Specific action A
- Specific action B

**FORBIDDEN** — You MUST NOT do any of the following:
- ❌ You MUST NOT [prohibited action]
- ❌ You MUST NOT [prohibited action]

**Why**: [One sentence — increases compliance]

Model-Tier Compensation Template

xml
<model-tier-compensation tier="[haiku|sonnet|opus]">
## Model-Tier Behavioral Constraints ([Tier Name])

- Do NOT [specific tendency to suppress].
- ALWAYS [specific required behavior].
</model-tier-compensation>

Rules:

  • Include tier attribute for automated validation
  • No meta-commentary about model weaknesses (model-visible; may reinforce behavior)
  • Actionable directives only — positive framing where possible
  • Place at TOP of agent prompt before role description

Self-Refine Loop (when quality matters)

Use for planning, security scans, and architecture tasks. 2–3 passes optimal (NeurIPS 2023).

markdown
## Pass 1: GENERATE
[Initial output]

## Pass 2: FEEDBACK
Critically analyse Pass 1. Enumerate:
- Gaps (missing)
- Errors (wrong)
- Ambiguities (unclear)

## Pass 3: REFINE
Apply Pass 2 feedback. Produce final output.

Anti-pattern: "Review your answer and improve it" — Tier 3, will be ignored. Use Tier 1: "Critically analyse for gaps and enumerate missing cases."


Stick+Carrot Pattern

Every block (hook or agent) MUST include a required next action:

code
# STICK only (bad)
BLOCKED: Cannot edit agents/*.md outside the pipeline.

# STICK + CARROT (good)
BLOCKED: Cannot edit agents/*.md outside the pipeline.
REQUIRED NEXT ACTION: Use /implement to run the pipeline with your changes.

Hook JSON format:

json
{
  "decision": "block",
  "reason": "What failed and why.",
  "requiredNextAction": "Specific step to take next."
}

Anti-Patterns Summary

Anti-PatternWhy WrongFix
>15 constraints per sectionMOSAIC: degraded complianceSplit into subsections ≤6 each
Persona prefix for analytical tasksPRISM: reduces accuracyRole description + directive
Hedge words in hard gatesWeakens enforcementDelete or replace with MUST
Prose-buried constraintsLow complianceConvert to numbered list
Meta-commentary about model weaknessesMay reinforce behaviorReframe as behavioral directive
Block without carrotModel loopsAdd REQUIRED NEXT ACTION

Cross-Reference

See docs/PROMPT-ENGINEERING.md for:

  • Full MOSAIC constraint budget analysis
  • PRISM persona findings detail
  • Self-Refine NeurIPS 2023 citations
  • XML sectioning rationale
  • Complete anti-pattern catalog