- 在 Agent 领域,“SDK”这个词被用得非常宽泛:
openai包、OpenAI Agents SDK、Claude Agent SDK、Tool Runner、pi、DSH 都被称为 SDK,但它们解决的问题不在同一层。 - 本文把 Agent 技术栈拆成 L0–L5 六层,并把 OpenAI、Claude、pi、DSH 的每个产品放到对应的位置。
- 选型本质上是在回答一个问题:这一层你想自己写,还是交给别人?
这是一篇概念性文章,不绑定具体的 SDK 版本。文中各产品归属哪一层,以 2026-10-09 各官方文档为准,出处见文末脚注。各 SDK 的具体版本号,见对应专题笔记开头的「版本与时效声明」。
1. 为什么需要一张分层图#
先看一组容易混淆的名字:
| 名字 | 它实际是什么 | 所在层(见下文) |
|---|---|---|
openai(Python 包) | OpenAI REST API 的官方客户端库 | L1 |
OpenAI Agents SDK(openai-agents) | 构建在 Responses API 之上的 Agent 运行时,包含 Runner、handoffs、guardrails、sessions 等 | L3,部分能力到 L4 |
| OpenAI Agents API(beta) | OpenAI 托管的 Codex harness | L5 |
anthropic(Python 包) | Claude API 客户端库,其中带一个 beta 的 Tool Runner | L1(Tool Runner 属于 L3) |
| Claude Agent SDK | 把 Claude Code 打包成库,带内置工具、权限、会话和 hooks | L4 |
| Claude Managed Agents(beta) | Anthropic 托管的 harness 加沙箱 | L5 |
| pi | 一组分层的包:pi-ai(L1)、pi-agent-core(L3)、pi-coding-agent(L4) | L1–L4 |
| DSH(DeepSeek Harness) | 基于 Cordis 的“一切皆插件” harness | L1–L4,每层都是插件 |
Anthropic 的官方文档专门用一张表区分了 Agent SDK、Claude Code CLI、Client SDK(含 tool runner)和 Managed Agents,区分的依据是“谁来运行 agent、内置了什么、通过什么方式访问”1。OpenAI 的文档也给出了 Agents API、Agents SDK、Responses API 三者的对比表2。两家厂商都在主动澄清这件事,说明它确实容易混淆。
2. 六层模型#
从下往上看:每往上一层,框架替你做的事就多一些,你能直接控制的细节就少一些。
L0 · 模型 HTTP API#
- 本质:一个 HTTP 接口,例如 OpenAI 的
POST /v1/responses、Anthropic 的POST /v1/messages。 - 有状态还是无状态
- 你需要自己处理:鉴权、序列化、重试、超时、SSE 流式解析。
L1 · 客户端 SDK(Client SDK)#
- 把 L0 包装成类型安全的方法调用,例如
client.responses.create(...)、client.messages.create(...)。 - 典型能力:类型定义、自动重试、超时控制、流式 helper、分页。以 Anthropic Python SDK 为例,它默认对连接错误以及 408、409、429 和 5xx 自动重试 2 次,默认超时为 10 分钟5。
- 特例:
pi-ai是一个“统一多厂商”的 L1。它用同一套Context和消息格式对接 OpenAI、Anthropic、Google、DeepSeek 等数十家提供方,并支持在对话中途切换模型6。
L2 · 工具调用协议(Tool Calling / Function Calling)#
- 模型本身不会执行任何代码。它只会返回一个结构化的请求,意思是“我想调用某个函数,参数是这些”;真正执行的是你的程序7。
- 按执行位置可以分成两类8:
- 客户端工具:由你的程序执行,比如你自己定义的
get_weather。 - 服务端工具:由厂商执行,比如 web search、code execution。
- 客户端工具:由你的程序执行,比如你自己定义的
- 完整的往返过程见 1.2 Tool Calling 与 Agent Loop 原理。
L3 · Agent Loop(智能体循环)#
- 自动重复“调用模型 → 执行工具 → 把结果放回上下文 → 再调用模型”,直到模型不再请求工具为止。
- 代表实现:
L4 · Harness(驾驭层,即完整的 Agent 运行时)#
“harness”原意是马具:给模型这匹马套上缰绳和车辕,它才能拉车干活。在 Agent 语境里,harness 指的是在 L3 循环之外再加上一整套“干活的设施”:
| 组件 | 作用 | Claude Agent SDK | pi-coding-agent | DSH |
|---|---|---|---|---|
| 内置工具 | 读写文件、执行命令、搜索 | Read、Edit、Write、Bash、Glob、Grep、WebSearch 等13 | 默认只启用 read、bash、edit、write 四个14 | tool-fs、tool-bash、tool-fs-search 等插件15 |
| 上下文管理 | 接近窗口上限时压缩历史 | 自动 compaction13 | compaction16 | compaction 插件族17 |
| 会话持久化 | 恢复、分叉 | JSONL 会话,支持 resume、fork18 | 树状 JSONL,支持分支16 | 事件溯源的 session log12 |
| 权限与沙箱 | 拦截危险操作 | 权限模式加 hooks13 | 不内置权限系统,靠扩展或容器19 | 沙箱阶梯加审批,fail-closed20 |
| 扩展机制 | 定制行为 | hooks、subagents、skills、plugins、MCP1 | extensions、skills、packages19 | 一切皆插件(Cordis)12 |
三者对自己的定位:
- Claude Agent SDK:提供与 Claude Code 相同的工具、agent loop 和上下文管理1。
- pi:自称 a minimal, extensible agent harness19。
- DSH:自称开源的 agent harness,架构是“一切皆插件”21。
- OpenAI:Agents SDK 里的 Sandbox Agents 补上了 workspace、文件和 shell 这一类 harness 能力22。
L5 · 托管 Agent 服务(Hosted Agents)#
- 由厂商替你运行 harness、沙箱和会话存储,你只通过 REST 接口和 SSE 事件流与它交互。
- 目前的代表:
- Claude Managed Agents:2026-04-08 公测23,详见 3.4 Claude Managed Agents。
- OpenAI Agents API:2026-09-10 随 openai-python 3.13.0 加入 SDK,运行的是 OpenAI 托管的 Codex harness2425,详见 2.4 OpenAI Agents API。
Responses API 的 web_search、Claude 的 code_execution 只是让厂商代为执行某一个工具,循环本身仍可能在你的程序里。L5 指的是整个循环加运行环境都放在厂商那边。
3. 四家产品在分层上的位置#
图中几条依赖关系的出处:
- Agents SDK 默认通过 Responses API 调用 OpenAI 模型26。
- Claude Agent SDK 会启动并管理一个
claudeCLI 子进程,通过 stdio 与它通信27。 - pi 的三个包逐层依赖11。
- DSH 有一个基于 pi-ai 的适配器插件
dsh-llm-pi-ai,作者称它为官方 DeepSeek 适配器的“设计验证孪生”28。
这一节的两个“轻量级”项目之间有真实的代码联系:DSH 的 LLM 层可以直接借用 pi-ai 的多厂商能力。
4. 一个 Agent 由什么组成#
| 部件 | 比喻 | 说明 | 对应层 |
|---|---|---|---|
| 模型(LLM) | 大脑 | 决定下一步做什么 | L0 / L1 |
| 指令(system prompt) | 岗位说明书 | 告诉模型它是谁、该怎么做 | L1 |
| 工具(tools) | 手和脚 | 读写文件、调用 API、执行命令 | L2 |
| 循环(loop) | 心跳 | 反复执行“思考 → 行动 → 观察” | L3 |
| 上下文与记忆 | 工作台 | 当前对话、工具结果、压缩后的摘要 | L3 / L4 |
| 会话存储 | 日记本 | 可以恢复、分叉、回放 | L4 |
| 运行环境与沙箱 | 工位和围栏 | 让工具在受控的环境里执行 | L4 / L5 |
| 护栏与权限 | 安全员 | 校验输入输出,审批危险操作 | L3 / L4 |
| 可观测性(tracing) | 行车记录仪 | 记录每一步,方便调试和评估 | L3 / L4 |
5. 关键术语速查#
更完整的定义见 术语表。
| 术语 | 一句话解释 |
|---|---|
| Agent | OpenAI 的定义是“配备了指令和工具的 LLM”26;Claude Agent SDK 的定义是“通过自己规划步骤、调用工具来完成任务的应用”1 |
| Harness | Agent 的完整运行时,等于循环加工具、上下文、会话、权限、扩展机制(见上文 L4) |
| Tool / Function Calling | 模型输出结构化的调用请求,由程序执行后把结果回传给模型7 |
| 服务端工具 / Hosted Tool | 由厂商代为执行的工具,例如 web search、code interpreter8 |
| MCP | Model Context Protocol,一个开放协议,规定应用如何以标准方式向 LLM 提供工具和上下文29 |
| Skills | 可复用的“说明书 + 脚本”包,通常是一个带 SKILL.md 的目录,在需要时才加载3016 |
| Handoff / Subagent | 多 Agent 协作:控制权转交给另一个 agent(handoff),或者派生一个子 agent 去完成子任务(subagent)3132 |
| Guardrail | 对输入、输出或工具调用做校验,不通过就中断执行33 |
| Compaction | 上下文接近窗口上限时,把较早的历史压缩成摘要13 |
| Sandbox | 隔离的执行环境,限制工具能读写哪些文件、能访问哪些网络20 |
6. 怎么用这张图做选型#
| 你的需求 | 建议的起点 |
|---|---|
| 只是调用模型做摘要、分类、抽取 | L1 客户端 SDK |
| 自定义工具,并且想完全控制流程 | L1 + 手写循环(参考 1.2 Tool Calling 与 Agent Loop 原理) |
| 想少写循环代码,但工具都是自己的 | L3:Agents SDK、Tool Runner、pi-agent-core |
| 需要一个能读写文件、跑命令的“干活型” agent | L4:Claude Agent SDK、pi-coding-agent、DSH |
| 不想运维,要长时间运行和托管沙箱 | L5:Managed Agents、Agents API |
| 要多厂商切换,或者想完全掌控上下文 | pi、DSH |
详细对比见 6.2 横向对比与选型建议;用同一个任务对比几种写法,见 6.1 同一个任务的六种写法。
小结#
- L1 解决“怎么调用模型”,L3 解决“怎么循环”,L4 解决“怎么让循环真正去干活”,L5 解决“谁来运维”。
- OpenAI 和 Claude 在每一层都有官方产品;pi 和 DSH 则把 L1 到 L4 全部开源,并且可以替换。
- 后续各篇都会先回答“它处在哪一层”,再展开讲细节。
相关笔记#
- 1.2 Tool Calling 与 Agent Loop 原理:L2 和 L3 的原理,以及手写循环
- 2.1 OpenAI 开发者生态全景 · 3.1 Claude 开发者生态全景 · 4.1 pi 全景与设计哲学 · 5.1 DeepSeek Harness 全景
- 6.2 横向对比与选型建议
参考资料#
注释与出处#
-
Anthropic,Agent SDK overview,https://code.claude.com/docs/en/agent-sdk/overview (访问于 2026-10-09) ↩ ↩2 ↩3 ↩4
-
OpenAI,Agents(Agents API、Agents SDK、Responses API 对比表),https://developers.openai.com/api/docs/guides/agents ↩
-
Anthropic,Working with the Messages API,原文写明 “The Messages API is stateless”,https://platform.claude.com/docs/en/build-with-claude/working-with-messages ↩
-
OpenAI,Conversation state(含
previous_response_id、Conversations API、30 天存储说明),https://developers.openai.com/api/docs/guides/conversation-state ↩ -
Anthropic,Python SDK(Retries 与 Timeouts 两节),https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python ↩
-
earendil-works/pi,
packages/ai/README.md(commit6fb2e78),https://github.com/earendil-works/pi/blob/6fb2e7815167e6b19006fc526d1a5d0f5f998787/packages/ai/README.md ↩ -
OpenAI,Function calling,https://developers.openai.com/api/docs/guides/function-calling ↩ ↩2
-
Anthropic,Tool use with Claude(客户端工具与服务端工具),https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview ↩ ↩2
-
openai/openai-agents-python,
docs/running_agents.md(commit26345c1),https://github.com/openai/openai-agents-python/blob/26345c1e45ebede8e2fc9b0bc7341dedab5e01fc/docs/running_agents.md ↩ -
Anthropic,Tool Runner (SDK),https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner ↩
-
earendil-works/pi,
packages/agent/README.md,https://github.com/earendil-works/pi/blob/6fb2e7815167e6b19006fc526d1a5d0f5f998787/packages/agent/README.md ↩ ↩2 -
deepseek-ai/deepseek-harness,
docs/architecture.zh.md(commit5badb15),https://github.com/deepseek-ai/deepseek-harness/blob/5badb15009ae1756c3afe0ae0cef1faafc290ccc/docs/architecture.zh.md ↩ ↩2 ↩3 -
Anthropic,How the agent loop works,https://code.claude.com/docs/en/agent-sdk/agent-loop ↩ ↩2 ↩3 ↩4 ↩5
-
earendil-works/pi,
packages/coding-agent/src/core/settings-manager.ts第 83 行DEFAULT_TOOL_NAMES,https://github.com/earendil-works/pi/blob/6fb2e7815167e6b19006fc526d1a5d0f5f998787/packages/coding-agent/src/core/settings-manager.ts#L83 ↩ -
deepseek-ai/deepseek-harness,
packages/bundle/web-app/presets/standard.patch.yml,https://github.com/deepseek-ai/deepseek-harness/blob/5badb15009ae1756c3afe0ae0cef1faafc290ccc/packages/bundle/web-app/presets/standard.patch.yml ↩ -
earendil-works/pi,
packages/coding-agent/docs/how-pi-works.md,https://github.com/earendil-works/pi/blob/6fb2e7815167e6b19006fc526d1a5d0f5f998787/packages/coding-agent/docs/how-pi-works.md ↩ ↩2 ↩3 -
deepseek-ai/deepseek-harness,
packages/compaction/,https://github.com/deepseek-ai/deepseek-harness/tree/5badb15009ae1756c3afe0ae0cef1faafc290ccc/packages/compaction ↩ -
Anthropic,Work with sessions,https://code.claude.com/docs/en/agent-sdk/sessions ↩
-
earendil-works/pi,根目录
README.md(含 “Permissions & Containerization” 一节),https://github.com/earendil-works/pi/blob/6fb2e7815167e6b19006fc526d1a5d0f5f998787/README.md ↩ ↩2 ↩3 -
deepseek-ai/deepseek-harness,
packages/sandbox/sandbox/README.zh.md,https://github.com/deepseek-ai/deepseek-harness/blob/5badb15009ae1756c3afe0ae0cef1faafc290ccc/packages/sandbox/sandbox/README.zh.md ↩ ↩2 -
deepseek-ai/deepseek-harness,
README.zh.md,https://github.com/deepseek-ai/deepseek-harness/blob/5badb15009ae1756c3afe0ae0cef1faafc290ccc/README.zh.md ↩ -
openai/openai-agents-python,
docs/sandbox_agents.md,https://github.com/openai/openai-agents-python/blob/26345c1e45ebede8e2fc9b0bc7341dedab5e01fc/docs/sandbox_agents.md ↩ -
Anthropic,Release notes,2026-04-08 条目:“launched Claude Managed Agents in public beta”,https://platform.claude.com/docs/en/release-notes/overview ↩
-
OpenAI,Agents API,https://developers.openai.com/api/docs/guides/agents-api/overview ↩
-
openai/openai-python,
CHANGELOG.md中 3.13.0(2026-09-10)条目 “add Agents API”,https://github.com/openai/openai-python/blob/9301e319ea33ef28fba380f39a289dedc14652c1/CHANGELOG.md ↩ -
openai/openai-agents-python,
docs/index.md,https://github.com/openai/openai-agents-python/blob/26345c1e45ebede8e2fc9b0bc7341dedab5e01fc/docs/index.md ↩ ↩2 -
Anthropic,Hosting the Agent SDK(The subprocess model 一节),https://code.claude.com/docs/en/agent-sdk/hosting ↩
-
deepseek-ai/deepseek-harness,
packages/llm/llm-pi-ai/package.json的 description 字段,https://github.com/deepseek-ai/deepseek-harness/blob/5badb15009ae1756c3afe0ae0cef1faafc290ccc/packages/llm/llm-pi-ai/package.json ↩ -
Model Context Protocol 官方介绍,https://modelcontextprotocol.io/introduction ↩
-
Anthropic,Agent Skills overview,https://platform.claude.com/docs/en/agents-and-tools/agent-skills/overview ↩
-
openai/openai-agents-python,
docs/multi_agent.md,https://github.com/openai/openai-agents-python/blob/26345c1e45ebede8e2fc9b0bc7341dedab5e01fc/docs/multi_agent.md ↩ -
Anthropic,Subagents in the SDK,https://code.claude.com/docs/en/agent-sdk/subagents ↩
-
openai/openai-agents-python,
docs/guardrails.md,https://github.com/openai/openai-agents-python/blob/26345c1e45ebede8e2fc9b0bc7341dedab5e01fc/docs/guardrails.md ↩ -
deepseek-ai/deepseek-harness,
docs/glossary.zh.md(“循环层级”一节),https://github.com/deepseek-ai/deepseek-harness/blob/5badb15009ae1756c3afe0ae0cef1faafc290ccc/docs/glossary.zh.md ↩