prompt-engineering
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePrompt Engineering for Agentic Systems
面向智能体系统的提示词工程
Overview
概述
Generate optimized prompts for agentic systems with clear rationale for technique selection.
Core Principles:
- Match technique to task - Different agent types require different prompting approaches
- Trade-offs matter - Always consider cost, latency, and accuracy when selecting techniques
- Structure over verbosity - Well-organized prompts outperform long unstructured ones
- Test and iterate - Verify prompts work before deploying to production
For broader agentic system design (choosing workflows vs agents, ACI/tool specifications, guardrails, multi-agent patterns), see the ai-engineering skill.
生成针对智能体系统的优化提示词,并说明技术选择的理由。
核心原则:
- 匹配技术与任务——不同类型的智能体需要不同的提示词方法
- 权衡利弊——选择技术时始终要考虑成本、延迟和准确性
- 结构优于冗长——组织良好的提示词效果优于冗长无结构的提示词
- 测试与迭代——部署到生产环境前需验证提示词的有效性
如需更全面的智能体系统设计(选择工作流vs智能体、ACI/工具规范、防护机制、多智能体模式),请查看ai-engineering skill。
When to Use
适用场景
Invoke this skill when:
- Creating prompts for tool-using agents (ReAct pattern)
- Designing prompts for planning or strategy agents
- Building prompts for data processing or validation agents
- Reducing hallucinations in fact-based tasks
- Optimizing prompt performance or cost
在以下情况调用本技能:
- 为工具型智能体(ReAct模式)创建提示词
- 为规划或策略型智能体设计提示词
- 为数据处理或验证型智能体构建提示词
- 在事实类任务中减少幻觉
- 优化提示词的性能或成本
Common Scenarios
常见场景
Scenario 1: Tool-Using Agent (ReAct)
场景1:工具型智能体(ReAct)
Use when: Agent needs to reason and use tools autonomously
markdown
undefined适用场景:智能体需要自主推理并使用工具
markdown
undefinedSYSTEM
SYSTEM
You are a research agent. Your goal is to gather information and synthesize findings.
You are a research agent. Your goal is to gather information and synthesize findings.
INSTRUCTIONS
INSTRUCTIONS
Follow this pattern for each action:
Thought: [what you want to do]
Action: [tool name and parameters]
Observation: [result from tool]
When you have enough information, provide a final summary.
Follow this pattern for each action:
Thought: [what you want to do]
Action: [tool name and parameters]
Observation: [result from tool]
When you have enough information, provide a final summary.
AVAILABLE TOOLS
AVAILABLE TOOLS
- search(query): Search for information
- read(url): Read a webpage
- finish(summary): Complete the task
- search(query): Search for information
- read(url): Read a webpage
- finish(summary): Complete the task
STOP CONDITION
STOP CONDITION
Stop when you have answered the user's question or gathered sufficient information.
---Stop when you have answered the user's question or gathered sufficient information.
---Scenario 2: Planning Agent (Tree of Thoughts)
场景2:规划智能体(Tree of Thoughts)
Use when: Agent needs to explore multiple approaches before committing
markdown
undefined适用场景:智能体需要在执行前探索多种方案
markdown
undefinedTASK
TASK
Design a migration strategy from monolith to microservices.
Design a migration strategy from monolith to microservices.
INSTRUCTIONS
INSTRUCTIONS
Generate 3 different approaches:
Approach 1: [description]
- Pros: [list]
- Cons: [list]
- Effort: [estimate]
Approach 2: [description]
- Pros: [list]
- Cons: [list]
- Effort: [estimate]
Approach 3: [description]
- Pros: [list]
- Cons: [list]
- Effort: [estimate]
Then select the best approach and explain your reasoning.
---Generate 3 different approaches:
Approach 1: [description]
- Pros: [list]
- Cons: [list]
- Effort: [estimate]
Approach 2: [description]
- Pros: [list]
- Cons: [list]
- Effort: [estimate]
Approach 3: [description]
- Pros: [list]
- Cons: [list]
- Effort: [estimate]
Then select the best approach and explain your reasoning.
---Scenario 3: Data Validation (Few-Shot with Negative Examples)
场景3:数据验证(带负例的少样本提示)
Use when: Agent needs consistent output format and should avoid common errors
markdown
undefined适用场景:智能体需要输出格式一致,且需避免常见错误
markdown
undefinedTASK
TASK
Validate email addresses and return structured JSON.
Validate email addresses and return structured JSON.
VALID EXAMPLES
VALID EXAMPLES
Input: user@example.com
Output: {"valid": true, "reason": "proper email format"}
Input: user.name@company.co.uk
Output: {"valid": true, "reason": "proper email format"}
Input: user@example.com
Output: {"valid": true, "reason": "proper email format"}
Input: user.name@company.co.uk
Output: {"valid": true, "reason": "proper email format"}
INVALID EXAMPLES (what NOT to accept)
INVALID EXAMPLES (what NOT to accept)
Input: user@.com
Output: {"valid": false, "reason": "invalid domain format"}
Input: @example.com
Output: {"valid": false, "reason": "missing local part"}
Input: user example.com
Output: {"valid": false, "reason": "missing @ symbol"}
Input: user@.com
Output: {"valid": false, "reason": "invalid domain format"}
Input: @example.com
Output: {"valid": false, "reason": "missing local part"}
Input: user example.com
Output: {"valid": false, "reason": "missing @ symbol"}
NOW VALIDATE
NOW VALIDATE
Input: {user_input}
---Input: {user_input}
---Scenario 4: Factual Accuracy (Chain-of-Verification)
场景4:事实准确性(验证链,CoVe)
Use when: Reducing hallucinations is critical
markdown
undefined适用场景:减少幻觉至关重要
markdown
undefinedTASK
TASK
Explain how transformers handle long-context windows
Explain how transformers handle long-context windows
STEP 1: Initial Answer
STEP 1: Initial Answer
Provide your explanation...
Provide your explanation...
STEP 2: Verification Questions
STEP 2: Verification Questions
Generate 5 questions that would expose errors in your answer:
- [question]
- [question]
- [question]
- [question]
- [question]
Generate 5 questions that would expose errors in your answer:
- [question]
- [question]
- [question]
- [question]
- [question]
STEP 3: Answer Verification
STEP 3: Answer Verification
Answer each verification question factually...
Answer each verification question factually...
STEP 4: Final Answer
STEP 4: Final Answer
Refine your original answer based on verification results...
---Refine your original answer based on verification results...
---Scenario 5: Complex Decision (Structured Thinking)
场景5:复杂决策(结构化思维)
Use when: Agent needs to analyze trade-offs before deciding
markdown
undefined适用场景:智能体需要在决策前分析权衡利弊
markdown
undefinedTASK
TASK
Recommend: microservices or monolith for our startup?
Recommend: microservices or monolith for our startup?
THINKING PROTOCOL
THINKING PROTOCOL
[UNDERSTAND]
- Restate the problem in your own words
- Identify what's actually being asked
[ANALYZE]
- Break down into sub-components
- Note assumptions and constraints
[STRATEGIZE]
- Outline 2-3 approaches
- Evaluate trade-offs
[EXECUTE]
- Provide final recommendation
- Explain reasoning
---[UNDERSTAND]
- Restate the problem in your own words
- Identify what's actually being asked
[ANALYZE]
- Break down into sub-components
- Note assumptions and constraints
[STRATEGIZE]
- Outline 2-3 approaches
- Evaluate trade-offs
[EXECUTE]
- Provide final recommendation
- Explain reasoning
---Scenario 6: Self-Improving Output (Self-Refine)
场景6:自我优化输出(自我修正)
Use when: You want the agent to review and improve its own work
markdown
undefined适用场景:希望智能体审核并改进自身输出
markdown
undefinedTASK
TASK
Write a README for the checkout API
Write a README for the checkout API
STEP 1: Initial Draft
STEP 1: Initial Draft
[Generate initial README]
[Generate initial README]
STEP 2: Critique
STEP 2: Critique
Identify 3-5 improvements needed:
- [weakness 1]
- [weakness 2]
- [weakness 3]
Identify 3-5 improvements needed:
- [weakness 1]
- [weakness 2]
- [weakness 3]
STEP 3: Refinement
STEP 3: Refinement
Rewrite addressing all identified improvements...
---Rewrite addressing all identified improvements...
---Quick Decision Tree
快速决策树
Use this table to select techniques quickly:
| Agent Characteristic | Recommended Technique |
|---|---|
| Uses tools autonomously | ReAct |
| Planning/strategy with alternatives | Tree of Thoughts |
| High-stakes correctness | Self-Consistency |
| Factual accuracy, hallucination reduction | Chain-of-Verification (CoVe) |
| Single-path complex reasoning | Chain of Thought |
| Complex decisions with trade-offs | Structured Thinking Protocol |
| Reducing bias, multiple viewpoints | Multi-Perspective Prompting |
| Uncertainty quantification | Confidence-Weighted Prompting |
| Proprietary documentation, prevent hallucinations | Context Injection with Boundaries |
| Self-review and improvement | Self-Refine |
| Breaking complex problems into subproblems | Least-to-Most Prompting |
| High-quality content through multiple passes | Iterative Refinement Loop |
| Multi-stage workflows with specialized prompts | Prompt Chaining |
| Improving recall for factual questions | Generated Knowledge Prompting |
| Unclear how to structure the prompt | Meta-Prompting (nuclear option) |
| Strict technical requirements | Constraint-First Prompting |
| Requires consistent format/tone | Few-Shot (supports negative examples) |
| Simple, well-defined task | Zero-Shot |
| Domain-specific expertise | Role Prompting |
| Procedural workflow | Instruction Tuning |
For detailed decision logic with branching, see decision-tree.md
使用下表快速选择技术:
| 智能体特征 | 推荐技术 |
|---|---|
| 自主使用工具 | ReAct |
| 需规划/策略与多方案 | Tree of Thoughts |
| 高风险场景下的正确性 | Self-Consistency |
| 事实准确性、减少幻觉 | Chain-of-Verification (CoVe) |
| 单路径复杂推理 | Chain of Thought |
| 需权衡利弊的复杂决策 | 结构化思维协议 |
| 减少偏见、多视角 | 多视角提示法 |
| 不确定性量化 | 置信度加权提示法 |
| 专有文档、防止幻觉 | 带边界的上下文注入 |
| 自我审核与改进 | Self-Refine |
| 将复杂问题拆解为子问题 | 由易到难提示法 |
| 多轮生成高质量内容 | 迭代优化循环 |
| 多阶段工作流与专用提示词 | 提示词链式调用 |
| 提升事实问题的召回率 | 生成式知识提示法 |
| 不清楚如何构建提示词 | 元提示法(终极方案) |
| 严格技术要求 | 约束优先提示法 |
| 需一致格式/语气 | 少样本提示(支持负例) |
| 简单、定义明确的任务 | 零样本提示 |
| 领域特定专业知识 | 角色提示法 |
| 流程化工作流 | 指令微调 |
如需带分支的详细决策逻辑,请查看 decision-tree.md
Technique Reference
技术参考
All available techniques with examples, use cases, and risks: techniques.md
所有可用技术的示例、适用场景与风险:techniques.md
Critical Anti-Patterns
关键反模式
Common mistakes to avoid: anti-patterns.md
Critical warnings:
- Do NOT use ReAct without tools - Adds unnecessary complexity
- Do NOT use Tree of Thoughts for deterministic problems - Single correct answer doesn't need alternatives
- Do NOT use vague roles - "Expert" without scope provides little benefit
- Do NOT omit stop conditions - Agents may continue indefinitely
- Do NOT use Self-Refine for objective tasks - Calculations don't need self-critique
需避免的常见错误:anti-patterns.md
关键警告:
- 请勿在无工具的情况下使用ReAct——会增加不必要的复杂度
- 请勿在确定性问题中使用Tree of Thoughts——有唯一正确答案时无需多方案
- 请勿使用模糊角色——无明确范围的“专家”几乎没有价值
- 请勿省略停止条件——智能体可能无限运行
- 请勿在客观任务中使用Self-Refine——计算类任务不需要自我批判
Canonical Template
标准模板
Use this template as the foundation for generated prompts: template.md
Basic structure:
markdown
undefined使用本模板作为生成提示词的基础:template.md
基本结构:
markdown
undefinedSYSTEM / ROLE
SYSTEM / ROLE
You are a [specific role] with authority over [explicit scope]
Boundaries: [what you must NOT do]
You are a [specific role] with authority over [explicit scope]
Boundaries: [what you must NOT do]
TASK
TASK
[Single clear goal in one sentence]
[Single clear goal in one sentence]
INSTRUCTIONS
INSTRUCTIONS
Follow these steps:
- [First step]
- [Second step]
Constraints:
- [Specific limits]
- [Format requirements]
Follow these steps:
- [First step]
- [Second step]
Constraints:
- [Specific limits]
- [Format requirements]
STOP CONDITION
STOP CONDITION
Stop when: [success criteria]
undefinedStop when: [success criteria]
undefinedOutput Rationale Template
输出理由模板
When delivering a generated prompt, use this structure:
markdown
undefined交付生成的提示词时,请使用以下结构:
markdown
undefinedGenerated Prompt for [Agent Name/Type]
Generated Prompt for [Agent Name/Type]
[prompt in code block]
[prompt in code block]
Rationale
Rationale
Agent Type: [Tool-using / Planner / Conversational / Data-processor]
Task Complexity: [Simple / Multi-step / Planning-heavy]
Techniques Used:
- [Technique]: [Why it works for this use case]
Expected Behavior: [What the agent will do]
Trade-offs: [Cost, latency, flexibility - ALWAYS include if technique increases tokens or latency]
Considerations: [Edge cases, limitations, or risks]
undefinedAgent Type: [Tool-using / Planner / Conversational / Data-processor]
Task Complexity: [Simple / Multi-step / Planning-heavy]
Techniques Used:
- [Technique]: [Why it works for this use case]
Expected Behavior: [What the agent will do]
Trade-offs: [Cost, latency, flexibility - ALWAYS include if technique increases tokens or latency]
Considerations: [Edge cases, limitations, or risks]
undefinedGuardrail Rule
防护规则
If a prompt increases latency, token usage, or operational cost, this MUST be stated explicitly in the rationale under "Trade-offs."
Techniques that increase cost/latency:
- Self-Consistency (multiple generations)
- Chain-of-Verification (multiple passes)
- Iterative Refinement Loop (multiple passes)
- Self-Refine (multiple passes)
- Tree of Thoughts (exploring alternatives)
- Least-to-Most Prompting (sequential subproblems)
如果提示词会增加延迟、token使用量或运营成本,必须在理由的“权衡利弊”部分明确说明。
会增加成本/延迟的技术:
- Self-Consistency(多轮生成)
- Chain-of-Verification(多轮验证)
- 迭代优化循环(多轮生成)
- Self-Refine(多轮修正)
- Tree of Thoughts(探索多方案)
- 由易到难提示法(顺序处理子问题)