LangGraph、OpenAI Agents SDK、Claude Agent SDK 对比:选对框架,构建高效智能体!
本文对比了 LangGraph、OpenAI Agents SDK 和 Claude Agent SDK 三种智能体框架。LangGraph 适合有状态工作流,OpenAI Agents SDK 强调实时交互,Claude Agent SDK 提供完整的 shell 环境。选择框架需根据具体工作形态,如实时语音交互、持久化多智能体编排、代码相关任务或 MCP 工具编排。Meridian 公司的案例展示了如何根据不同需求选择合适的框架。

LangGraph 提供了一个 graph runtime,其中节点是函数,边负责处理转换。OpenAI Agents SDK 依赖 handoff,让 agents 能够通过 typed sessions 和原生 MCP 集成,将工作委派给其他 agents。Claude Agent SDK 则选择了一条不太明显的路径:为 agent 提供一台计算机。Anthropic 围绕 bash 执行、文件写入和 hook 系统构建了自己的框架,因为他们认为,一个能力出色的 agent 需要真正的 shell。
在它们之间做选择,取决于一个大多数架构比较都会忽略的问题。工作的形态是什么?
三种 Primitive
LangGraph 专为有状态工作流而设计。你定义一个 state schema,这个 typed object 会从开始到结束流经整个 graph。Checkpointer 会在每个节点持久化该 state。如果服务器崩溃,或者工作流因等待人工审批而暂停,之后可以恢复运行,而不会丢失上下文。LangChain 1.0 于 2025 年 10 月 22 日正式发布,该版本中的标准 create_agent 调用就是这个 graph runtime 的 facade。过去关于应该使用 LangChain 还是 LangGraph 的争论已经结束。
OpenAI Agents SDK 基于九个核心 building blocks 运行,包括 Agents、Handoffs、Tools、Guardrails、Sessions 和 Realtime。其原子单元是一个 Agent 将任务 handoff 给另一个 Agent。2025 年,借助 LiteLLM,SDK 支持超过 100 个 language models,实现了 provider agnosticism。该 SDK 将 MCP 视为一等工具类型,并通过 gpt-realtime-2 系列模型原生提供语音能力。
Anthropic 围绕 shell environment 构建了 Claude Agent SDK。开发者可以使用 Bash、Read、Write、Edit、Glob 和 Grep 工具,以及 PreToolUse、PostToolUse 和 Stop 等生命周期 hooks。Subagents 会在各自隔离的 context windows 中启动。Anthropic 于 2025 年底将其从 Claude Code SDK 重命名为现在的名称,以反映这一 harness 除了支持标准编码任务之外,还能支持深度研究、视频创作和笔记记录。团队只能使用 Claude models,但可以选择在 Bedrock、Vertex 和 Azure Foundry 上进行部署。

一个应该抛弃的 2025 年认知
去年有一个持续存在的假设:OpenAI Agents SDK 强制你使用 OpenAI models。这一说法已经过时约 15 个月。官方 repository 支持 OpenAI Responses API,同时还可以通过 LiteLLM 和 Any-LLM integrations 支持另外 100 个 models。
# Install: pip install "openai-agents[litellm]"# Env: export GEMINI_API_KEY=...import osfrom agents import Agent, Runner, function_toolfrom agents.extensions.models.litellm_model import LitellmModel@function_tooldef current_time_utc() -> str: """Return the current UTC time as an ISO-8601 string.""" from datetime import datetime, timezone return datetime.now(timezone.utc).isoformat(timespec="seconds")# OpenAI Agents SDK using Gemini via LiteLLM. No OpenAI key required.gemini_model = LitellmModel( model="gemini/gemini-2.5-pro", api_key=os.environ["GEMINI_API_KEY"],)agent = Agent( name="time-agent", instructions="Answer time questions using the current_time_utc tool.", model=gemini_model, tools=[current_time_utc],)result = Runner.run_sync(agent, "What is the current UTC time?")print(result.final_output)# -> "The current UTC time is 2026-07-06T14:32:11+00:00."
LitellmModel(model="gemini/gemini-2.5-pro") 的实例化证明,该框架可以将请求路由到 OpenAI 生态之外。无论底层使用哪种 model,@function_tool decorator 的行为都相同。非 OpenAI 路径被记录为 best-effort,不同 provider 之间的 feature parity 也有所差异。在不再受严格 model 限制的情况下,这些框架如今的竞争焦点转向了各自的 architectural primitives。
介绍 Meridian
假设有一家中型 fintech,我们称其为 Meridian。其 engineering department 正在由不同团队构建四个 distinct agents。其中一个小组需要一个 customer support voice agent,通过电话处理计费问题。另一个团队正在构建一个 multi-agent refund workflow,在将工单交给 finance 之前先验证 fraud rules。Developer experience team 希望构建一个内部 code migration agent,能够遍历大型 Java repository,应用 syntax transformations,并创建 pull requests。最后,platform team 正在组装一个 ops dashboard,通过 MCP servers 查询 Sentry、Linear、PagerDuty 和 Postgres。

