簡介
代理基本上以「思考 1 步,執行 1 步」的方式運作。高級代理需要知道如何計劃、自我評估和自我糾正。本文涵蓋了最重要的設計模式。
1. 計畫與執行模式
User Request → Planner (tạo plan) → Executor (thực hiện từng step) → Re-planner (adjust)
2.自我反思/批判循環
def reflect_and_improve(agent_output, original_task):
critic_prompt = f"""
Task: {original_task}
Agent Output: {agent_output}
Evaluate:
1. Does it fully answer the task? (completeness)
2. Is the information accurate? (accuracy)
3. Is it well-structured? (quality)
If issues found, provide specific improvements.
"""
feedback = call_llm(critic_prompt)
if "APPROVED" in feedback:
return agent_output
else:
improved = call_llm(f"Improve based on feedback: {feedback}")
return improved
3. 思想樹
探索並行思想的多個分支,而不是一條思想鏈,然後選擇最佳分支。
總結
- 計劃與執行:先計劃,後執行
- 自我反思:批評循環提高輸出品質
- 思考樹:探索多種推理路徑
- 組合模式打造最強特工
練習
- 實施計劃和執行代理 2.添加自反射循環(最多3次迭代)
- 比較輸出品質:有反射與無反射
- 運用思考樹解決數學問題