附录 A+B 主流框架速查 & 工具与资源清单

本篇是《AI Agent 实战:从设计模式到生产落地》的附录 A + B 合集:主流框架速查 + 工具与资源清单,方便随时查阅。


附录 A:主流框架速查

本附录为全书涉及的 5 大框架/协议的横向对比速查。详细选型逻辑见正文对应章节。

A.1 框架总览

框架/协议 类型 核心概念 适合 正文章节
LangGraph 编排框架 图(StateGraph)+ 节点 + 条件边 复杂编排、生产级 6、10-16 章
AutoGen 多 Agent 框架 Agent 群聊(ConversableAgent) 研究、辩论、协商 16 章
CrewAI 多 Agent 框架 角色/任务/工具声明式 快速原型 16 章
MCP 工具接入协议 Server / Client + 工具/资源/提示 工具标准化接入 7 章
OpenAI 兼容 API 模型接口 chat.completions + tools 参数 通用模型调用 5、14 章

A.2 LangGraph 速查

核心概念

text 复制代码
StateGraph(状态图)→ 节点(Node)+ 边(Edge)
  ├─ add_node: 添加处理节点
  ├─ add_edge: 顺序边
  ├─ add_conditional_edges: 条件边(路由/循环)
  └─ compile: 编译为可执行图 → invoke(输入)

最小示例(提示链)

python 复制代码
from langgraph.graph import StateGraph, END

g = StateGraph(dict)
g.add_node("extract", lambda s: {**s, "e": extract(s)})
g.add_node("write", lambda s: {**s, "r": write(s)})
g.add_edge("extract", "write")
g.add_edge("write", END)
app = g.compile()
result = app.invoke({"q": "..."})

关键能力

  • 状态管理:节点间通过 state 传递,天然支持分支/循环
  • 条件边:实现路由、反思循环、重试
  • checkpointer:断点续跑、人工介入(Human-in-loop)

A.3 AutoGen 速查

核心概念

text 复制代码
ConversableAgent(可对话 Agent)
  ├─ UserProxyAgent(人类代理:可执行代码/工具)
  ├─ AssistantAgent(助手)
  └─ GroupChat(群聊)+ GroupChatManager(群聊管理者)

最小示例(双 Agent 对话)

python 复制代码
from autogen import ConversableAgent, UserProxyAgent

assistant = ConversableAgent("assistant", llm_config={"model": "..."})
user_proxy = UserProxyAgent("user", code_execution_config={"work_dir": "."})
user_proxy.initiate_chat(assistant, message="帮我写个冒泡排序")

注意事项

  • 群聊模式易失控:自由对话需强约束(停止条件/轮数上限,见 16 章)
  • 生产场景慎用自由对话:优先结构化传递(16.3.1)

A.4 CrewAI 速查

核心概念

text 复制代码
Agent(角色)+ Task(任务)+ Crew(团队)
  ├─ Agent: role/goal/backstory/tools
  ├─ Task: description/expected_output/agent
  └─ Crew: agents + tasks + process(sequential/hierarchical)

最小示例

python 复制代码
from crewai import Agent, Task, Crew

researcher = Agent(role="研究员", goal="查资料", backstory="...")
writer = Agent(role="写手", goal="写报告", backstory="...")
task1 = Task(description="调研市场", expected_output="要点清单", agent=researcher)
task2 = Task(description="写报告", expected_output="报告", agent=writer)
crew = Crew(agents=[researcher, writer], tasks=[task1, task2])
result = crew.kickoff()

注意事项

  • 上手快但封装深:底层控制力弱,复杂逻辑受限
  • 适合原型:快速验证多 Agent 想法(16.4)

A.5 MCP 速查

架构

text 复制代码
MCP Client(Agent 应用) ←协议→ MCP Server(工具/数据提供方)
  ├─ 传输:stdio(本地)/ HTTP(远程)
  ├─ 能力:tools(工具)/ resources(资源)/ prompts(提示)
  └─ SDK:mcp(官方)/ fastmcp(FastMCP 简化)

最小 Server(FastMCP)

python 复制代码
from fastmcp import FastMCP
mcp = FastMCP("my-tools")

@mcp.tool()
def my_tool(x: int) -> int:
    """工具描述:何时用/做什么"""
    return x * 2

mcp.run(transport="stdio")

关键点

  • docstring 即工具描述(7.4.2)
  • 接入前审查 Server 暴露的工具(供应链安全,22 章)

A.6 OpenAI 兼容 API 速查

基础调用

python 复制代码
from openai import OpenAI
client = OpenAI(base_url="https://api.deepseek.com", api_key="<key>")

resp = client.chat.completions.create(
    model="deepseek-chat",
    messages=[{"role": "user", "content": "你好"}],
    temperature=0.3,
    max_tokens=1000,
)
print(resp.choices[0].message.content)

工具调用(第 5 章)

python 复制代码
resp = client.chat.completions.create(
    model="deepseek-chat",
    messages=[{"role": "user", "content": "查订单 A1"}],
    tools=[{...}],           # Function Schema
    tool_choice="auto",
)
msg = resp.choices[0].message
if msg.tool_calls:
    print(msg.tool_calls[0].function.name, msg.tool_calls[0].function.arguments)

结构化输出(第 4 章)

python 复制代码
resp = client.chat.completions.create(
    model="deepseek-chat",
    messages=[...],
    response_format={"type": "json_object"},   # 或 json_schema
)

