目標先講清楚:
當任務變複雜,長而清楚的結構化提示比「一句話魔法」更重要。本文整理 Claude Code 與社群最佳實務(含 parahelp、LangChain),整理一些技巧
Claude 的建議是幫助讓你跟它的模型進行更有效率的溝通,透過技巧,掌握跟LLM說話的方式;使用Parahelp的prompt當作技巧的範例。
對應片段
- Make sure your description NEVER assumes any information, variables or tool call results...
- Make sure your plan NEVER includes or guesses on information/instructions/rules...
- Make sure you ALWAYS highlight ... that <helpcenter_result> is the source of truth...
- Make sure that the plan always follows the procedures and rules of the # Customer service agent Policy doc
- The action_name should always be the name of a valid tool
對應片段
- When planning next steps, make sure it's only the goal of next steps...
- Make sure that the plan always follows the procedures and rules of the # Customer service agent Policy doc
Scenario: The user has error with feature_name and have provided basic information about the error
對應片段
_IMPORTANT_: This example of a plan is only to give you an idea...
<plan>
<step> ... </step>
<if_block condition='...'> ... </if_block>
</plan>
- The description should be a short description of why the action is needed...
- ...which outputs from other tool calls that should be used (if relevant)
- ...e.g. "reply to the user with instrucitons from <helpcenter_result>"
對應片段
- A plan consists of steps.
- You can always include <if_block> tags...
- The step should be in the following format:
<step>
<action_name></action_name>
<description>{...}</description>
</step>
- Every step can have an if block...
- ...wrapped with the <if_block condition=''></if_block> tags.
對應片段
- You can always include <if_block> tags to include different steps based on a condition.
- ...which outputs from other tool calls that should be used (if relevant)
- To create multiple if/else blocks just create multiple <if_block> tags.
- ...think in possible paths and use <tool_calls> as variable names...
XML 標籤能把 政策、步驟、條件、工具 I/O 變成讓模型容易讀懂的格式。
重點:把「計畫」與「反思」寫成明確步驟。
使用在 LangChain 的 open_deep_research 當作Reflection的範例
(補充-langchain的這個專案,把Reflect包成一個think_tool
給agent調用的方式很酷)
Plan也是類似的方式,透過how to plan:
或steps for planning
去引導模型
@tool(description="Strategic reflection tool for research planning")
def think_tool(reflection: str) -> str:
"""Tool for strategic reflection on research progress and decision-making.
Use this tool after each search to analyze results and plan next steps systematically.
This creates a deliberate pause in the research workflow for quality decision-making.
When to use:
- After receiving search results: What key information did I find?
- Before deciding next steps: Do I have enough to answer comprehensively?
- When assessing research gaps: What specific information am I still missing?
- Before concluding research: Can I provide a complete answer now?
Reflection should address:
1. Analysis of current findings - What concrete information have I gathered?
2. Gap assessment - What crucial information is still missing?
3. Quality evaluation - Do I have sufficient evidence/examples for a good answer?
4. Strategic decision - Should I continue searching or provide my answer?
Args:
reflection: Your detailed reflection on research progress, findings, gaps, and next steps
Returns:
Confirmation that reflection was recorded for decision-making
"""
return f"Reflection recorded: {reflection}"
接下來是Prompt的管理