我们可以观察 Meridian 构建这四种 workload,从而了解哪个框架最适合它们。
Workload 1:Voice 和 Realtime Streaming
Voice team 面临严格的延迟预算。他们需要为 billing support agent 实现低于 500ms 的 streaming。Interrupts 很重要。处理用户 barge-in 是一项要求。将标准 text LLM 封装在 speech-to-text 和 text-to-speech 循环中速度太慢,因为每一次网络跳转都会累积延迟。
OpenAI Agents SDK 很适合处理这一 workload。gpt-realtime-2 model 原生 streaming audio tokens,而 RealtimeAgent 则提供了这一能力的 wrapper。截至 2026 年年中,LangGraph 和 Claude Agent SDK 都没有在这一层级提供原生 realtime primitive。
# Install: pip install openai-agents# Env: export OPENAI_API_KEY=...import asynciofrom agents import function_toolfrom agents.realtime import RealtimeAgent, RealtimeRunner@function_tooldef lookup_billing_balance(account_id: str) -> str: """Return the current outstanding balance for an account.""" # In production, this hits the billing service. Here it is a stub. return "42.17 USD outstanding as of 2026-07-06."voice_agent = RealtimeAgent( name="meridian-billing-voice", instructions=( "You are Meridian's billing voice assistant. Answer politely, briefly. " "Confirm the account_id before disclosing any balance." ), tools=[lookup_billing_balance],)async def main(): runner = RealtimeRunner( starting_agent=voice_agent, config={"model_settings": {"model_name": "gpt-realtime-2.1"}}, ) # session handles the audio stream and tool calls session = await runner.run() async with session: # Wire the audio input source here via sounddevice or pyaudio async for event in session: if event.type == "history_updated": # The item contains the finalized transcript once the turn ends print(f"History updated with item: {event.item}") elif event.type == "error": print(f"Error: {event.error}") breakasyncio.run(main())
RealtimeAgent 和 RealtimeSession classes 会管理 audio-in 和 audio-out streams,以及 tool-calling loop。使用 @function_tool 定义的 tools,在 realtime session 中的工作方式与在 text agent 中完全相同。该框架对外暴露 event loop,同时将 WebSocket state management 抽象掉。
如果要在 LangGraph 或 Claude Agent SDK 中构建这一功能,团队必须自行编写 custom WebSocket handling、voice activity detection 以及复杂的 interrupt semantics。这样一来,项目就会从 agent project 变成 media pipeline project。
如果公司政策规定 voice model 必须是 Claude 或 Gemini,答案就会改变。Anthropic 后来才增加 realtime capabilities,如果你是在 2026 年年中之后阅读本文,团队应当验证 feature parity。

