Skip to content
Gains Summary
Main Navigation 首页 / Home
C++ 编程 / C++ Programming
系统与高性能 / Systems & Performance
Web 开发 / Web Development
人工智能 / Artificial Intelligence
工业软件 / Industrial Software
其他内容 / Other Topics
C++ 编程 / C++系统与性能 / SystemsWeb 开发 / Web人工智能 / AI工业软件 / Industrial

外观

Sidebar Navigation

← 人工智能 / Artificial Intelligence

智能体工程 / Agent Engineering

1. Agent 工程体系全景 / Agent Engineering System Overview

2. Function Calling - 让 LLM 具备行动能力 / Function Calling for Giving LLMs the Ability to Act

3. Agent 框架演进 - 从裸 SDK 到 LangGraph / The Evolution of Agent Frameworks from Raw SDKs to LangGraph

4. RAG 基础 - 让 Agent 拥有"知识" / Retrieval-Augmented Generation Fundamentals for Agent Knowledge

5. 记忆管理 - Agent 的大脑 / Memory Management as the Brain of an Agent

6. Agent 工作流 - 从单步到复杂的执行编排 / Agent Workflows from Single Steps to Complex Orchestration

7. 多 Agent 系统 - 多个 Agent 协作 / Multi-Agent Systems and Agent Collaboration

8. RAG 进阶 - 企业级知识库实战 / Advanced RAG for Enterprise Knowledge Bases

9. 真实 Agent 应用场景 / Real-World AI Agent Applications

10. Structured Output - 让 LLM 输出可控的结构化数据 / Structured Output for Controllable, Machine-Readable LLM Responses

11. Tools Design Best Practices - AI Agent 工具设计最佳实践 / Tools Design Best Practices for AI Agents

12. Agent 架构模式 - 从单 Agent 到多 Agent 的工程范式 / Agent Architecture Patterns

13. Agent Modes — 编程 Agent 的交互模式设计 / Designing Interaction Modes for Coding Agents

14. Agent Workflow 编排:从循环到持久化执行的演进

15. Context Engineering - 从 Prompt 设计到上下文编排 / Context Engineering: From Prompt Design to Context Orchestration

16. Agent 缓存工程:从 KV Cache、Prompt Cache 到语义缓存 / Agent Caching Engineering

17. Harness Engineering, Skills, and Loop Engineering — 从信任模型到验证系统 / From Trusting Models to Verifying Systems

18. MCP 协议 - AI 工具的"USB 接口" / Model Context Protocol for AI Tool Integration

19. Agent 评估与测试 — 如何衡量一个"不可预测"的系统 / Agent Evaluation and Testing — How to Measure an "Unpredictable" System

20. 安全沙箱 - Agent 的安全边界 / Secure Sandboxes as Agent Safety Boundaries

21. 权限与门卫 - Agent 的安全控制中枢 / Permissions and Policy Gates for Agent Control

22. API Key 管理与安全 - Agent 的密钥生命周期的管理 / API Key Lifecycle Management and Security for Agents

23. 提示词注入防护 - Agent 的防御前沿 / Prompt Injection Defense for AI Agents

24. 可观测性与调试 - Agent 运行的透明度保障 / Observability and Debugging for Transparent Agent Operations

25. 模型路由 - 让正确的模型做正确的事 / Model Routing for Matching Models to Tasks

26. OpenClaw 设计深度分析 - 为什么它让人觉得"活"了 / OpenClaw Design Analysis and the Illusion of Liveliness

27. Claude Code 泄露源码深度分析 - 512,000 行代码揭示的生产级 Agent 架构 / Claude Code Source Analysis and Production Agent Architecture

28. LobeChat 设计深度分析 - 全栈 Agent Chat 应用工程实践 / LobeChat Design Analysis and Full-Stack Agent Chat Engineering

29. 编程 Agent 全面对比:从 Claude Code 到 Pi 的设计哲学 / Coding Agents Comparison: Design Philosophies from Claude Code to Pi

30. 领域 Agent 的确定性工具编译与延迟执行——从自然语言规格到单次 CAE 提交

31. Agent 工程学习指南 / An AI Agent Engineering Learning Guide

本页目录

真实 Agent 应用场景 / Real-World AI Agent Applications ​

📅 创建时间:2026-05-08 🏷️ 标签:#Agent应用 #CodeAgent #客服Agent #数据分析Agent #AutoGPT 📚 前置知识:[[07-rag-advanced]]


