AgentSkillsCN

prompt-engineering

针对 LLM 交互进行高级提示工程。当您需要:(1) 为 Claude Code 或其他代理编写系统提示、命令、钩子或技能;(2) 为子代理、工具描述,或多代理工作流创建提示;(3) 设计具有结构化输出(JSON、XML)的生产级提示模板;(4) 优化提示的准确性、一致性或令牌效率;(5) 实施少样本学习、思维链或其他提示技巧;(6) 利用 Claude 特有的功能,如扩展思考或提示缓存。内置常用模式的可复用模板。

SKILL.md
--- frontmatter
name: prompt-engineering
description: >
  Advanced prompt engineering for LLM interactions. Use this skill when:
  (1) Writing system prompts, commands, hooks, or skills for Claude Code or other agents,
  (2) Creating prompts for sub-agents, tool descriptions, or multi-agent workflows,
  (3) Designing production prompt templates with structured outputs (JSON, XML),
  (4) Optimizing prompts for accuracy, consistency, or token efficiency,
  (5) Implementing few-shot learning, chain-of-thought, or other prompting techniques,
  (6) Working with Claude-specific features like extended thinking or prompt caching.
  Includes reusable templates for common patterns.

Prompt Engineering

Techniques to maximize LLM performance, reliability, and controllability.

Quick Reference

TechniqueWhen to UseReference
Few-ShotConsistent formatting, classificationreferences/core-techniques.md
Chain-of-ThoughtMulti-step reasoning, math, debuggingreferences/core-techniques.md
Structured OutputJSON/XML parsing, schema enforcementreferences/structured-outputs.md
Tool DescriptionsFunction calling, agent toolsreferences/tool-use-prompting.md
Extended ThinkingComplex analysis, deep reasoningreferences/claude-specific.md
Prompt CachingRepeated prompts, cost optimizationreferences/claude-specific.md

Core Principles

1. Be Specific — Vague prompts → inconsistent results

2. Show, Don't Tell — Examples outperform descriptions

3. Structure Matters — Use XML tags, clear delimiters, consistent formatting

4. Start Simple — Add complexity only when needed

5. Test Broadly — Diverse inputs including edge cases

Instruction Hierarchy

code
[System Context] → [Task] → [Examples] → [Input] → [Output Format]

Put stable instructions in system prompts. Reserve user messages for variable content.

Key Patterns

Progressive Disclosure

  1. Direct instruction
  2. Add constraints
  3. Add reasoning steps
  4. Add examples

Error Recovery

Include: fallback instructions, confidence handling, missing info behavior.

markdown
If information is missing: [specify fallback]
If uncertain: [specify behavior]
If task cannot be completed: [specify response]

References

FileContent
references/core-techniques.mdFew-shot, chain-of-thought, optimization
references/structured-outputs.mdJSON, XML, schemas, parsing
references/tool-use-prompting.mdTool descriptions, parameters, orchestration
references/claude-specific.mdExtended thinking, caching, artifacts
references/agent-prompting.mdContext window, degrees of freedom
references/persuasion-principles.mdAuthority, commitment, compliance patterns

Templates

Reusable templates in assets/templates/:

TemplateUse Case
system-prompt.mdSystem prompt structure
tool-description.mdTool/function definitions
few-shot-classifier.mdClassification with examples
agent-task.mdAgent/sub-agent task prompts

Common Pitfalls

  • Over-engineering before trying simple prompts
  • Example pollution (examples don't match target)
  • Context overflow (too many examples)
  • Ambiguous instructions without examples
  • Missing error/edge case handling

Performance Tips

Token efficiency:

  • Remove redundant words
  • Use abbreviations after first definition
  • Move stable content to system prompts
  • Use prompt caching for repeated prefixes

Latency:

  • Minimize prompt length
  • Use streaming for long outputs
  • Cache common prompt prefixes