Workload 2:带 HITL 的 Durable Multi-Agent Orchestration
Ops team 正在构建 refund flow。该 workflow 要求先进行 fraud check,然后 handoff 给 finance approval。对于金额超过 $500 的退款,流程必须等待 human review。它必须将最终 decision 写回 Postgres database。系统需要能够承受 server crashes,并在 asynchronous human-in-the-loop pauses 期间保留上下文。
LangGraph 很适合这一 workload。Checkpointers 与 interrupt primitive 的组合,提供了 long-running business processes 所需的精确 control flow。
真实的 engineering teams 已经在 production 中验证了这一架构。Uber 使用 LangGraph 构建 AutoCover 和 Validator systems,节省了约 21,000 个 developer hours。LinkedIn 发布了一篇论文,详细介绍其 Hiring Assistant 使用的 hierarchical semantic memory tree;他们的 supervisor 和 subagent architecture 则分别记录在 LangChain engineering talks 中。
from typing import TypedDict, Literalfrom langgraph.graph import StateGraph, START, ENDfrom langgraph.checkpoint.memory import MemorySaverfrom langgraph.types import interrupt, Commandfrom langchain_google_genai import ChatGoogleGenerativeAI# LangGraph is provider-agnostic. Here it uses Gemini.llm = ChatGoogleGenerativeAI(model="gemini-2.5-pro", temperature=0)class RefundState(TypedDict): order_id: str amount_usd: float customer_reason: str fraud_risk: Literal["low", "medium", "high"] | None finance_decision: Literal["approved", "denied"] | None human_review_needed: booldef fraud_check(state: RefundState) -> RefundState: """Run the LLM-backed fraud check against the customer's stated reason.""" prompt = ( f"Assess fraud risk for refund of ${state['amount_usd']:.2f}. " f"Customer reason: {state['customer_reason']!r}. " "Respond with one word: low, medium, or high." ) verdict = llm.invoke(prompt).content.strip().lower() if verdict not in {"low", "medium", "high"}: verdict = "high" # fail-closed on ambiguous LLM output return {**state, "fraud_risk": verdict}def finance_approval(state: RefundState) -> RefundState: """Above $500 or medium risk, pause for a human. Otherwise auto-approve.""" needs_human = state["amount_usd"] > 500 or state["fraud_risk"] in {"medium", "high"} if needs_human: # Pause the graph. On resume, interrupt returns the human's decision. human_decision = interrupt({ "order_id": state["order_id"], "amount_usd": state["amount_usd"], "fraud_risk": state["fraud_risk"], "prompt": "Approve (yes/no)?", }) return {**state, "human_review_needed": True, "finance_decision": human_decision} return {**state, "human_review_needed": False, "finance_decision": "approved"}# Build the graphgraph = StateGraph(RefundState)graph.add_node("fraud_check", fraud_check)graph.add_node("finance_approval", finance_approval)graph.add_edge(START, "fraud_check")graph.add_conditional_edges( "fraud_check", lambda s: "finance_approval" if s["fraud_risk"] != "high" else END,)graph.add_edge("finance_approval", END)# Checkpointer. For production, swap MemorySaver for PostgresSaver.compiled = graph.compile(checkpointer=MemorySaver())# Run it. Interrupt fires on the $850 refund and the graph pauses.config = {"configurable": {"thread_id": "order-4291"}}result = compiled.invoke( { "order_id": "4291", "amount_usd": 850.00, "customer_reason": "arrived damaged, no photo", "fraud_risk": None, "finance_decision": None, "human_review_needed": False, }, config=config,)# Later, a human reviewer says yes. Resume with Command.final = compiled.invoke(Command(resume="approved"), config=config)
暂停与恢复模式展示了 durable execution 在代码中的实际表现。Finance approval node 内部的 interrupt() function 会将当前 state 写入 checkpointer。系统可以在此时关闭。数小时后,Command(resume="approved") call 会使用相同的 thread ID,从 graph 暂停的位置继续执行,而不会重新运行 fraud check。
这里需要区分 durability 的不同实现。Open-source runtime 会将 state 持久化到 MemorySaver,而它存在于 process memory 中。在负载下实现真正的 crash recovery,需要使用由 Postgres 支持的 LangGraph Platform,或自定义 PostgresSaver 实现。
OpenAI Agents SDK 提供 Sessions 来处理 conversation state,也提供 Sandbox Agents 来执行 long-horizon work。但它没有与 LangGraph 在 arbitrary graph 中进行 node-level checkpointing 直接对应的功能。Claude Agent SDK 在本地提供 JSONL session state,或者提供 Managed Agents 以实现 hosted durability,但会将团队限制在 Claude models 上。LangGraph 目前占据着 durable orchestration 领域。

