跳到主要内容Skip to main content
← Harness

OpenAI Agents SDKOpenAI Agents SDK

OpenAI
Python 开源 MIT 编程底座 通用harness guardrails MCP human-in-the-loop sandbox partial lifecycle: active 核验Checked 2026-09-30

OpenAI Agents SDK 是「primitives-only 的多agent harness」。

官方自述 lightweight yet powerful:filesystem / 规划 / 记忆都不替你决定。

"A primitives-only multi-agent harness" — the official description is "lightweight yet powerful": it hands you the agent-loop primitives and does not decide for you how the filesystem, planning or memory work.

适合与不适合When to use it, when not to

适合:

  • 要薄 harness,要内建 guardrails 与 human-in-the-loop。
  • 要 MCP 一等支持,团队是 Python 栈。

不适合:

  • 要开箱即用的长任务工作区(用 Deep Agents 或走 SandboxAgent 路线)。
  • TypeScript 生态(用 openai-agents-js)。

Fits: you want a thin harness with built-in guardrails / human-in-the-loop, first-class MCP support, and a Python stack. Not a fit: a ready-made long-task workspace (use Deep Agents or the SandboxAgent route); a TypeScript ecosystem (use openai-agents-js).

中文生态China availability 国产 / 国内可直接用 / 备案状态 · 快照domestic / direct access / CAC filing · snapshot 2026-10-20

