OpenAI Agents SDK v1.0.0-alpha.4弃用Codex
OpenAI Agents SDK v1.0.0-alpha.4
v1 alpha版本引入破坏性API变更,直接弃用Codex Runner和RealtimeRunner等核心调用入口。正在使用OpenAI Agents SDK构建自动化流程的开发者必须立即迁移至agent.run()等新接口,否则代码将无法运行。
OpenAI Agents SDK v1.0.0-alpha.4
Custom instructions now replace the Codex base prompt when supplied to Agent. When you omit instructions, the default prompt stays in place. Set instructions_mode="codex" to append your instructions to the base prompt as in alpha.3.
当向 Agent 提供自定义指令时,它们将替换 Codex 的基础提示词。如果省略指令,默认提示词保持不变。设置 instructions_mode="codex" 可将你的指令追加到基础提示词中,行为与 alpha.3 版本一致。
Highlights
亮点
- Validate final answers against JSON Schema before returning them to callers.
- Apply tool policies and defer individual function definitions. Let Codex recover from invalid arguments in the same turn for decorated functions without approval or an input transform.
- Connect MCP servers, including stdio servers running in sandboxes. Call another agent as a tool.
- Use the A2A client to contact approved endpoints and continue tasks that need more input.
- Store session checkpoints in Redis, filter conversation snapshots before storage, and trace streams with OpenTelemetry.
- Test offline with scripted Responses API replies and explore new sandbox examples.
- 在将最终答案返回给调用者之前,针对 JSON Schema 进行验证。
- 应用工具策略并推迟单个函数定义。让 Codex 在同一轮次中恢复装饰函数的无效参数,无需批准或输入转换。
- 连接 MCP 服务器,包括在沙箱中运行的 stdio 服务器。将另一个 Agent 作为工具调用。
- 使用 A2A 客户端联系已批准的端点,并继续需要更多输入的任務。
- 在 Redis 中存储会话检查点,在存储前过滤对话快照,并使用 OpenTelemetry 追踪流。
- 使用脚本化的 Responses API 回复进行离线测试,并探索新的沙箱示例。
Upgrade
升级
- Replace deprecated Codex Runner calls with agent.run(). Omit the deprecated Agent.name.
- Replace RealtimeRunner with agent.start().
- Upgrade all workers sharing a SQLite session database together.
- 使用 agent.run() 替换已弃用的 Codex Runner 调用。省略已弃用的 Agent.name。
- 使用 agent.start() 替换 RealtimeRunner。
- 升级共享同一个 SQLite 会话数据库的所有工作进程。
For v0 applications, keep the Python loop by moving most agents imports to openai_agents.classic. Move Realtime imports to openai_agents.realtime. See the v1 import mapping.
对于 v0 应用程序,通过将大多数 agents 导入移至 openai_agents.classic 来保留 Python 循环。将 Realtime 导入移至 openai_agents.realtime。请参阅 v1 导入映射。
Install
安装
Install the compiled GitHub release wheel for your platform. The wheels support standard 64-bit CPython 3.10-3.14 and include the Codex runtime. No Rust toolchain is needed.
安装适用于你平台的编译版 GitHub 发布 wheel 包。这些 wheel 包支持标准的 64 位 CPython 3.10-3.14,并包含 Codex 运行时。无需 Rust 工具链。
Use a virtual environment. Keep v0 in a separate environment because both versions use the openai-agents package name.
使用虚拟环境。由于两个版本都使用 openai-agents 包名,请将 v0 保留在单独的环境中。
Choose your platform below. pip verifies the SHA-256 digest.
选择下方的平台。pip 会验证 SHA-256 摘要。
Linux x86-64 (glibc 2.28 or newer)
Linux x86-64 (glibc 2.28 或更高版本)
python -m pip install --only-binary=:all: "https://github.com/openai/openai-agents-python/releases/download/v1.0.0-alpha.4/openai_agents-1.0.0a4-cp310-abi3-manylinux_2_28_x86_64.whl#sha256=d2a45e49bae501d10a196b812ae3ba2b252be384e3e60891b9c51158fb7017e9"Linux ARM64 (glibc 2.28 or newer)
Linux ARM64 (glibc 2.28 或更高版本)
python -m pip install --only-binary=:all: "https://github.com/openai/openai-agents-python/releases/download/v1.0.0-alpha.4/openai_agents-1.0.0a4-cp310-abi3-manylinux_2_28_aarch64.whl#sha256=dd4589c1ebac43b76d4f85036725092fa153788fce28c5b993a26f46cf94014d"macOS 11 or newer on Apple Silicon
Apple Silicon 上的 macOS 11 或更高版本
python -m pip install --only-binary=:all: "https://github.com/openai/openai-agents-python/releases/download/v1.0.0-alpha.4/openai_agents-1.0.0a4-cp310-abi3-macosx_11_0_arm64.whl#sha256=f70e1696a01c83a8082e8e3fed676022005681e6d1987e3d18a9fe77baf6dd6e"Windows x64
python -m pip install --only-binary=:all: "https://github.com/openai/openai-agents-python/releases/download/v1.0.0-alpha.4/openai_agents-1.0.0a4-cp310-abi3-win_amd64.whl#sha256=1295f9d12af5fbb447b6e71757a71a38513c7e8e6591a9336c00f32388d270b0"Check the installation offline. This check is unbilled and requires no API key.
离线检查安装。此检查不产生费用且不需要 API 密钥。
python -I -m openai_agents.codexExpect Codex runtime version 0.172.0.
预期 Codex 运行时版本为 0.172.0。
Run a history tutor
运行历史导师
Set OPENAI_API_KEY to your OpenAI API key and OPENAI_MODEL to a Codex-compatible model available to your project.
将 OPENAI_API_KEY 设置为你的 OpenAI API 密钥,并将 OPENAI_MODEL 设置为项目可用的与 Codex 兼容的模型。
Save this as tutor.py.
将其保存为 tutor.py。
import asyncio
import os
from openai_agents import Agent
async def main():
agent = Agent(
model=os.environ["OPENAI_MODEL"],
instructions="Answer history questions clearly.",
)
prompt = "When did the Western Roman Empire fall?"
result = await agent.run(prompt)
print(result.output_text)
asyncio.run(main())Run the tutor to make a billable OpenAI Responses API request.
运行导师以发起一次计费的 OpenAI Responses API 请求。
python tutor.pyExpect an answer mentioning 476 CE.
预期答案会提及公元 476 年。
Release details
发布详情
Full changelog
完整更新日志
Wheel build
Wheel 构建
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力