Workload 3:Coding-Adjacent 以及以 File-and-Shell 为中心的任务
Developer experience team 正在构建一个内部 code migration agent。该 agent 需要遍历一个 400,000 行的 Java repository,应用 syntax transformations,运行 unit tests,并创建 pull requests。Agent 需要读取文件、编辑文件、执行 shell commands,并根据 compiler errors 进行迭代。Bash 和 Edit 就是整个 workload。
Claude Agent SDK 与 DX team 的需求高度匹配。Anthropic 的理念是为你的 agents 提供一台计算机。
该框架原生提供 Bash、Read、Write、Edit、Glob 和 Grep tools。它还包含一个充当 control surface 的 hook system。PreToolUse hook 可以强制实施 security guardrails,防止执行 destructive commands。PostToolUse hook 可以触发 formatters 或 linters。Subagents 会在隔离的 contexts 中并行执行 transformation work,这意味着传递给 subagent 的冗长 compiler error log 不会污染 main agent 的 context window。
# Install: pip install claude-agent-sdk# Env: export ANTHROPIC_API_KEY=...import anyiofrom claude_agent_sdk import ( ClaudeSDKClient, ClaudeAgentOptions, AgentDefinition, HookMatcher,)# PreToolUse hook: block Bash calls that look like rm -rfasync def block_dangerous_bash(input_data, tool_use_id, context): if input_data.get("tool_name") == "Bash": cmd = input_data.get("tool_input", {}).get("command", "") if "rm -rf" in cmd or "rm -rf" in cmd: return { "hookSpecificOutput": { "hookEventName": "PreToolUse", "permissionDecision": "deny", "permissionDecisionReason": "rm -rf blocked by policy", } } return {}# Subagent: runs in isolated context to lint one filelint_agent = AgentDefinition( description="Run linters on a single file and return a concise report.", prompt=( "You are the lint subagent. Given a file path, run the project's linter " "on it and return a one-paragraph summary of failures. Do not fix anything." ), tools=["Bash", "Read"], # Note: tools is deprecated in favor of skills in recent SDKs)options = ClaudeAgentOptions( system_prompt=( "You are Meridian's code migration agent. Walk the target directory, " "apply the migration, run tests, and open a PR. Prefer small commits." ), allowed_tools=["Bash", "Read", "Write", "Edit", "Glob", "Grep"], hooks={"PreToolUse": [HookMatcher(hooks=[block_dangerous_bash])]}, agents={"lint": lint_agent}, # resume="mig-run-2026-07-06-01", # uncomment to resume a prior session)async def main(): async with ClaudeSDKClient(options=options) as client: await client.query( "Migrate services/payments/ from Java 17 to Java 21. " "For every file you touch, delegate to the `lint` subagent afterward. " "Do NOT commit or open PRs yet. Stop after changes are on disk." ) async for message in client.receive_response(): print(message)anyio.run(main)
allowed_tools list 定义了 agent 的 environment。Hook system 提供了一个在 agent loop 内部运行、而不是围绕 agent loop 运行的 guardrail surface。PreToolUse hook 会在 tool 执行之前触发。返回 deny decision 会立即阻止这次调用。
lint subagent 拥有自己的 tool list 和 context window。在最近的 SDK 更新中,Anthropic 已将 AgentDefinition 上的 tools field 标记为 deprecated,建议改用 skills,不过目前仍然可用。被注释掉的 resume line 展示了如何从 local filesystem 上的 JSONL files 中恢复 session state。
LangGraph 要求团队将这些 shell primitives 构建为 custom Python functions。OpenAI Agents SDK 的 Sandbox Agents 运行在 containerized environments 中,在架构上与此相似,但其 primitive set 并不是以相同的 file-centric 方式原生命名或暴露的。
需要注意的是 model lock-in。如果团队在 model layer 上有严格的反 vendor lock-in 规定,Claude Agent SDK 就不是可行选项。此时 LangGraph 会成为 fallback,但团队必须自行重新构建 bash 和 edit primitives。

Workload 4:以 MCP 为主的 Tool Orchestration
Platform team 正在构建一个 one-question ops dashboard。工程师可以提出一个问题,agent 会查询 Sentry 获取 errors、查询 Linear 获取 tickets、查询 PagerDuty 获取 incidents,并查询 Postgres 获取 user data。Agent 的大部分时间都花在编排 third-party MCP servers 上,只有一小部分时间用于综合最终答案。
这个 workload 是 OpenAI Agents SDK 与 Claude Agent SDK 之间的平局。两者都将 MCP 视为一等 primitive,其行为类似于 local functions。LangGraph 也支持 MCP,但截至 2026 年年中,其 ergonomics 需要更多 boilerplate。使用 LangGraph 的团队最终往往需要手动将 MCP servers 封装为 tools。
对于以 MCP 为主的 workload,在 OpenAI 和 Claude 之间做选择取决于次要约束条件。
如果系统需要 first-party tracing、strict guardrails,以及 handoffs 到 specialist sub-agents,请选择 OpenAI Agents SDK。如果公司希望通过 LiteLLM 将 queries 路由到不同的 model providers,以节省简单 synthesis tasks 的成本,那么选择 OpenAI Agents SDK 也很合理。
如果系统能够从 hook lifecycle、strict subagent isolation 以及 Claude 的 tool-use reliability 中获益,请选择 Claude Agent SDK。
为标准 SaaS tools 编写 custom API wrappers 会消耗 engineering time。MCP 对 context 和 tool discovery 进行了标准化。框架只需要不妨碍 agent,让 agent 与 server 对话即可。OpenAI 和 Anthropic 都构建了各自的 SDK,以原生支持这种模式。

决策矩阵

