[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$ft7rB3kn-3JbLUMoF4wOE7O_Jio_HOkl3l1uO1h4xJuM":3,"$fJU-4tot_gC5fDkujNeoE-cGsdMy5V_KcdUXLuAnTFgw":15,"$foNMnsSOMlOjWl2WYMVfAAQpEusRc0Ob0ZSgAAdTgryE":423},{"slug":4,"title":5,"description":6,"content":7,"content_html":8,"pub_date":9,"tags":10,"draft":14},"llm-prompt-engineering","Prompt Engineering 实战：让 LLM 真正听话的技巧","System prompt 怎么写、Few-shot 怎么设计、Chain-of-Thought 原理，以及常见失败模式和调试方法。","# Prompt Engineering 实战：让 LLM 真正听话的技巧\n\n> TL;DR：LLM 不是指令跟随机器，是概率下一词预测器。理解这一点，才能写出真正有效的 prompt。\n\n## 认知基础：LLM 是什么\n\nLLM（大语言模型）的本质是**概率模型**：给定前文，预测下一个 token 的概率分布。它从海量文本学到的是\"什么样的文字在统计上应该接在这段文字后面\"，而不是在执行你的指令。\n\n这个认知影响一切后续的 prompt 设计决策。\n\n## System Prompt 的作用域与局限\n\nSystem prompt 是对话开始时设置的\"角色说明\"，在 Chat 格式下位于 `system` role。\n\n**它能做什么：**\n- 设定角色和语气（\"你是一个严格的代码审查员\"）\n- 建立输出格式约定（\"始终用 JSON 回复\"）\n- 提供领域背景知识\n- 设定行为边界\n\n**它做不到的：**\n- 完全阻止越狱（jailbreak）\n- 保证长对话中指令始终被遵循（指令遗忘）\n- 覆盖训练时形成的深层倾向（sycophancy）\n\n```\n# 好的 System Prompt 结构\nYou are a senior backend engineer specializing in Go.\n\n## Your role\n- Review code for correctness, performance, and idioms\n- Point out potential race conditions and nil pointer issues\n\n## Output format\nFor each issue found:\n1. **Severity**: [Critical\u002FMajor\u002FMinor]\n2. **Location**: file:line\n3. **Issue**: brief description\n4. **Fix**: concrete suggestion\n\n## Constraints\n- Only comment on actual problems, not style preferences\n- If the code looks correct, say \"LGTM\" with a brief reason\n```\n\n## Instruction Following vs Role Playing vs In-context Learning\n\n三种不同的机制，适合不同场景：\n\n| 方式 | 原理 | 适合场景 |\n|------|------|---------|\n| Instruction Following | 直接描述任务要求 | 明确的单步任务 |\n| Role Playing | 让模型扮演某角色 | 需要特定风格\u002F视角 |\n| In-context Learning | 给例子让模型归纳 | 有规律但难描述的任务 |\n\n## Zero-shot \u002F One-shot \u002F Few-shot\n\n**选择逻辑：**\n\n```python\n# Zero-shot：任务简单或模型能力强时\nprompt = \"将以下英文翻译为中文：Hello, world!\"\n\n# One-shot：给一个示例校准风格\nprompt = \"\"\"\n翻译风格示例：\nEN: The system encountered an unexpected error.\nCN: 系统遭遇意外错误。\n\n请翻译：The connection timed out after 30 seconds.\n\"\"\"\n\n# Few-shot：任务有微妙规律时\nprompt = \"\"\"\n判断以下句子情感（考虑反讽）：\n\n\"这个产品真是太棒了，我的电脑崩了三次。\" -> 负面\n\"虽然外观普通，但性能超出预期。\" -> 正面\n\"又是一个让人热血沸腾的周一早晨。\" -> 负面（反讽）\n\n请判断：这次更新解决了旧 bug，又引入了两个新 bug。\n\"\"\"\n```\n\n**Few-shot 的注意事项：**\n- 例子数量：3-8 个通常足够，过多反而混淆\n- 例子质量 > 数量：边缘案例比重复普通例子更有价值\n- 顺序影响：模型对最后几个例子权重更高\n\n## Chain-of-Thought（CoT）：让模型先想再说\n\nCoT 核心思路：强迫模型生成中间推理步骤，而不是直接输出答案。\n\n```\n# 不带 CoT（容易出错的复杂推理）\nQ: 一家店有 23 个苹果，卖了 20 个，又进货了 6 个，现在有多少？\nA: 9\n\n# 带 CoT（更准确）\nQ: 一家店有 23 个苹果，卖了 20 个，又进货了 6 个，现在有多少？\n请一步步思考。\nA: \n初始：23 个\n卖出：23 - 20 = 3 个\n进货：3 + 6 = 9 个\n答案：9 个\n```\n\n**Zero-shot CoT**：简单加一句 \"Let's think step by step\" 或 \"请一步步思考\" 就能显著提升推理质量。\n\n**Self-consistency**：对同一问题生成多条推理路径，投票选最常见答案，准确率更高。\n\n## Structured Output\n\n强制模型输出结构化数据，减少解析不确定性。\n\n**方法一：JSON mode（OpenAI API）**\n```python\nresponse = client.chat.completions.create(\n    model=\"gpt-4o\",\n    response_format={\"type\": \"json_object\"},\n    messages=[\n        {\"role\": \"system\", \"content\": \"你是数据提取器，始终返回 JSON\"},\n        {\"role\": \"user\", \"content\": f\"从以下文本提取人名和日期：{text}\"}\n    ]\n)\n```\n\n**方法二：Function Calling \u002F Tool Use**\n```python\ntools = [{\n    \"type\": \"function\",\n    \"function\": {\n        \"name\": \"extract_person\",\n        \"description\": \"提取人物信息\",\n        \"parameters\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"name\": {\"type\": \"string\"},\n                \"age\": {\"type\": \"integer\"},\n                \"occupation\": {\"type\": \"string\"}\n            },\n            \"required\": [\"name\"]\n        }\n    }\n}]\n```\n\n**方法三：Prompt 约束**（不依赖 API 特性）\n\n要求输出严格的 JSON 格式，不要添加任何额外文字，直接输出 JSON 对象。\n\n## 参数实际意义\n\n```python\n# Temperature：控制随机性\n# 0.0 = 贪心解码，总选概率最高的词（适合代码、事实查询）\n# 0.7 = 适度随机（适合写作、对话）\n# 1.0+ = 高随机性（适合创意、头脑风暴）\ntemperature = 0.7\n\n# Top_p（nucleus sampling）：只从累计概率达到 p 的词集中采样\n# 与 temperature 类似效果，通常只用一个\ntop_p = 0.9\n\n# 实践建议：\n# - 代码生成：temperature=0, top_p=1\n# - 文本摘要：temperature=0.3\n# - 创意写作：temperature=0.8-1.0\n# - 不要同时调 temperature 和 top_p\n```\n\n## 常见失败模式\n\n### 1. 幻觉（Hallucination）\n模型生成听起来正确但实际错误的信息。\n- **对策**：要求模型引用来源；对事实敏感的任务加 RAG；要求模型表达不确定性\n\n### 2. 指令遗忘（Instruction Drift）\n长对话中模型逐渐忽略 system prompt 中的约束。\n- **对策**：重要指令在 user message 中重复；定期重置对话；使用 sliding window 时保留 system 部分\n\n### 3. 越狱（Jailbreak）\n通过角色扮演、假设情景等绕过安全限制。\n- **对策**：输出层二次审查；不要把安全完全依赖 prompt；使用模型自带的安全过滤\n\n### 4. Sycophancy（讨好倾向）\n模型倾向于同意用户，即使用户是错的。\n\n```python\n# 对策：明确要求批判性审查\nsystem_prompt = \"\"\"你是严格的代码审查员。即使用户认为代码没问题，\n你也必须独立评估，发现问题就直说。不要因为用户的判断而改变你的结论。\"\"\"\n```\n\n## 调试方法\n\n**A\u002FB 测试 prompt：**\n```python\nimport anthropic\n\ndef eval_prompt(system_prompt, test_cases):\n    client = anthropic.Anthropic()\n    scores = []\n    for case in test_cases:\n        response = client.messages.create(\n            model=\"claude-3-5-sonnet-20241022\",\n            max_tokens=1000,\n            system=system_prompt,\n            messages=[{\"role\": \"user\", \"content\": case[\"input\"]}]\n        )\n        score = evaluate_with_llm(response.content[0].text, case[\"expected\"])\n        scores.append(score)\n    return sum(scores) \u002F len(scores)\n\nscore_v1 = eval_prompt(prompt_v1, test_cases)\nscore_v2 = eval_prompt(prompt_v2, test_cases)\nprint(f\"V1: {score_v1:.2f}, V2: {score_v2:.2f}\")\n```\n\n**用更强模型评估弱模型输出：**\n```python\ndef evaluate_with_llm(output, expected_criteria):\n    judge_prompt = f\"\"\"\n评估以下输出是否满足标准（1-5分）：\n\n输出：{output}\n\n标准：{expected_criteria}\n\n只输出数字 1-5，不要解释。\n\"\"\"\n    response = strong_model.complete(judge_prompt)\n    return int(response.strip())\n```\n\n## 实用模板\n\n```\n# 通用 System Prompt 框架\n## 角色\n你是 [具体角色描述]。\n\n## 任务\n你的主要任务是 [任务描述]。\n\n## 输出格式\n[具体格式要求，最好给示例]\n\n## 约束条件\n- [限制1]\n- [限制2]\n- 如果遇到 [边界情况]，则 [处理方式]\n\n## 示例（可选）\nInput: [示例输入]\nOutput: [示例输出]\n```\n\n## 总结\n\nPrompt Engineering 的本质是**设计信息环境**，让模型的概率分布偏向你想要的输出。关键原则：\n\n1. **明确 > 隐晦**：不要期望模型猜测你的意图\n2. **示例 > 描述**：给一个例子胜过描述十条规则\n3. **结构化输出**：减少后处理的不确定性\n4. **CoT 推理**：复杂任务让模型先想再说\n5. **测试驱动**：建立评估集，量化 prompt 改进效果\n","\u003Ch1>Prompt Engineering 实战：让 LLM 真正听话的技巧\u003C\u002Fh1>\n\u003Cblockquote>\n\u003Cp>TL;DR：LLM 不是指令跟随机器，是概率下一词预测器。理解这一点，才能写出真正有效的 prompt。\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\u003Ch2 id=\"认知基础-llm-是什么\">认知基础：LLM 是什么\u003C\u002Fh2>\n\u003Cp>LLM（大语言模型）的本质是\u003Cstrong>概率模型\u003C\u002Fstrong>：给定前文，预测下一个 token 的概率分布。它从海量文本学到的是&quot;什么样的文字在统计上应该接在这段文字后面&quot;，而不是在执行你的指令。\u003C\u002Fp>\n\u003Cp>这个认知影响一切后续的 prompt 设计决策。\u003C\u002Fp>\n\u003Ch2 id=\"system-prompt-的作用域与局限\">System Prompt 的作用域与局限\u003C\u002Fh2>\n\u003Cp>System prompt 是对话开始时设置的&quot;角色说明&quot;，在 Chat 格式下位于 \u003Ccode>system\u003C\u002Fcode> role。\u003C\u002Fp>\n\u003Cp>\u003Cstrong>它能做什么：\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Cul>\n\u003Cli>设定角色和语气（“你是一个严格的代码审查员”）\u003C\u002Fli>\n\u003Cli>建立输出格式约定（“始终用 JSON 回复”）\u003C\u002Fli>\n\u003Cli>提供领域背景知识\u003C\u002Fli>\n\u003Cli>设定行为边界\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>\u003Cstrong>它做不到的：\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Cul>\n\u003Cli>完全阻止越狱（jailbreak）\u003C\u002Fli>\n\u003Cli>保证长对话中指令始终被遵循（指令遗忘）\u003C\u002Fli>\n\u003Cli>覆盖训练时形成的深层倾向（sycophancy）\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cpre>\u003Ccode># 好的 System Prompt 结构\nYou are a senior backend engineer specializing in Go.\n\n## Your role\n- Review code for correctness, performance, and idioms\n- Point out potential race conditions and nil pointer issues\n\n## Output format\nFor each issue found:\n1. **Severity**: [Critical\u002FMajor\u002FMinor]\n2. **Location**: file:line\n3. **Issue**: brief description\n4. **Fix**: concrete suggestion\n\n## Constraints\n- Only comment on actual problems, not style preferences\n- If the code looks correct, say &quot;LGTM&quot; with a brief reason\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2 id=\"instruction-following-vs-role-playing-vs-in-context-learning\">Instruction Following vs Role Playing vs In-context Learning\u003C\u002Fh2>\n\u003Cp>三种不同的机制，适合不同场景：\u003C\u002Fp>\n\u003Ctable>\n\u003Cthead>\n\u003Ctr>\n\u003Cth>方式\u003C\u002Fth>\n\u003Cth>原理\u003C\u002Fth>\n\u003Cth>适合场景\u003C\u002Fth>\n\u003C\u002Ftr>\n\u003C\u002Fthead>\n\u003Ctbody>\n\u003Ctr>\n\u003Ctd>Instruction Following\u003C\u002Ftd>\n\u003Ctd>直接描述任务要求\u003C\u002Ftd>\n\u003Ctd>明确的单步任务\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>Role Playing\u003C\u002Ftd>\n\u003Ctd>让模型扮演某角色\u003C\u002Ftd>\n\u003Ctd>需要特定风格\u002F视角\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>In-context Learning\u003C\u002Ftd>\n\u003Ctd>给例子让模型归纳\u003C\u002Ftd>\n\u003Ctd>有规律但难描述的任务\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftbody>\n\u003C\u002Ftable>\n\u003Ch2 id=\"zero-shot-one-shot-few-shot\">Zero-shot \u002F One-shot \u002F Few-shot\u003C\u002Fh2>\n\u003Cp>\u003Cstrong>选择逻辑：\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-python\"># Zero-shot：任务简单或模型能力强时\nprompt = &quot;将以下英文翻译为中文：Hello, world!&quot;\n\n# One-shot：给一个示例校准风格\nprompt = &quot;&quot;&quot;\n翻译风格示例：\nEN: The system encountered an unexpected error.\nCN: 系统遭遇意外错误。\n\n请翻译：The connection timed out after 30 seconds.\n&quot;&quot;&quot;\n\n# Few-shot：任务有微妙规律时\nprompt = &quot;&quot;&quot;\n判断以下句子情感（考虑反讽）：\n\n&quot;这个产品真是太棒了，我的电脑崩了三次。&quot; -&gt; 负面\n&quot;虽然外观普通，但性能超出预期。&quot; -&gt; 正面\n&quot;又是一个让人热血沸腾的周一早晨。&quot; -&gt; 负面（反讽）\n\n请判断：这次更新解决了旧 bug，又引入了两个新 bug。\n&quot;&quot;&quot;\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Few-shot 的注意事项：\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Cul>\n\u003Cli>例子数量：3-8 个通常足够，过多反而混淆\u003C\u002Fli>\n\u003Cli>例子质量 &gt; 数量：边缘案例比重复普通例子更有价值\u003C\u002Fli>\n\u003Cli>顺序影响：模型对最后几个例子权重更高\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2 id=\"chain-of-thought-cot-让模型先想再说\">Chain-of-Thought（CoT）：让模型先想再说\u003C\u002Fh2>\n\u003Cp>CoT 核心思路：强迫模型生成中间推理步骤，而不是直接输出答案。\u003C\u002Fp>\n\u003Cpre>\u003Ccode># 不带 CoT（容易出错的复杂推理）\nQ: 一家店有 23 个苹果，卖了 20 个，又进货了 6 个，现在有多少？\nA: 9\n\n# 带 CoT（更准确）\nQ: 一家店有 23 个苹果，卖了 20 个，又进货了 6 个，现在有多少？\n请一步步思考。\nA: \n初始：23 个\n卖出：23 - 20 = 3 个\n进货：3 + 6 = 9 个\n答案：9 个\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Zero-shot CoT\u003C\u002Fstrong>：简单加一句 “Let’s think step by step” 或 “请一步步思考” 就能显著提升推理质量。\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Self-consistency\u003C\u002Fstrong>：对同一问题生成多条推理路径，投票选最常见答案，准确率更高。\u003C\u002Fp>\n\u003Ch2 id=\"structured-output\">Structured Output\u003C\u002Fh2>\n\u003Cp>强制模型输出结构化数据，减少解析不确定性。\u003C\u002Fp>\n\u003Cp>\u003Cstrong>方法一：JSON mode（OpenAI API）\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-python\">response = client.chat.completions.create(\n    model=&quot;gpt-4o&quot;,\n    response_format={&quot;type&quot;: &quot;json_object&quot;},\n    messages=[\n        {&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;你是数据提取器，始终返回 JSON&quot;},\n        {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: f&quot;从以下文本提取人名和日期：{text}&quot;}\n    ]\n)\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>方法二：Function Calling \u002F Tool Use\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-python\">tools = [{\n    &quot;type&quot;: &quot;function&quot;,\n    &quot;function&quot;: {\n        &quot;name&quot;: &quot;extract_person&quot;,\n        &quot;description&quot;: &quot;提取人物信息&quot;,\n        &quot;parameters&quot;: {\n            &quot;type&quot;: &quot;object&quot;,\n            &quot;properties&quot;: {\n                &quot;name&quot;: {&quot;type&quot;: &quot;string&quot;},\n                &quot;age&quot;: {&quot;type&quot;: &quot;integer&quot;},\n                &quot;occupation&quot;: {&quot;type&quot;: &quot;string&quot;}\n            },\n            &quot;required&quot;: [&quot;name&quot;]\n        }\n    }\n}]\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>方法三：Prompt 约束\u003C\u002Fstrong>（不依赖 API 特性）\u003C\u002Fp>\n\u003Cp>要求输出严格的 JSON 格式，不要添加任何额外文字，直接输出 JSON 对象。\u003C\u002Fp>\n\u003Ch2 id=\"参数实际意义\">参数实际意义\u003C\u002Fh2>\n\u003Cpre>\u003Ccode class=\"language-python\"># Temperature：控制随机性\n# 0.0 = 贪心解码，总选概率最高的词（适合代码、事实查询）\n# 0.7 = 适度随机（适合写作、对话）\n# 1.0+ = 高随机性（适合创意、头脑风暴）\ntemperature = 0.7\n\n# Top_p（nucleus sampling）：只从累计概率达到 p 的词集中采样\n# 与 temperature 类似效果，通常只用一个\ntop_p = 0.9\n\n# 实践建议：\n# - 代码生成：temperature=0, top_p=1\n# - 文本摘要：temperature=0.3\n# - 创意写作：temperature=0.8-1.0\n# - 不要同时调 temperature 和 top_p\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2 id=\"常见失败模式\">常见失败模式\u003C\u002Fh2>\n\u003Ch3 id=\"1-幻觉-hallucination\">1. 幻觉（Hallucination）\u003C\u002Fh3>\n\u003Cp>模型生成听起来正确但实际错误的信息。\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>对策\u003C\u002Fstrong>：要求模型引用来源；对事实敏感的任务加 RAG；要求模型表达不确定性\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch3 id=\"2-指令遗忘-instruction-drift\">2. 指令遗忘（Instruction Drift）\u003C\u002Fh3>\n\u003Cp>长对话中模型逐渐忽略 system prompt 中的约束。\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>对策\u003C\u002Fstrong>：重要指令在 user message 中重复；定期重置对话；使用 sliding window 时保留 system 部分\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch3 id=\"3-越狱-jailbreak\">3. 越狱（Jailbreak）\u003C\u002Fh3>\n\u003Cp>通过角色扮演、假设情景等绕过安全限制。\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>对策\u003C\u002Fstrong>：输出层二次审查；不要把安全完全依赖 prompt；使用模型自带的安全过滤\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch3 id=\"4-sycophancy-讨好倾向\">4. Sycophancy（讨好倾向）\u003C\u002Fh3>\n\u003Cp>模型倾向于同意用户，即使用户是错的。\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-python\"># 对策：明确要求批判性审查\nsystem_prompt = &quot;&quot;&quot;你是严格的代码审查员。即使用户认为代码没问题，\n你也必须独立评估，发现问题就直说。不要因为用户的判断而改变你的结论。&quot;&quot;&quot;\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2 id=\"调试方法\">调试方法\u003C\u002Fh2>\n\u003Cp>\u003Cstrong>A\u002FB 测试 prompt：\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-python\">import anthropic\n\ndef eval_prompt(system_prompt, test_cases):\n    client = anthropic.Anthropic()\n    scores = []\n    for case in test_cases:\n        response = client.messages.create(\n            model=&quot;claude-3-5-sonnet-20241022&quot;,\n            max_tokens=1000,\n            system=system_prompt,\n            messages=[{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: case[&quot;input&quot;]}]\n        )\n        score = evaluate_with_llm(response.content[0].text, case[&quot;expected&quot;])\n        scores.append(score)\n    return sum(scores) \u002F len(scores)\n\nscore_v1 = eval_prompt(prompt_v1, test_cases)\nscore_v2 = eval_prompt(prompt_v2, test_cases)\nprint(f&quot;V1: {score_v1:.2f}, V2: {score_v2:.2f}&quot;)\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>用更强模型评估弱模型输出：\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-python\">def evaluate_with_llm(output, expected_criteria):\n    judge_prompt = f&quot;&quot;&quot;\n评估以下输出是否满足标准（1-5分）：\n\n输出：{output}\n\n标准：{expected_criteria}\n\n只输出数字 1-5，不要解释。\n&quot;&quot;&quot;\n    response = strong_model.complete(judge_prompt)\n    return int(response.strip())\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2 id=\"实用模板\">实用模板\u003C\u002Fh2>\n\u003Cpre>\u003Ccode># 通用 System Prompt 框架\n## 角色\n你是 [具体角色描述]。\n\n## 任务\n你的主要任务是 [任务描述]。\n\n## 输出格式\n[具体格式要求，最好给示例]\n\n## 约束条件\n- [限制1]\n- [限制2]\n- 如果遇到 [边界情况]，则 [处理方式]\n\n## 示例（可选）\nInput: [示例输入]\nOutput: [示例输出]\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2 id=\"总结\">总结\u003C\u002Fh2>\n\u003Cp>Prompt Engineering 的本质是\u003Cstrong>设计信息环境\u003C\u002Fstrong>，让模型的概率分布偏向你想要的输出。关键原则：\u003C\u002Fp>\n\u003Col>\n\u003Cli>\u003Cstrong>明确 &gt; 隐晦\u003C\u002Fstrong>：不要期望模型猜测你的意图\u003C\u002Fli>\n\u003Cli>\u003Cstrong>示例 &gt; 描述\u003C\u002Fstrong>：给一个例子胜过描述十条规则\u003C\u002Fli>\n\u003Cli>\u003Cstrong>结构化输出\u003C\u002Fstrong>：减少后处理的不确定性\u003C\u002Fli>\n\u003Cli>\u003Cstrong>CoT 推理\u003C\u002Fstrong>：复杂任务让模型先想再说\u003C\u002Fli>\n\u003Cli>\u003Cstrong>测试驱动\u003C\u002Fstrong>：建立评估集，量化 prompt 改进效果\u003C\u002Fli>\n\u003C\u002Fol>\n","2026-05-03",[11,12,13],"ai","llm","工程实践",false,[16,29,40,52,55,62,69,76,83,90,100,109,119,128,136,144,153,162,171,181,188,198,204,211,217,226,233,240,248,258,267,276,286,296,306,314,324,335,345,354,362,368,376,384,392,400,408,415],{"slug":17,"title":18,"description":19,"pub_date":20,"tags":21,"draft":14,"word_count":28},"ide-skills-guide","Agent Skills 完全指南：21 款第三方 Skill 深度评测与使用心得","全面评测 21 款第三方 Agent Skills，涵盖 Vue 生态、前端设计、构建工具、实用工具四大分类。从安装配置到实际使用场景，带你了解每个 Skill 的功能特点、最佳实践与使用心得。","2026-06-15",[22,23,24,25,26,27],"agent","skills","AI","效率工具","前端","Vue",4169,{"slug":30,"title":31,"description":32,"pub_date":33,"tags":34,"draft":14,"word_count":39},"linux-kernel-skeleton-struct-funcptr-container_of","Linux 内核骨架：struct、函数指针与 container_of","读懂 Linux 内核源码的三件套：巨大的 struct 组合代替继承、函数指针表实现虚派发、container_of 宏从嵌入成员找回完整对象。","2026-05-09",[35,36,37,38],"linux","kernel","C","container_of",1369,{"slug":41,"title":42,"description":43,"pub_date":44,"tags":45,"draft":14,"word_count":51},"astro-complete-guide-2025","Astro 5 深度剖析：Islands 架构原理、构建优化与 Cloudflare Workers 边缘部署","从编译器视角解析 Astro 5 的 Islands 架构实现原理，Content Layer API 的 Vite 插件机制，Server Islands 的流式渲染，以及如何在 Cloudflare Workers + D1 边缘环境下榨干性能。","2026-05-08",[46,47,48,49,50],"astro","frontend","cloudflare","performance","architecture",3663,{"slug":4,"title":5,"description":6,"pub_date":9,"tags":53,"draft":14,"word_count":54},[11,12,13],1723,{"slug":56,"title":57,"description":58,"pub_date":9,"tags":59,"draft":14,"word_count":61},"rag-system-design","RAG 系统设计：从 naive 到 production-ready","Retrieval-Augmented Generation 不只是「向量数据库 + LLM」，分块策略、召回质量、重排序、缓存才是工程核心。",[11,60,12,13],"rag",1613,{"slug":63,"title":64,"description":65,"pub_date":9,"tags":66,"draft":14,"word_count":68},"git-advanced-workflow","Git 进阶工作流：rebase、cherry-pick、bisect 的正确使用","merge 会了，但 rebase 总搞错？bisect 找 bug 提交？interactive rebase 整理历史？这篇一次说清楚。",[67,13],"git",1396,{"slug":70,"title":71,"description":72,"pub_date":9,"tags":73,"draft":14,"word_count":75},"docker-practical-guide","Docker 实战：从会用到用好","会 docker run 不够，Dockerfile 最佳实践、多阶段构建、Compose 编排、镜像瘦身才是日常真正需要的。",[74,35,13],"docker",1268,{"slug":77,"title":78,"description":79,"pub_date":9,"tags":80,"draft":14,"word_count":82},"anthropics-skills-guide","anthropics\u002Fskills：Anthropic 官方 Agent Skills 仓库解析","Anthropic 官方开源的 Agent Skills 标准仓库，127k stars，解析 SKILL.md 规范、17 个示例 skill 的设计模式，以及如何在 Claude Code \u002F Claude.ai \u002F API 中使用",[11,81,22,23],"Claude",2090,{"slug":84,"title":85,"description":86,"pub_date":9,"tags":87,"draft":14,"word_count":89},"karpathy-claude-code-guidelines","Karpathy 的 LLM 编码批评与 CLAUDE.md 最佳实践","基于 Andrej Karpathy 对 LLM 编程助手的观察，forrestchang 提炼出一个 CLAUDE.md 文件，4 条原则解决 AI 编码的典型失控问题：乱猜假设、过度设计、乱改代码、目标不清",[11,81,88,13],"Claude Code",2699,{"slug":91,"title":92,"description":93,"pub_date":9,"tags":94,"draft":14,"word_count":99},"typescript-advanced-patterns","TypeScript 高级模式：让类型系统为你工作","基础 TS 会了但类型总是 any？条件类型、映射类型、模板字面量类型、infer 关键字才是 TS 的真正威力。",[95,96,97,98],"typescript","类型系统","前端工程","高级模式",1419,{"slug":101,"title":102,"description":103,"pub_date":9,"tags":104,"draft":14,"word_count":108},"linux-performance-tuning","Linux 性能调优实战：从 top 到 perf 的完整工具链","遇到性能问题不知道从哪下手？这篇建立系统化的排查思路，从 CPU\u002F内存\u002FIO\u002F网络逐层分析。",[35,105,106,107],"性能","运维","系统编程",1524,{"slug":110,"title":111,"description":112,"pub_date":9,"tags":113,"draft":14,"word_count":118},"python-functional-programming","Python 函数式编程：map\u002Ffilter\u002Freduce 之外","Python 不是纯函数式语言，但 functools、itertools、偏函数、闭包这些工具用好了能让代码简洁一个量级。",[114,115,116,117],"python","函数式","闭包","装饰器",1867,{"slug":120,"title":121,"description":122,"pub_date":9,"tags":123,"draft":14,"word_count":127},"python-oop-guide","Python 面向对象：__init__ 之外你需要知道的","Python OOP 不只是 class + __init__，魔术方法、描述符、元类才是真正的武器。",[114,124,125,126],"OOP","面向对象","魔术方法",1792,{"slug":129,"title":130,"description":131,"pub_date":9,"tags":132,"draft":14,"word_count":135},"python-data-structures","Python 内置数据结构深度解析","list、dict、set、tuple 不只是数据容器，搞懂它们的底层实现和时间复杂度，才能写出高性能 Python。",[114,133,105,134],"数据结构","算法",1517,{"slug":137,"title":138,"description":139,"pub_date":9,"tags":140,"draft":14,"word_count":143},"python-basics-quick-start","Python 快速上手：写给有编程基础的人","已经会其他语言，想快速掌握 Python 的语法特性和思维方式，这篇是捷径。",[114,141,142],"入门","基础",1607,{"slug":145,"title":146,"description":147,"pub_date":9,"tags":148,"draft":14,"word_count":152},"python-dataclass-pydantic","Python dataclass vs Pydantic：数据类选型指南","dataclass 是标准库的轻量选择，Pydantic v2 是带验证的重武器，什么时候用哪个，这篇说清楚。",[114,149,150,151],"dataclass","pydantic","数据验证",1323,{"slug":154,"title":155,"description":156,"pub_date":9,"tags":157,"draft":14,"word_count":161},"python-asyncio-practical","Python asyncio 实战：从回调地狱到协程优雅","asyncio 是 Python 异步编程的核心，搞懂 event loop、Task、gather 这些概念才能写出真正高效的异步代码。",[114,158,159,160],"asyncio","并发","网络编程",1258,{"slug":163,"title":164,"description":165,"pub_date":9,"tags":166,"draft":14,"word_count":170},"python-type-hints-guide","Python 类型注解完全指南：从入门到实践","Python 3.5+ 引入类型注解，配合 mypy\u002Fpyright 让 Python 也能享受静态类型检查的好处。",[114,167,168,169],"typescript-style","type-hints","工具链",1102,{"slug":172,"title":173,"description":174,"pub_date":175,"tags":176,"draft":14,"word_count":180},"pwa-install-update-button","PWA 踩坑：为什么安装按钮从来不出现","从 beforeinstallprompt 到 Service Worker waiting，把 PWA 的安装与更新提示真正做对","2026-05-02",[177,178,179],"pwa","javascript","web",1683,{"slug":182,"title":183,"description":184,"pub_date":185,"tags":186,"draft":14,"word_count":187},"openclaw-vs-hermes-agent","OpenClaw vs Hermes Agent：两个本地优先 Agent 的设计差异","OpenClaw（Novita AI）和 Hermes Agent（Nous Research）都是本地运行的个人 AI Agent，但在记忆系统、技能学习、运行环境和模型生态上走了不同的路。深入对比两种架构的核心差异。","2026-05-01",[11,22,12],1679,{"slug":189,"title":190,"description":191,"pub_date":185,"tags":192,"draft":14,"word_count":197},"cpp-random-design-patterns","C++ 设计模式实战：RAII、观察者、工厂","用现代 C++（C++17\u002F20）实现三种高频设计模式：RAII 资源管理、观察者模式事件系统、工厂模式插件架构。每种模式给出问题场景、实现代码和真实工程案例。",[193,194,195,196],"cpp","设计模式","c++17","工程",2613,{"slug":199,"title":200,"description":201,"pub_date":185,"tags":202,"draft":14,"word_count":203},"data-structures-fundamentals","数据结构基础：从数组到红黑树","系统梳理常用数据结构的核心原理、时间复杂度和适用场景。数组、链表、栈、队列、哈希表、二叉树、堆、图，每种结构附实现要点和 C++ 代码片段。",[133,134,193,142],3004,{"slug":205,"title":206,"description":207,"pub_date":208,"tags":209,"draft":14,"word_count":210},"ai-agent-what-is","什么是 AI Agent？从 LLM 到自主执行","LLM 本身是无状态问答机，Agent 是什么让它’动’起来的？本文深入解析 Agent 的四个核心能力、ReAct 框架、工具调用原理，以及主流框架横向对比。","2026-04-30",[11,22,12],2116,{"slug":212,"title":213,"description":214,"pub_date":208,"tags":215,"draft":14,"word_count":216},"ai-agent-memory","AI Agent 的记忆系统：从上下文窗口到长期记忆","深入拆解 AI Agent 的四种记忆类型、上下文窗口压缩策略、RAG 向量检索原理，以及三种典型失败模式和工程选型建议。",[11,22,60],2052,{"slug":218,"title":219,"description":220,"pub_date":208,"tags":221,"draft":14,"word_count":225},"network-proxy-vpn-guide","代理与翻墙技术原理：从 HTTP 代理到现代协议","深入解析代理与 VPN 的本质区别，梳理从 SOCKS5 到 Shadowsocks、V2Ray\u002FXray、Hysteria2 的协议演进，以及机场订阅的技术本质。",[222,223,224],"网络","代理","协议",2148,{"slug":227,"title":228,"description":229,"pub_date":208,"tags":230,"draft":14,"word_count":143},"algorithm-binary-search","二分查找：永远写不对？记住这个模板","彻底搞清楚二分查找的边界问题：闭区间和左闭右开两套模板、三道经典 LeetCode 题目完整 C++ 实现，以及二分答案的进阶思路。",[134,231,232,193],"二分查找","leetcode",{"slug":234,"title":235,"description":236,"pub_date":208,"tags":237,"draft":14,"word_count":239},"algorithm-sliding-window","滑动窗口算法：从暴力到 O(n) 的思维跃迁","系统讲解滑动窗口算法的核心模板、适用题型，配合三道经典 LeetCode 题目的完整 C++ 实现，彻底理解双指针收缩思路。",[134,238,232,193],"滑动窗口",1943,{"slug":241,"title":242,"description":243,"pub_date":208,"tags":244,"draft":14,"word_count":247},"network-clash-config","Clash \u002F Mihomo 配置详解：规则、策略组与分流","深入解析 Clash\u002FMihomo 的核心配置结构，包括代理节点、策略组类型、规则优先级、DNS fake-ip 模式，以及一份实用的完整配置模板。",[222,245,223,246],"clash","配置",1292,{"slug":249,"title":250,"description":251,"pub_date":252,"tags":253,"draft":14,"word_count":257},"hid-hotplug","HID 设备热插拔检测：从 udev 到 node-hid","在 Linux 上用 node-hid + usb 库实现可靠的 USB HID 设备热插拔检测，踩坑记录","2026-04-28",[193,254,35,255,256],"hid","nodejs","electron",2039,{"slug":259,"title":260,"description":261,"pub_date":262,"tags":263,"draft":14,"word_count":266},"electron-ipc-types","Electron IPC 类型安全：从 any 到完全类型化","用 TypeScript 泛型封装 Electron IPC，彻底消灭 any，preload 契约集中管理","2026-04-25",[256,95,264,265],"ipc","vue",1446,{"slug":268,"title":269,"description":270,"pub_date":271,"tags":272,"draft":14,"word_count":275},"element-plus-popover-hide","手动关闭多个 el-popover（不用 v-model:visible）","通过 ref + Reflect.get 调用 hide() 方法手动关闭 Element Plus Popover，解释 Vue3 Proxy 导致无法直接调用实例方法的原因。","2024-10-25",[265,273,274],"element-plus","vue3",1321,{"slug":277,"title":278,"description":279,"pub_date":280,"tags":281,"draft":14,"word_count":285},"vite-vue3-ts-elementplus-pinia","用 Vite+（vp）从零搭建 Vue3 + TypeScript + Element Plus + Pinia + Vue Router","使用 Vite+ 统一工具链（vp）一条命令搭建 Vue3 全家桶，涵盖按需导入、Pinia store、路由配置，以及常见坑的解决方案。","2024-08-27",[265,282,95,273,283,284],"vite","pinia","vite-plus",1960,{"slug":287,"title":288,"description":289,"pub_date":290,"tags":291,"draft":14,"word_count":295},"cef-lnk2038-iterator-debug-level","CEF LNK2038：解决 _ITERATOR_DEBUG_LEVEL 不匹配错误","分析 CEF（Chromium Embedded Framework）集成时出现的 LNK2038 _ITERATOR_DEBUG_LEVEL 链接错误，从根本原因到解决方案的完整指南。","2024-05-07",[193,292,293,294],"CEF","Visual Studio","链接错误",1509,{"slug":297,"title":298,"description":299,"pub_date":300,"tags":301,"draft":14,"word_count":305},"npm-electron-install-fix","彻底解决 npm 安装 Electron 失败的问题","分析 npm install electron 失败的根本原因（下载二进制超时\u002F被墙），通过国内镜像（npmmirror）彻底解决，并介绍多种备选方案和常见错误排查。","2024-03-01",[256,302,303,304],"npm","前端工具链","国内镜像",1494,{"slug":307,"title":308,"description":309,"pub_date":310,"tags":311,"draft":14,"word_count":313},"git-out-of-memory","解决 git 报错：Fatal: Out of memory, malloc failed","分析 git 大仓库操作时出现 Out of memory malloc failed 的根本原因，通过调整 pack.windowMemory、http.postBuffer 和 git repack 彻底解决。","2024-01-31",[67,35,312],"工具",2244,{"slug":315,"title":316,"description":317,"pub_date":318,"tags":319,"draft":14,"word_count":323},"vmware-tools-install","在 VMware 虚拟机中安装 open-vm-tools 完整指南","详解 VMware Tools 的作用、open-vm-tools 与官方 VMware Tools 的区别，以及在 Ubuntu 虚拟机中安装并生效的完整步骤和常见问题排查。","2023-11-21",[320,35,321,322],"VMware","Ubuntu","虚拟机",2523,{"slug":325,"title":326,"description":327,"pub_date":328,"tags":329,"draft":14,"word_count":334},"load-balancing-algorithms","负载均衡算法完全指南：从轮询到一致性哈希","系统梳理静态与动态负载均衡算法，涵盖轮询、随机、权重、IP Hash、一致性 Hash、最少连接、最快响应等，并对比 Nginx、Dubbo、Spring Cloud LoadBalancer 的实现差异。","2023-11-15",[330,331,332,333],"分布式","负载均衡","Nginx","微服务",1764,{"slug":336,"title":337,"description":338,"pub_date":339,"tags":340,"draft":14,"word_count":344},"win-cw2a-ca2w","ATL 字符串转换：CW2A 与 CA2W 完全指南","详解 ATL 宏 CW2A\u002FCA2W 在 Unicode 与 ANSI 之间的字符串转换用法、头文件依赖、USES_CONVERSION 宏的作用与常见陷阱。","2023-06-09",[193,341,342,343],"windows","ATL","字符串",1665,{"slug":346,"title":347,"description":348,"pub_date":339,"tags":349,"draft":14,"word_count":353},"csharp-sendmessage-cpp","C# 通过 SendMessage 向 C++ 窗口发送消息与字符串","使用 P\u002FInvoke 调用 user32.dll 的 SendMessage，从 C# 发送自定义 WM_USER 消息及字符串指针给 C++ 原生窗口，并在 C++ 侧正确接收和转换。",[350,193,341,351,352],"C#","互操作","PInvoke",1554,{"slug":355,"title":356,"description":357,"pub_date":358,"tags":359,"draft":14,"word_count":361},"win-postmessage-vector","Windows PostMessage 跨线程传递 std::vector 指针","通过 PostMessage 在 Windows 消息队列中传递 std::vector 指针，使用 reinterpret_cast 将指针装入 LPARAM，并在接收方正确释放内存。","2023-05-26",[193,341,360],"WinAPI",1823,{"slug":363,"title":364,"description":365,"pub_date":358,"tags":366,"draft":14,"word_count":367},"exe-dll-single-package","将 EXE 和 DLL 打包成单一可执行文件","介绍两种将 exe 和依赖 dll 打包成单文件的方案：Enigma Virtual Box 和 WinRAR 自解压，适合发布 Windows 桌面程序时简化分发流程。",[341,193,312],1619,{"slug":369,"title":370,"description":371,"pub_date":358,"tags":372,"draft":14,"word_count":375},"cpp-random-mt19937","C++ 现代随机数生成：用 mt19937 彻底告别 rand()","深入讲解为什么 rand() 不够用，以及如何用 C++11 的 \u003Crandom> 库正确生成高质量随机数，涵盖 mt19937、各种分布和线程安全。",[193,373,374],"c++11","random",1549,{"slug":377,"title":378,"description":379,"pub_date":380,"tags":381,"draft":14,"word_count":383},"win-startup-registry","C++ 实现程序开机自启动：注册表方式详解","通过操作 Windows 注册表 Run 键实现程序开机自启动，包括 HKCU 与 HKLM 区别、完整封装代码、工作目录问题和 UAC 权限处理。","2022-12-26",[341,193,382],"registry",1201,{"slug":385,"title":386,"description":387,"pub_date":388,"tags":389,"draft":14,"word_count":391},"mfc-cstring-wparam","MFC 中 CString 与 WPARAM 之间的转换","详解 MFC 消息传递中 CString 无法直接强转为 WPARAM 的原因，以及两种正确的转换方案，并介绍结构体指针传递的正确姿势。","2022-11-25",[390,193,341],"mfc",1546,{"slug":393,"title":394,"description":395,"pub_date":396,"tags":397,"draft":14,"word_count":399},"duilib-static-build","正确编译 Duilib 静态库：避免 ATL 依赖和链接错误","详解如何用 DuiLib_Static.vcxproj 编译 Duilib 静态库，解决 VARIANT 未定义、Unicode 配置不匹配和 ATL 依赖等常见问题。","2022-08-24",[193,398,341,390],"duilib",2639,{"slug":401,"title":402,"description":403,"pub_date":404,"tags":405,"draft":14,"word_count":407},"mfc-dpi-adaptive","MFC 界面自适应不同分辨率","MFC 对话框程序实现控件和字体随分辨率自动缩放的完整方案，附 DPI Awareness 配置说明","2022-08-17",[390,193,341,406],"dpi",1414,{"slug":409,"title":410,"description":411,"pub_date":412,"tags":413,"draft":14,"word_count":414},"mfc-drag-window","MFC 无标题栏窗口客户区拖动：三种方法对比","MFC 对话框去掉标题栏后如何实现拖动移动窗口，三种方案完整实现与适用场景分析","2022-08-16",[390,193,341],1633,{"slug":416,"title":417,"description":418,"pub_date":419,"tags":420,"draft":14,"word_count":422},"algorithm-number-complement","整数的补数：位运算掩码解法","LeetCode 476 题，用掩码 XOR 实现整数补数，附 C++\u002FPython\u002FJava 三种实现及补数与补码的区别","2021-03-08",[134,421,232],"位运算",1374,[]]