📋 本章目标 ​

  • 了解 Agent 在各行业的典型应用场景
  • 掌握不同场景下的技术选型和架构设计
  • 理解场景驱动的 Agent 设计思路
  • 能够为新场景设计合适的 Agent 架构

第1部分:AI 客服 Agent ​

1.1 场景描述 ​

┌─────────────────────────────────────────────────────────────┐
│                    AI 客服 Agent 场景                         │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  用户:"我在网上看到你们的课程,想咨询一下价格"               │
│                                                             │
│  AI 客服需要:                                              │
│  1. 理解用户意图(咨询课程价格)                              │
│  2. 查询产品知识库(课程定价、优惠信息)                      │
│  3. 检查用户历史(是否是新客户、有无优惠)                    │
│  4. 生成专业回复(结合知识 + 个性化)                        │
│  5. 处理追问(课程内容、上课方式等)                          │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14

1.2 技术架构 ​

┌─────────────────────────────────────────────────────────────┐
│                    AI 客服 Agent 架构                        │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│                      用户输入                                │
│                         ↓                                   │
│              ┌──────────────────────┐                       │
│              │     意图识别        │                       │
│              │  NLU / LLM 分类     │                       │
│              └──────────┬─────────┘                       │
│                         ↓                                   │
│         ┌───────────────┼───────────────┐                  │
│         ↓               ↓               ↓                  │
│  ┌─────────────┐ ┌─────────────┐ ┌─────────────┐          │
│  │   产品咨询   │ │   订单查询   │ │   投诉处理   │          │
│  │  RAG 检索   │ │   API 调用   │ │   情感分析   │          │
│  └──────┬──────┘ └──────┬──────┘ └──────┬──────┘          │
│         └───────────────┼───────────────┘                  │
│                         ↓                                   │
│              ┌──────────────────────┐                       │
│              │     回复生成 + 审核   │                       │
│              └──────────┬───────────┘                       │
│                         ↓                                   │
│                      回复用户                                │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

1.3 核心实现 ​

python
from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain.tools import Tool

# 知识库检索工具
product_kb_tool = Tool(
    name="product_knowledge",
    func=lambda query: rag_search("product_kb", query),
    description="查询产品信息、价格、优惠活动"
)

# 订单查询工具
order_tool = Tool(
    name="order_query",
    func=lambda order_id: query_order_system(order_id),
    description="查询用户订单状态、物流信息"
)

# 用户历史工具
user_history_tool = Tool(
    name="user_history",
    func=lambda user_id: get_user_profile(user_id),
    description="获取用户历史记录和偏好"
)

tools = [product_kb_tool, order_tool, user_history_tool]

# System Prompt
system_prompt = """你是一个专业的在线课程平台客服。

要求:
1. 热情、专业、有耐心
2. 不确定时如实告知,不编造信息
3. 遇到无法处理的问题时转人工
4. 涉及价格、优惠等敏感信息,以知识库为准
5. 每次回复前先检索知识库"""