关于 CrewAI
补充说明一下 CrewAI。这是许多开发者预期会在此类比较中看到的框架。在进行验证时,我发现关于 CrewAI 当前版本、Flows 的采用情况以及 enterprise case studies 的主要证据,并不像 LangGraph、OpenAI 和 Anthropic 的相关证据那样经得起检验。与其使用较弱的来源来填充比较内容,我选择将其排除在外。
真正的选择
Meridian 使用三个不同的框架构建了四个 agents。Voice team 和 platform team 使用了 OpenAI SDK。Ops team 使用了 LangGraph。Code migration team 使用了 Claude Agent SDK。
Framework wars 是错误的 engineering decision 视角。问题在于将框架的 primary primitive 与 workload 的形态相匹配。
随着 LangGraph Platform 与 Anthropic Managed Agents 展开 durability 竞争,生态系统的下一轮讨论很可能会再次围绕 durability 展开。我们可能会看到 LangGraph 添加 first-class realtime primitives,或者 Anthropic 将其 SDK 开放给其他 model providers。在此之前,primitives 将决定 architecture。
最后
我在一线科技企业深耕十二载,见证过太多因技术更迭而跃迁的案例。那些率先拥抱 AI 的同事,早已在效率与薪资上形成代际优势,我意识到有很多经验和知识值得分享给大家,也可以通过我们的能力和经验解答大家在大模型的学习中的很多困惑。
我整理出这套 AI 大模型突围资料包:
- ✅AI大模型学习路线图
- ✅Agent行业报告
- ✅100集大模型视频教程
- ✅大模型书籍PDF
- ✅DeepSeek教程
- ✅AI产品经理入门资料
完整的大模型学习和面试资料已经上传带到CSDN的官方了,有需要的朋友可以扫描下方二维码免费领取【保证100%免费】👇👇

为什么说现在普通人就业/升职加薪的首选是AI大模型?
人工智能技术的爆发式增长,正以不可逆转之势重塑就业市场版图。从DeepSeek等国产大模型引发的科技圈热议,到全国两会关于AI产业发展的政策聚焦,再到招聘会上排起的长队,AI的热度已从技术领域渗透到就业市场的每一个角落。

智联招聘的最新数据给出了最直观的印证:2025年2月,AI领域求职人数同比增幅突破200% ,远超其他行业平均水平;整个人工智能行业的求职增速达到33.4%,位居各行业榜首,其中人工智能工程师岗位的求职热度更是飙升69.6%。
AI产业的快速扩张,也让人才供需矛盾愈发突出。麦肯锡报告明确预测,到2030年中国AI专业人才需求将达600万人,人才缺口可能高达400万人,这一缺口不仅存在于核心技术领域,更蔓延至产业应用的各个环节。


资料包有什么?
①从入门到精通的全套视频教程⑤⑥
包含提示词工程、RAG、Agent等技术点

② AI大模型学习路线图(还有视频解说)
全过程AI大模型学习路线

③学习电子书籍和技术文档
市面上的大模型书籍确实太多了,这些是我精选出来的

④各大厂大模型面试题目详解

⑤ 这些资料真的有用吗?
这份资料由我和鲁为民博士共同整理,鲁为民博士先后获得了北京清华大学学士和美国加州理工学院博士学位,在包括IEEE Transactions等学术期刊和诸多国际会议上发表了超过50篇学术论文、取得了多项美国和中国发明专利,同时还斩获了吴文俊人工智能科学技术奖。目前我正在和鲁博士共同进行人工智能的研究。
所有的视频教程由智泊AI老师录制,且资料与智泊AI共享,相互补充。这份学习大礼包应该算是现在最全面的大模型学习资料了。
资料内容涵盖了从入门到进阶的各类视频教程和实战项目,无论你是小白还是有些技术基础的,这份资料都绝对能帮助你提升薪资待遇,转行大模型岗位。


智泊AI始终秉持着“让每个人平等享受到优质教育资源”的育人理念,通过动态追踪大模型开发、数据标注伦理等前沿技术趋势,构建起"前沿课程+智能实训+精准就业"的高效培养体系。
课堂上不光教理论,还带着学员做了十多个真实项目。学员要亲自上手搞数据清洗、模型调优这些硬核操作,把课本知识变成真本事!


如果说你是以下人群中的其中一类,都可以来智泊AI学习人工智能,找到高薪工作,一次小小的“投资”换来的是终身受益!
应届毕业生:无工作经验但想要系统学习AI大模型技术,期待通过实战项目掌握核心技术。
零基础转型:非技术背景但关注AI应用场景,计划通过低代码工具实现“AI+行业”跨界。
业务赋能 突破瓶颈:传统开发者(Java/前端等)学习Transformer架构与LangChain框架,向AI全栈工程师转型。
👉获取方式:
😝有需要的小伙伴,可以保存图片到wx扫描二v码免费领取【保证100%免费】🆓**

更多推荐


所有评论(0)