Skip to content
Go back

AI Agent 基本设计模式

Updated:
Edit page

Contents

Open Contents

基本设计模式

1. ReAct 模式

示例 Prompt 模板:

manual_react = f"""
Question: What profession does Nicholas Ray and Elia Kazan have in common?
Thought: I need to search Nicholas Ray and Elia Kazan, find their professions, then find the profession they have in common.
Action: Search[Nicholas Ray]
Observation: Nicholas Ray (born Raymond Nicholas Kienzle Jr., August 7, 1911 - June 16, 1979) was an American film director, screenwriter, and actor best known for the 1955 film Rebel Without a Cause.
Thought: Professions of Nicholas Ray are director, screenwriter, and actor. I need to search Elia Kazan next and find his professions.
Action: Search[Elia Kazan]
Observation: Elia Kazan was an American film and theatre director, producer, screenwriter and actor.
Thought: Professions of Elia Kazan are director, producer, screenwriter, and actor. So profession Nicholas Ray and Elia Kazan have in common is director, screenwriter, and actor.
Action: Finish[director, screenwriter, actor]
"""

2. Plan-and-Solve 模式

3. Reason without Observation 模式

4. LLMCompiler 模式

示例任务分解:

找三篇关于AI安全的论文,总结核心观点并对比异同,最后生成中文报告

分解为:search×3 → summarize×3 → compare → translate

5. Basic Reflection 模式

Prompt 示例:

prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "You are an essay assistant tasked with writing excellent 5-paragraph essays."
            " Generate the best essay possible for the user’s request."
            " If the user provides critique, respond with a revised version of your previous attempts.",
        ),
        MessagesPlaceholder(variable_name="messages"),
    ]
)

reflection_prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "You are a teacher grading an essay submission. Generate critique and recommendations for the user’s submission."
            " Provide detailed recommendations, including requests for length, depth, style, etc.",
        ),
        MessagesPlaceholder(variable_name="messages"),
    ]
)
reflect = reflection_prompt | llm

6. Reflexion 模式

7. Language Agent Tree Search 模式

MCP

MCP (Model Context Protocol,模型上下文协议)定义了应用程序和 AI 模型之间交换上下文信息的方式。这使得开发者能够以一致的方式将各种数据源、工具和功能连接到 AI 模型(一个中间协议层),就像 USB-C 让不同设备能够通过相同的接口连接一样。MCP 的目标是创建一个通用标准,使 AI 应用程序的开发和集成变得更加简单和统一。

MCP 三大核心组件

流程示例:

  1. 用户提问 → Claude Desktop (Host)
  2. Claude 模型决定需要文件信息 → MCP Client 连接
  3. 文件系统 MCP Server 执行操作 → 返回结果
  4. Claude 生成回答 → 显示在 Claude Desktop

Claude(模型)如何确定使用哪些工具?

参考资料


Edit page
Share this post on:

Previous Post
计算机网络基础概念(一)
Next Post
Git 版本控制小记