出品属地Origin
国外出品foreign-made 国外主体(网信办公示名单未见对应备案主体)。foreign entity (no matching filing entity in the CAC registry).
国内使用Direct access
大陆可直连direct OK openai.github.io 直连实测 200;PyPI 实测可达。openai.github.io measured 200 direct; PyPI measured reachable.
备案状态CAC filing
未见于备案名单not in filing list:未见于网信办公示名单(2026-10-20 检索 13 批附件,https://www.cac.gov.cn/2024-04/02/c_1713729983803145.htm);该产品未面向大陆公众提供服务,备案不适用。not in the CAC public registry (13 batch attachments searched 2026-10-20, https://www.cac.gov.cn/2024-04/02/c_1713729983803145.htm); the product does not serve the mainland public, so filing does not apply.

备案信息以网信办《生成式人工智能服务已备案信息》公示名单为准(按批次滚动更新,本站只抄编号不解读);「大陆可直连」是本站从大陆网络直连实测的结果,不是厂商承诺。GitHub 类站点当日实测有波动,口径写在依据里。Filing status is quoted from the CAC public registry (updated batch by batch; this site copies the number and does not interpret it). "Direct access" is this site's own reachability measurement from a mainland network, not a vendor promise. GitHub-hosted sites fluctuated on the measurement day — the note says so.

固定坐标系Fixed coordinate system

8 个维度dimensions, 与同分区其他对象逐项可比each comparable item by item against others in the same section.

模型与开放条件Model & openness

官方自述 provider-agnostic。 官方的接入口径是一句话: 支持 OpenAI 两套 API,也支持 100+ 其他 LLM。

官方原文:"It is provider-agnostic, supporting the OpenAI Responses and Chat Completions APIs, as well as 100+ other LLMs."

实现路径有两层证据:

  • 核心依赖是 openai>=3.0.0。
  • 可选依赖有两个 extra,都是非 OpenAI 路径。

两个 extra 分别是 litellm(openai-agents[litellm]) 与 any-llm(openai-agents[any-llm],要求 Python ≥3.11)。

官方 models 页给出完整接入面(已核验)。 官方专列 "Non-OpenAI models" 与 "Third-party adapters" 两节。

两节里的接入点:

  • 内置 provider 接入点可指向 OpenAI 兼容端点。
  • 另有 Any-LLM / LiteLLM 两个 beta 适配器。

内置接入点的官方示例:

MultiProvider(openai_base_url="https://openrouter.ai/api/v1")

适配器的官方示例:

anthropic/claude-3-5-sonnet

LiteLLM 页上的口径是:一个接口接 100+ 模型,也可以用任何 AI 模型。

官方原文:"allows you to use 100+ models via a single interface ... use any AI model in the Agents SDK"

换 provider 的改动量 = 换 model(字符串名 / LitellmModel(...) / provider 前缀)。

⚠ 但官方没有「零改动」的量化承诺,各家能力对齐度需实测。

运行位置Where it runs

你自己运营进程 —— 它是库,不是服务。

README 的四种运行方式全部是本地代码调用:

  • Runner.run_sync
  • RealtimeRunner.run
  • VoicePipeline.run
  • sandbox client

唯一例外是 SandboxAgent 的 hosted sandbox client —— 官方提到可以用托管沙箱。

⚠ 但那依赖 OpenAI 侧的容器服务,不是「整个 agent 托管」。

本地文件Local files

本地文件能力明确存在,但不在默认 agent 里。

官方为「需要检查文件、跑命令、打补丁,或在长任务间保留工作区状态」 的场景单独提供了 SandboxAgent。

官方原文:SandboxAgent 是 preconfigured to work with a container to perform work over long time horizons

它的 default_manifest 里可以声明 GitRepo(repo=..., ref=...)。

沙箱客户端分平台:

  • UnixLocalSandboxClient —— macOS / Linux。
  • Windows 须用 DockerSandboxClient(需 openai-agents[docker] extra)。
  • Windows 也可用 hosted sandbox client。

⚠ 这条是本站选型时的实用信息:Windows 用户不能直接用本地 Unix 沙箱路径。

关机后的任务Tasks after shutdown

自托管 = 关了就停。 README 没有托管执行选项 (Realtime 是长连接,但进程仍在自己手里)。

断点续跑有官方支撑。 Sessions 章节写明 官方原文:"Automatic conversation history management across agent runs"。

可选后端有 SQLite(SQLAlchemy 依赖)与 Redis(openai-agents[redis])。

SandboxAgent 的 default_manifest 也面向 官方原文:"preserve workspace state across longer tasks"。

工具与扩展Tools & extensions

工具面是官方列出的四类:functions、MCP、hosted tools, 以及 agents as tools(把别的 agent 当工具调)。

后两类与 handoffs 并列,都是核心委派机制。

MCP 是核心依赖,不是可选。 这一点看 tools 的依赖声明:

  • mcp>=1.19.0,<3 写在 dependencies 里。
  • 它不在 optional-dependencies 里,是一等能力。

Guardrails 可配置。 官方列「Configurable safety checks for input and output validation」,分 input 与 output 两个方向。

上下文与记忆Context & memory

官方原文只有 Sessions。

官方原文:"Automatic conversation history management across agent runs"

可选后端有 Redis(openai-agents[redis]) 与 SQLAlchemy(SQLAlchemy + asyncpg 依赖)。

注意与本站主张的分野。

Sessions 管的是会话历史。

本站的「状态 ≠ 上下文」主张里,把大工具输出落盘这类手段在本 SDK 属用户自建。

SandboxAgent 的沙箱工作区可以承担这个角色,但官方没有把它宣传成 context 管理层。

权限与限制Permissions & limits

内建 Guardrails(输入 + 输出双向校验)+ Human in the loop(工具级审批)。

这是本站目前见到的权限面最完整的内建方案。两句官方原文:

官方原文:"Configurable safety checks for input and output validation"

官方原文:"Built-in mechanisms for involving humans across agent runs"

机制细节已核验(官方 guardrails 与 human_in_the_loop 专章)。 guardrails 共三类:

  • input —— 只在链条第一个 agent 跑。
  • output —— 只在产出最终输出的 agent 跑。
  • tool —— 包 FunctionTool,执行前后各校验一次,可 skip/replace/raise tripwire。

第三条的 tripwire 命中即抛异常并立即中止。

input 侧可选 run_in_parallel=False,在 agent 启动前拦截。

工具级审批:needs_approval=True|callable 可用在 function_tool、ShellTool、ApplyPatchTool、Agent.as_tool。

MCP server 用 require_approval。

审批以 run-wide interruptions 暂停,RunState 可序列化/恢复。 参数无法安全解析时 fail closed,always_approve 可固化决策。

⚠ 边界要说清:官方没有内建文件/网络沙箱。

guardrails 是用户可编程的校验钩子;真正的沙箱边界交宿主机或 SandboxAgent 容器,不在 guardrail 层。

(已查 guardrails、human_in_the_loop、Sandbox agents 三页。)

与 Deep Agents 的「trust the LLM,边界责任交给你」形成鲜明对照。

适合什么任务Best for

适合:

  • 想要「薄 harness」,agent loop 原语之外的自己挑。
  • 需要 guardrails 与 human-in-the-loop 是内建的。
  • 需要 MCP 一等支持,团队是 Python 栈。

不适合:

  • 想要开箱即用的长任务工作区。
  • 追求 TypeScript 生态(该用 openai-agents-js)。

不适合的两条各有替代路线。长任务工作区用 Deep Agents, 或走该 SDK 的 SandboxAgent 路线。

头号误解Top misconception

  • 以为「provider-agnostic」= 换provider 零改动 —— 文档给了 100+ 的承诺但没给量化保证,本站标记为未核验Reading "provider-agnostic" as "switching providers costs nothing" — the docs promise 100+ without a quantified guarantee; this site marks it unverified
  • 以为 SandboxAgent 在 Windows 上开箱可用 —— 本地路径只有 UnixLocalSandboxClient(macOS/Linux),Windows 要走 Docker 或 hostedAssuming SandboxAgent works out of the box on Windows — the local path is only UnixLocalSandboxClient (macOS/Linux); Windows needs Docker or hosted
  • 以为 Guardrails 能当权限护栏用 —— 它是输入/输出校验,不是沙箱边界;两者能解决的风险类型不同Assuming Guardrails work as a permission boundary — they are input/output validation, not a sandbox boundary; they address different risk types
  • 以为这是 OpenAI 闭源 SDK 的「官方壳」 —— 它本身是 MIT 开源框架,官方明确「committed to continuing to build the Agents SDK as an open source framework」Assuming this is an official shell around OpenAI's closed-source SDK — it is itself an MIT-licensed framework, and the official docs state they are "committed to continuing to build the Agents SDK as an open source framework"

未知项清单Known unknowns

  • 100+ provider 各自的能力对齐度矩阵
  • hosted sandbox client 的可用区域、配额与计费方式(报价按 D9 口径本站不采)
  • Sessions 后端在多进程/多机下的并发写语义
  • litellm / any-llm extra 的实际依赖体积与升级冲突

证据来源Evidence sources

判断可回到以下一手源复核。本站核验日Every judgement can be rechecked against the primary sources below. Verified on 2026-09-30,内容更新日content updated on 2026-09-30。

类型Type名称Name链接Link
repoOpenAI Agents SDK · 仓库(Python)https://github.com/openai/openai-agents-python
docs官方文档首页https://openai.github.io/openai-agents-python/
docsModels(provider-agnostic、Non-OpenAI models、Any-LLM / LiteLLM 适配器)https://openai.github.io/openai-agents-python/models/
docsUsing any model via LiteLLM("use any AI model"、100+ models)https://openai.github.io/openai-agents-python/models/litellm/
docsSandbox agents(官方专章)https://openai.github.io/openai-agents-python/sandbox_agents
docsGuardrails(官方专章)https://openai.github.io/openai-agents-python/guardrails/
docsHuman in the loop(官方专章)https://openai.github.io/openai-agents-python/human_in_the_loop/
docsSessions(官方专章)https://openai.github.io/openai-agents-python/sessions/
docsSandbox clients(平台差异与 hosted client)https://openai.github.io/openai-agents-python/sandbox/clients/
repoAgents SDK JS/TS(独立仓,MIT,3,882★,核验 2026-09-30)https://github.com/openai/openai-agents-js
changelogReleases(0.22.3 @ 2026-09-17)https://github.com/openai/openai-agents-python/releases

实测记录Measured runs

本站尚未完成实测。测试协议见 tasks/_protocol.md。

实测建议(按 harness 分区五维度定制到这个 SDK 的重点):

#测什么为什么值得测
1最小 hello agent 要几个文件、多少行官方称 lightweight,要验证「薄」到什么程度
2Guardrails 能不能拦住「读文件」类越权官方定位是 input/output 校验,与文件访问权限不是一回事
3SandboxAgent 在 Windows 上的最小可用路径官方示例是 Unix,Windows 要另走 Docker
4换成 litellm / any-llm 接本地模型要改多少官方说 provider-agnostic,验证真实改动量
5Sessions 断掉进程后恢复状态是否完整这是本站最关心的「可靠长期运行」

provider-agnostic 是官方写在首段的

官方首段把这条写在最前面:

The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
It is provider-agnostic, supporting the OpenAI Responses and Chat Completions APIs, as well as 100+ other LLMs.

这是本站的第一决策点。 代码层面的证据也一致:

  • 核心依赖 openai>=3.0.0。
  • 另有 litellm 与 any-llm 两个可选 extra,作为非 OpenAI 路径。

⚠ 但要说清边界:「100+」是官方声明,本站未实测具体各家 provider 的能力对齐度。

工具调用、structured output、多模态在各家差异很大。

与 Deep Agents 的对照:本站最该给用户看的一张表

两个都在 Python agent harness 档,风格完全相反:

维度OpenAI Agents SDKDeep Agents
风格primitives-only,薄batteries-included,厚
filesystem不预置(要自己接,或用 SandboxAgent)核心卖点,可插拔后端
子代理agents as tools / handoffs(需自己建)预置 sub-agents
上下文管理只有 Sessions(会话历史)summarize + 落盘 + 跨会话记忆
权限内建 guardrails + human-in-the-loop官方明说「trust the LLM」,边界归你
运行形态你自己跑(本地/容器/Redis)你自己跑

选型口诀:想要「安全内建」选前者,想要「功能内建」选后者。

SandboxAgent:本地文件能力的官方答案,但有个 Windows 坑

普通 Agent 不带本地工作区。官方为此单独提供 SandboxAgent:

Use a SandboxAgent when the agent needs to inspect files, run commands, apply patches, or preserve workspace state across longer tasks.

它的 default_manifest 可以声明要检出的仓库:

``python agent = SandboxAgent( name="Workspace Assistant", default_manifest=Manifest( entries={"repo": GitRepo(repo="openai/openai-agents-python", ref="main")} ), ) ``

⚠ 平台差异是选型时必须知道的:

客户端支持平台说明
UnixLocalSandboxClientmacOS / LinuxREADME 示例用的就是它
DockerSandboxClientWindows 等需 openai-agents[docker] extra
hosted sandbox client依赖 OpenAI 侧服务官方提到可用

Windows 用户不能直接走本地 Unix 沙箱路径。

权限面:目前本站见到的最完整内建方案

官方提供章节
Guardrails(input + output 双向校验)「Configurable safety checks for input and output validation」
Human in the loop(跨多次运行引入人工)「Built-in mechanisms for involving humans across agent runs」

对比 Deep Agents 的官方声明(原文):

Deep Agents follows a "trust the LLM" model... Enforce boundaries at the tool/sandbox level, not by expecting the model to self-police.

这两句话就是本站「权限归属」这个问题的两种答案,也是一个真实的选择依据。

你要内建的输入输出校验,还是你要自己划沙箱边界?

机制已核验(见 axes.permissions):

  • guardrails 分 input / output / tool 三类,命中抛 tripwire 中止。
  • 工具级审批 needs_approval 覆盖 function_tool / ShellTool / ApplyPatchTool / MCP。

⚠ 边界:官方无内建文件/网络沙箱。

guardrail 是用户可编程校验钩子。真正的沙箱边界交宿主机或 SandboxAgent 容器。

「状态 ≠ 上下文」在这两个 SDK 里的不同答案

OpenAI Agents SDKDeep Agents
会话历史Sessions(Redis / SQLAlchemy 后端)persistent memory(pluggable state and store)
长上下文无官方 context management 层summarize long threads
大输出落盘无官方宣称(SandboxAgent 的工作区可承担)offload tool outputs to disk

本站主张「持久化 ≠ 压缩」时,Deep Agents 是有官方落盘手段的那一方。

⚠ 但要注意:SandboxAgent 的工作区保留(preserve workspace state) 实际上也是一种持久化。

只是官方没把它归类成 context management。

这是本站的判断,不是官方表述,已标注为推断。

MCP 是一等能力,不是可选插件

pyproject.toml 里 mcp>=1.19.0,<3 在 dependencies,而非 optional-dependencies。

官方 README 把 MCP 与 functions、hosted tools 并列为工具类型。

在这套 SDK 里接 MCP server 不需要额外装东西。

附:JS/TS 版是独立仓,本站不单独收录

README 里明确指向 openai/openai-agents-js(核验 2026-09-30:MIT,3,882★,活跃)。

⚠ 本站不把它作为独立对象收录:同一产品的第二语言实现, 与本站「一个对象 = 一套决策依据」的粒度不符(同 Deep Agents Code 的处理法)。 记录在此是因为选型时需要知道「Python 版之外还有 JS/TS 版」。

核验说明

confidence: partial 的依据(2026-10-03 由 verified 降级):

为什么降级:下方 ❌ 项的主语是本站的取证缺口,不是「官方未提供」。 按 v3 铁律「未知就说未知」,这些条目存在时标 verified 属于虚高,故降为 partial。 主要缺口:100+ provider 的实际能力对齐度(A6.2 已补:guardrail 三类机制与工具级审批已核验)。

✅ 已核验清单:

  • 仓库存在与星数(29,792)、许可(MIT,经 license API)。
  • 最近推送(2026-10-01,仍活跃)。
  • 最新版本 0.22.3(releases @ 2026-09-17)。
  • pyproject.toml 全文关键项(requires-python >=3.10、mcp>=1.19.0,<3 是核心依赖、 litellm/any-llm/sqlalchemy 均为可选 extra)。
  • README 全文十项核心概念、四种运行方式代码示例。
  • SandboxAgent 段落与平台差异、JS 版仓元数据。

❌ 未核验清单:

  • 100+ provider 的实际能力对齐度。
  • hosted sandbox client 的可用性与计费方式(报价按 D9 口径本站不采)。
  • Sessions 的具体后端语义。
  • Realtime/Voice 路径的成本。

相关条目Related entries

  • Deep Agents本站最值得对照的一对:Deep Agents 是 batteries-included(含 filesystem + 子代理 + 上下文管理),本 SDK 是 primitives-only。同一决策树的两个分支。
  • Claude Agent SDK同为「编程底座」档,且同样出自模型厂商。OpenAI 侧走 primitives-only + guardrails 内建,Anthropic 侧的主场是 Claude Code。
  • LangGraphLangGraph 是 graph runtime,OpenAI Agents SDK 是 agent harness —— 可组合(把图当工具/子代理),但层级不同。
  • Codex CLICodex CLI另一层 · 现成的 AI 工具Other layer · Ready-made AI tools

本页由This page is generated from the ai-agent-guide 数据层生成(CC BY 4.0)。data layer (CC BY 4.0). 方法论与坐标系定义见仓库内 METHODOLOGY.md。