agent = create_openai_functions_agent(llm, tools, system_prompt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

第2部分:Code Agent(代码助手) ​

2.1 场景描述 ​

┌─────────────────────────────────────────────────────────────┐
│                    Code Agent 场景                          │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  用户:"帮我写一个函数,计算斐波那契数列第 N 项"              │
│                                                             │
│  Code Agent 需要:                                          │
│  1. 理解任务(斐波那契数列)                                 │
│  2. 选择语言(用户未指定,可用默认或询问)                    │
│  3. 编写代码                                                │
│  4. 运行测试                                                │
│  5. 如果有错误,调试并修复                                  │
│  6. 解释代码逻辑                                             │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

2.2 技术架构 ​

┌─────────────────────────────────────────────────────────────┐
│                    Code Agent 架构                           │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  ┌─────────────────────────────────────────────────────┐   │
│  │                    任务理解                          │   │
│  │            LLM 分析需求,确定实现方案                │   │
│  └─────────────────────────┬───────────────────────────┘   │
│                            ↓                                │
│  ┌─────────────────────────────────────────────────────┐   │
│  │                    代码生成                          │   │
│  │              生成代码 + 单元测试                      │   │
│  └─────────────────────────┬───────────────────────────┘   │
│                            ↓                                │
│  ┌─────────────────────────────────────────────────────┐   │
│  │                    代码执行                        │   │
│  │  Tool:subprocess / docker 隔离执行                 │   │
│  └─────────────────────────┬───────────────────────────┘   │
│                            ↓                                │
│              ┌─────────────┴─────────────┐                  │
│              ↓                           ↓                  │
│         测试通过                      测试失败               │
│              ↓                           ↓                  │
│        解释代码                    调试修复                   │
│              ↓                           ↓                  │
│              └─────────────┬─────────────┘                  │
│                            ↓                                │
│                      最终输出                               │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

2.3 核心实现 ​

python
import subprocess
from langchain.tools import Tool

# 代码执行工具(安全隔离)
def execute_code(code: str, language: str = "python") -> str:
    """安全执行代码"""
    # 实际生产中应使用 Docker 隔离
    try:
        if language == "python":
            result = subprocess.run(
                ["python", "-c", code],
                capture_output=True,
                text=True,
                timeout=10
            )
        elif language == "javascript":
            result = subprocess.run(
                ["node", "-e", code],
                capture_output=True,
                text=True,
                timeout=10
            )
        return result.stdout + result.stderr
    except Exception as e:
        return f"执行错误: {e}"

# 单元测试生成
def generate_tests(code: str, language: str) -> str:
    """生成单元测试"""
    prompt = f"""为以下{language}代码生成单元测试:

{code}

要求:
1. 使用 pytest 框架
2. 覆盖正常和边界情况
3. 输出可直接运行的测试代码"""
    return llm.invoke(prompt)

# 工具注册
code_tools = [
    Tool(name="execute_code", func=execute_code, description="执行代码"),
    Tool(name="write_tests", func=generate_tests, description="生成单元测试"),
]

# Code Agent System Prompt
code_system_prompt = """你是一个专业的代码助手。

工作流程:
1. 理解用户需求
2. 编写代码(包含边界检查)
3. 生成单元测试
4. 运行测试验证
5. 如果测试失败,分析错误并修复
6. 解释代码逻辑

安全规则:
- 不执行删除文件、系统命令等危险操作
- 代码执行有 10 秒超时限制
- 如果代码有问题,诚实地告诉用户"""
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

2.4 主流 Code Agent 工具 ​

┌─────────────────────────────────────────────────────────────┐
│                    主流 Code Agent 工具                      │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  GitHub Copilot                                             │
│  • 代码补全、生成                                            │
│  • 基于上下文智能推断                                        │
│                                                             │
│  Cursor                                                     │
│  • AI 代码编辑器                                            │
│  • 支持多文件编辑                                            │
│                                                             │
│  Claude (Anthropic)                                        │
│  • 强大的代码理解和生成能力                                  │
│  • 支持复杂项目级任务                                        │
│                                                             │
│  Devin (Cognition)                                          │
│  • 自主完成端到端软件任务                                    │
│  • 可以自主修复 bug、优化代码                                │
│                                                             │
│  SWE-agent                                                 │
│  • 开源的软件工程 Agent                                      │
│  • 专注于 bug 修复                                          │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

第3部分:数据分析 Agent ​

3.1 场景描述 ​

┌─────────────────────────────────────────────────────────────┐
│                    数据分析 Agent 场景                        │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  用户:"分析一下我们公司 Q3 的销售数据,看看有什么问题"        │
│                                                             │
│  数据分析 Agent 需要:                                       │
│  1. 连接数据源(数据库、Excel、API)                         │
│  2. 数据清洗和预处理                                         │
│  3. 执行分析(趋势、同比、环比、异常检测)                   │
│  4. 生成可视化图表                                          │
│  5. 撰写分析报告                                            │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14

3.2 技术架构 ​

┌─────────────────────────────────────────────────────────────┐
│                    数据分析 Agent 架构                       │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│                      用户问题                                │
│                         ↓                                   │
│              ┌──────────────────────┐                       │
│              │   意图分解 & 规划    │                       │
│              │  确定需要哪些数据    │                       │
│              └──────────┬───────────┘                       │
│                         ↓                                   │
│    ┌────────────────────┼────────────────────┐             │
│    ↓                    ↓                    ↓              │
│ ┌────────┐        ┌────────────┐       ┌────────────┐      │
│ │数据获取│        │   数据清洗  │       │   数据存储  │      │
│ │SQL查询│        │   异常处理   │       │  中间结果   │      │
│ └────┬───┘        └──────┬─────┘       └────────────┘      │
│      └───────────────────┼────────────────────┘             │
│                          ↓                                   │
│              ┌──────────────────────┐                       │
│              │       分析执行       │                       │
│              │  统计 / 趋势 / 异常   │                       │
│              └──────────┬───────────┘                       │
│                         ↓                                   │
│              ┌──────────────────────┐                       │
│              │    报告生成          │                       │
│              │  图表 + 文字解读     │                       │
│              └──────────────────────┘                       │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

3.3 核心实现 ​

python
from langchain.tools import Tool
import pandas as pd

# SQL 查询工具
def query_database(sql: str) -> str:
    """执行 SQL 查询"""
    try:
        df = pd.read_sql(sql, connection)
        return df.to_string()
    except Exception as e:
        return f"查询错误: {e}"

# Python 执行工具(数据分析专用)
def analyze_data(code: str) -> str:
    """执行数据分析代码"""
    try:
        # 隔离的命名空间执行
        namespace = {"pd": pd}
        exec(code, namespace)
        # 返回关键结果
        if "result" in namespace:
            return str(namespace["result"])
        return "分析完成"
    except Exception as e:
        return f"分析错误: {e}"

analysis_tools = [
    Tool(name="query_sql", func=query_database, description="查询数据库"),
    Tool(name="analyze_python", func=analyze_data, description="执行数据分析代码"),
]

analysis_system_prompt = """你是一个专业的数据分析师。

能力:
1. 编写 SQL 查询数据
2. 使用 Python 进行数据分析(pandas, numpy, matplotlib)
3. 生成分析报告和图表
4. 发现数据异常和趋势

工作流程:
1. 理解用户需求
2. 确定需要哪些数据表
3. 编写 SQL 获取数据
4. 执行数据分析
5. 生成结论和建议

注意:
- SQL 要注意性能和准确性
- 分析代码要有注释
- 最终用通俗语言解释分析结果"""
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

第4部分:研究与报告 Agent ​

4.1 场景描述 ​

┌─────────────────────────────────────────────────────────────┐
│                    研究报告 Agent 场景                        │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  用户:"帮我研究一下 AI Agent 领域最新的技术进展"             │
│                                                             │
│  研究 Agent 需要:                                           │
│  1. 多源信息搜索(新闻、论文、博客、社交媒体)                │
│  2. 信息去重和优先级排序                                    │
│  3. 内容深度阅读和提取                                      │
│  4. 信息整合和观点综合                                      │
│  5. 撰写结构化报告                                          │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14

4.2 技术架构 ​

┌─────────────────────────────────────────────────────────────┐
│                    研究 Agent 架构                           │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  ┌─────────────────────────────────────────────────────┐   │
│  │                    搜索阶段                         │   │
│  │  多源并行搜索 → 去重 → 质量筛选 → 候选列表           │   │
│  └─────────────────────────┬───────────────────────────┘   │
│                            ↓                                │
│  ┌─────────────────────────────────────────────────────┐   │
│  │                    阅读阶段                         │   │
│  │  深度阅读 → 关键信息提取 → 摘要 → 观点库             │   │
│  └─────────────────────────┬───────────────────────────┘   │
│                            ↓                                │
│  ┌─────────────────────────────────────────────────────┐   │
│  │                    整合阶段                         │   │
│  │  观点分类 → 逻辑组织 → 报告大纲                     │   │
│  └─────────────────────────┬───────────────────────────┘   │
│                            ↓                                │
│  ┌─────────────────────────────────────────────────────┐   │
│  │                    撰写阶段                         │   │
│  │  按大纲撰写 → 引用标注 → 格式优化 → 审核             │   │
│  └─────────────────────────┬───────────────────────────┘   │
│                            ↓                                │
│                         最终报告                             │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

4.3 多 Agent 协作实现 ​

python
from crewai import Agent, Task, Crew

# 研究员 Agent
researcher = Agent(
    role="AI 领域研究员",
    goal="收集并分析 AI Agent 领域最新的技术动态",
    backstory="你是一位专注 AI 领域的技术研究员,善于发现技术趋势和关键突破",
    tools=[search_web_tool, read_url_tool]
)

# 分析师 Agent
analyst = Agent(
    role="技术分析师",
    goal="对收集的信息进行深度分析和趋势判断",
    backstory="你是一位资深技术分析师,擅长从复杂信息中提取关键洞察",
    tools=[]
)

# 作家 Agent
writer = Agent(
    role="技术作家",
    goal="将分析结果撰写成专业、易读的技术报告",
    backstory="你是一位经验丰富的技术作家,文章结构清晰、逻辑严谨",
    tools=[]
)

# 审核 Agent
reviewer = Agent(
    role="质量审核",
    goal="审核报告的准确性、完整性和可读性",
    backstory="你是一位严格的编辑,对技术细节有敏锐的洞察",
    tools=[]
)

# 定义任务
task1 = Task(description="搜索 AI Agent 领域近三个月的重要进展", agent=researcher)
task2 = Task(description="分析收集到的信息,识别关键趋势", agent=analyst)
task3 = Task(description="撰写 2000 字技术报告", agent=writer)
task4 = Task(description="审核报告质量", agent=reviewer)

# 创建团队
crew = Crew(
    agents=[researcher, analyst, writer, reviewer],
    tasks=[task1, task2, task3, task4],
    process="sequential"
)

result = crew.kickoff()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

第5部分:自动化工作流 Agent(AutoGPT 类) ​

5.1 场景描述 ​

┌─────────────────────────────────────────────────────────────┐
│                    AutoGPT 类 Agent 场景                      │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  用户:"帮我把桌面上的照片整理一下,按日期分类"               │
│                                                             │
│  AutoGPT 类 Agent:                                         │
│  1. 分析任务:需要读取文件、执行文件操作                      │
│  2. 制定计划:列出具体步骤                                    │
│  3. 逐步执行:读取照片 EXIF → 确定日期 → 移动到文件夹       │
│  4. 自我检查:验证整理结果                                    │
│  5. 持续优化:发现遗漏则补充                                  │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14

5.2 技术架构 ​

┌─────────────────────────────────────────────────────────────┐
│                    AutoGPT Agent 核心循环                     │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  while not done:                                           │
│  ┌─────────────────────────────────────────────────────┐   │
│  │ 1. Think(思考):分析当前状态,决定下一步           │   │
│  └─────────────────────────┬───────────────────────────┘   │
│                            ↓                                │
│  ┌─────────────────────────────────────────────────────┐   │
│  │ 2. Plan(规划):制定具体的执行计划                   │   │
│  └─────────────────────────┬───────────────────────────┘   │
│                            ↓                                │
│  ┌─────────────────────────────────────────────────────┐   │
│  │ 3. Act(行动):调用工具执行                         │   │
│  └─────────────────────────┬───────────────────────────┘   │
│                            ↓                                │
│  ┌─────────────────────────────────────────────────────┐   │
│  │ 4. Observe(观察):检查执行结果                     │   │
│  └─────────────────────────┬───────────────────────────┘   │
│                            ↓                                │
│  ┌─────────────────────────────────────────────────────┐   │
│  │ 5. 是否完成?→ 是则结束,否继续循环                   │   │
│  └─────────────────────────────────────────────────────┘   │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

5.3 核心实现 ​

python
from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain.tools import Tool
import os
from pathlib import Path

# 文件读取工具
def read_file(path: str) -> str:
    """读取文件内容"""
    try:
        return Path(path).read_text(encoding='utf-8')
    except:
        return f"无法读取: {path}"

# 文件列表工具
def list_files(dir_path: str) -> str:
    """列出目录中的文件"""
    try:
        files = list(Path(dir_path).iterdir())
        return "\n".join([f.name for f in files])
    except:
        return f"无法列出: {dir_path}"

# 文件移动工具
def move_file(source: str, dest: str) -> str:
    """移动文件"""
    try:
        Path(source).rename(dest)
        return f"已移动: {source} → {dest}"
    except Exception as e:
        return f"移动失败: {e}"

# 文件操作 Agent
file_tools = [
    Tool(name="read_file", func=read_file, description="读取文件内容"),
    Tool(name="list_files", func=list_files, description="列出目录中的文件"),
    Tool(name="move_file", func=move_file, description="移动文件到新位置"),
]

autogpt_system_prompt = """你是一个任务执行助手。

核心循环:
1. Think:分析当前状态和目标
2. Plan:制定具体步骤
3. Act:执行一个步骤
4. Observe:检查结果
5. 如果完成则停止,否则继续

安全规则:
- 只操作用户明确授权的文件和目录
- 执行前先确认操作
- 每次只执行一个步骤
- 遇到错误时停止并报告"""

# 最大化迭代次数,允许多步骤执行
agent = create_openai_functions_agent(llm, file_tools, autogpt_system_prompt)
executor = AgentExecutor(
    agent=agent,
    tools=file_tools,
    max_iterations=50,  # AutoGPT 风格:允许很多次迭代
    max_execution_time=300  # 5 分钟超时
)

result = executor.invoke({
    "input": "把桌面上的照片按日期分类到 '照片/YYYY-MM' 文件夹"
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

第6部分:场景技术选型总结 ​

┌─────────────────────────────────────────────────────────────┐
│                    场景技术选型指南                           │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  │ 场景           │ Agent 类型    │ 核心能力      │ 框架选择 │
│  ├────────────────┼───────────────┼───────────────┼─────────┤
│  │ 客服           │ 单 Agent      │ RAG + 记忆    │ LangChain│
│  │ 代码助手       │ 单/多 Agent   │ 代码执行      │ LangGraph│
│  │ 数据分析       │ 单 Agent      │ SQL + Python │ LangChain│
│  │ 研究报告       │ 多 Agent      │ 搜索 + 写作   │ CrewAI   │
│  │ 自动化工作流   │ ReAct 循环    │ 工具调用      │ LangGraph│
│                                                             │
│  通用原则:                                                  │
│  • 简单任务 → 单 Agent                                      │
│  • 复杂多步骤 → ReAct / Plan-and-Execute                  │
│  • 多角色协作 → CrewAI / AutoGen                           │
│  • 需要状态管理 → LangGraph                                 │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

核心总结 ​

总结1:五大典型场景 ​

场景核心挑战关键技术
AI 客服知识库 + 情感理解RAG + 意图识别
Code Agent代码执行 + 调试沙箱执行 + 循环修复
数据分析数据连接 + 自动化分析SQL + Python + 可视化
研究报告多源信息整合多 Agent 协作
AutoGPT自主规划 + 工具调用ReAct + 状态管理

总结2:选型建议 ​

任务简单、固定 → 单 Agent + RAG
任务复杂、需探索 → ReAct 循环
任务多角色 → CrewAI / AutoGen
任务有状态依赖 → LangGraph
1
2
3
4

章节测试 ​

测试1:场景匹配 ​

什么场景最适合用多 Agent 协作(CrewAI)?

测试2:Code Agent ​

Code Agent 需要哪些关键能力?

测试3:AutoGPT ​

AutoGPT 的核心循环是什么?

测试4:选型 ​

用户需要"帮我分析这份 Excel 销售数据",应该选择什么技术方案?

测试5:架构设计 ​

设计一个"AI 个人助理"Agent,至少需要哪些能力模块?


参考答案 ​

测试1答案 ​

答案:需要多个专业角色协作、任务有明确流水线分工的场景,如研究报告(研究员 + 分析师 + 作家 + 审核员)。


测试2答案 ​

答案:代码生成、代码执行(沙箱隔离)、单元测试生成、错误调试和修复、代码解释。


测试3答案 ​

答案:Think(思考当前状态)→ Plan(制定计划)→ Act(执行行动)→ Observe(观察结果)→ 判断是否完成,未完成则循环。


测试4答案 ​

答案:数据分析 Agent,核心技术包括:文件读取(Excel/Pandas)、数据处理(清洗、统计)、SQL 查询(如果连接数据库)、可视化(图表生成),框架可选 LangChain。


测试5答案 ​

答案:至少需要:

  1. 消息理解(RAG/对话管理)
  2. 日程管理(工具调用)
  3. 邮件处理(工具调用)
  4. 知识搜索(RAG)
  5. 记忆管理(短期+长期)
  6. 任务规划(工作流编排)

相关笔记 ​

  • [[05-agent-workflow]] - 不同场景的工作流选择
  • [[06-multi-agent]] - 多 Agent 协作在研究报告中的应用
  • [[03-rag-basics]] - RAG 在客服等场景中的应用

下一步学习 ​

恭喜你完成了 Agent 学习路线!

  • [ ] 回顾 [[00-agent-overview]] - 重新梳理整体框架
  • [ ] 实践项目:选择一个场景,从零构建一个 Agent

学习状态:🟡 开始学习

最后更新于:

Pager
上一篇8. RAG 进阶 - 企业级知识库实战 / Advanced RAG for Enterprise Knowledge Bases
下一篇10. Structured Output - 让 LLM 输出可控的结构化数据 / Structured Output for Controllable, Machine-Readable LLM Responses

持续记录,持续成长

Copyright © Tidenflow