A.7 框架选型速查表

你的需求 首选 备选
纯顺序流程(提示链) 自研(10 章) LangGraph
复杂图结构(分支/循环) LangGraph 自研
多 Agent 协作(生产) LangGraph + 自研编排 CrewAI
多 Agent 研究/辩论 AutoGen LangGraph
工具标准化接入 MCP 手写 Schema
快速原型验证 CrewAI AutoGen
通用模型调用 OpenAI 兼容 API 各厂商 SDK

核心原则(第 29 章):先自研跑通理解原理,再按需选框架;学模式,不追框架。


附录 B:工具与资源清单

本附录汇总全书涉及的开发工具、开源项目、云服务与学习资源。均为第三方资源,使用时以官方文档为准,接入前按第 22 章做安全审查。

B.1 开发框架与库

类别 工具 用途 备注
Agent 编排 LangGraph 图结构工作流 第 10-16 章对照
Agent 编排 AutoGen 多 Agent 对话 第 16 章
Agent 编排 CrewAI 声明式多 Agent 第 16 章
工具接入 MCP / FastMCP 工具标准化 第 7 章
提示工程 LangChain 链式组件 部分章节对照
评测 Langfuse LLM 追踪/评测 第 20-21 章
评测 LangSmith LangChain 生态评测 第 20 章
评测 LLM-as-Judge(自建) 模型评分 第 17、20 章
向量库 Chroma 轻量向量库 第 8 章
向量库 Qdrant 生产级向量库 第 8 章
向量库 FAISS Meta 开源向量库 第 8 章
向量库 Milvus 大规模向量库 第 8 章
语义路由 semantic-router embedding 意图路由 第 11 章变体
记忆存储 Redis 会话/缓存 第 3、9 章
记忆存储 PostgreSQL 结构化记忆 第 9 章

B.2 模型与 API

模型 厂商 接入方式 特点 备注
DeepSeek-V3 深度求索 OpenAI 兼容 API 通用强、价格低 第 2 章推荐主力
DeepSeek-R1 深度求索 OpenAI 兼容 API 推理强 别乱调温度(24 章)
Qwen 系列 阿里 OpenAI 兼容 API / 开源 开源可私有化 长窗口
豆包 Doubao 字节 火山方舟 API 中文对话自然 字节生态
混元 Hunyuan 腾讯 OpenAI 兼容 API 腾讯生态 微信场景
GPT 系列 OpenAI 官方 API 综合最强 成本高
Claude Anthropic 官方 API 长文本/代码强 MCP 起源

B.3 追踪与可观测

工具 类型 特点 正文章节
Langfuse 开源可自部署 LLM 专用 trace/评测/成本面板 21 章推荐
OpenTelemetry 标准 通用可观测,可接 LLM 21 章
LangSmith SaaS LangChain 生态 20-21 章
自建 JSON 日志 自研 零依赖起步 21 章

B.4 部署基础设施

类别 工具/服务 用途
无服务器 AWS Lambda / 云函数 Agent 服务托管
容器 Docker 环境打包
编排 Kubernetes / 云原生 大规模部署
网关 API Gateway 限流/鉴权/路由
消息队列 Redis Streams / Kafka 异步任务
定时任务 APScheduler / Celery beat 周期任务

B.5 安全工具

工具 用途 说明
Guardrails AI 输出护栏 第 17 章
NeMo Guardrails 企业级护栏 NVIDIA,第 17 章
LlamaGuard 内容安全分类 Meta,第 22 章
自建注入检测 输入过滤 第 22 章 22.4
沙箱(Docker) 代码执行隔离 第 22 章

B.6 学习资源

类型 资源 说明
文档 MCP 官方文档 协议最新规范
文档 LangGraph 官方文档 图编排 API
开源 AutoGen / CrewAI 仓库 学习多 Agent 实现
图书 本书参考书单 见策划方案 1.1 节竞品表
社区 GitHub Trending / Hacker News 跟踪 Agent 生态演进
论文 ReAct / Reflexion / ToT 设计模式源头

B.7 快速上手建议

  1. 起步组合:DeepSeek API + Chroma + 自建日志(零成本跑通第 1-9 章)
  2. 工程组合:DeepSeek/Qwen API + Qdrant + Langfuse + MCP(生产级)
  3. 私有化组合:Qwen 开源 + Docker + 自建(数据敏感场景)
  4. 多 Agent 组合:LangGraph + MCP Server 群(复杂编排)

注意:第三方服务随时可能变更,接入前查看最新文档;涉及数据/安全的工具,先过第 22 章检查清单。

相关推荐
进击的横打1 小时前
【人工智能】把经验沉淀成 Skill
人工智能
用户976104399211 小时前
7.3框架接口实现
agent
代码方舟1 小时前
PHP数据工程:利用天远学历信息高级版优化专家资源池合规体验
人工智能
飞哥数智坊1 小时前
ZCode 可以自己看微信小程序了
人工智能·ai编程
江润舟1 小时前
万物|炼器 从零手搓工业级旋转目标检测网络 · 卷3 —— 核心算子锻造(三)
人工智能·深度学习
桃西西呀1 小时前
你的 Agent 每判一次都要为大模型吐的字买单?-Laya模型帮你做判断
人工智能·llm·ai编程
用户976104399212 小时前
7.2HelloAgentsLLM扩展
agent
品牌常新2 小时前
安防巡检机器人推荐:园区仓储楼宇怎么选
人工智能