OpenAI 推出了新的 API 和工具,旨在简化 Agent 的开发


来源: 官网
仓库: repo

今天我们正式推出首批“积木式”组件, 助力各位开发者和企业轻松打造实用又靠谱的智能代理(agents)。 所谓智能代理,可以理解为是代表用户独立完成各种任务的智能系统。

过去一年,我们不断升级模型能力, 像是更强大的推理能力、多模态互动,还有最新的安全技术等等, 这些都为模型打下了坚实的基础, 让它们能够胜任构建智能代理所需的各种复杂任务。 不过,也有客户反映,想把这些能力真正落地,开发出能实际应用的智能代理, 还是挺有挑战的。 经常需要反复调整提示词,编写复杂的定制化流程,而且过程不够透明, 缺乏足够的技术支持。

为了解决这些难题,我们现在推出一套全新的API和工具,专门用来简化智能代理应用的开发流程:

  • 新的 Responses API 它结合了Chat Completions API的简洁性和Assistants API的工具使用能力,可以更轻松地构建智能代理。
  • 内置工具: 包括网页搜索文件搜索电脑使用等功能,相当于给智能代理配备了“外脑”和“助手”。
  • 新的 Agents SDK 用于编排单智能代理和多智能代理的工作流程,让智能代理之间的协作更高效。
  • 集成的可观测性工具 可以追踪和检查智能代理的工作流程执行情况,方便开发者调试和优化。

总而言之,这些新工具简化了智能代理的核心逻辑、流程编排和互动方式,让开发者更容易上手。接下来几个月,我们还会陆续发布更多工具和功能,进一步简化和加速大家在我们平台上开发智能代理应用 applications)。


两个API的关系( 并存在 openai 库):

Developers who don’t require built-in tools can confidently continue using Chat Completions. We’ll keep releasing new models to Chat Completions whenever their capabilities don’t depend on built-in tools or multiple model calls. However, the Responses API is a superset of Chat Completions with the same great performance, so for new integrations, we recommend starting with the Responses API.


python-agents SDK 库

安装

pip install openai-agents # or `uv add openai-agents`, etc

The Agents SDK has a very small set of primitives:

  • Agents, which are LLMs equipped with instructions and tools
  • Handoffs, which allow agents to delegate to other agents for specific tasks
  • Guardrails, which enable the inputs to agents to be validated

handoffs example

可以看到,agent A 可以成为 另一个 agent B 的 tool(handoffs),如递归一般

from agents import Agent, Runner
import asyncio

spanish_agent = Agent(
    name="Spanish agent",
    instructions="You only speak Spanish.",
)

english_agent = Agent(
    name="English agent",
    instructions="You only speak English",
)

triage_agent = Agent(
    name="Triage agent",
    instructions="Handoff to the appropriate agent based on the language of the request.",
    handoffs=[spanish_agent, english_agent],
)


async def main():
    result = await Runner.run(triage_agent, input="Hola, ¿cómo estás?")
    print(result.final_output)
    # ¡Hola! Estoy bien, gracias por preguntar. ¿Y tú, cómo estás?


if __name__ == "__main__":
    asyncio.run(main())

Functions example

这个直接上函数 name,不需要设置 schema,这个做法 最早在gemini 的代码仓库见到,但这里似乎是更简洁的实现(连函数的参数说明都不必…)

import asyncio

from agents import Agent, Runner, function_tool


@function_tool
def get_weather(city: str) -> str:
    return f"The weather in {city} is sunny."


agent = Agent(
    name="Hello world",
    instructions="You are a helpful agent.",
    tools=[get_weather],
)


async def main():
    result = await Runner.run(agent, input="What's the weather in Tokyo?")
    print(result.final_output)
    # The weather in Tokyo is sunny.


if __name__ == "__main__":
    asyncio.run(main())

补充 另一个资料
2025年纽约AI工程师峰会,主题是 building and scaling use cases with OpenAI

OpenAI 如何 operate

  • Research :build and deploy these foundational model (推进研究,建造模型)
  • Apply: take model ,then build it into product (建造产品和app层,并持续迭代)
  • Deploy: in the go-to-market sense, deploy this (将产品交付给 end 用户)

identify pathway to implement AI into your organization

  • Buliding an AI-enabled workforce
  • AI automated operations
  • Infusing AI into products

建造 Agent 的思路

如何定义 Agent:

an agent is an AI application consisting of a model equipped with instructions that guide its behavior, access to tools that extend its capabilities , encapsulated in a runtime with a dynamic lifecycle

四个 insight:

1 Abstraction is a tool , not a crutch(拐杖)
必须说 starting with a framework is pretty enticing , 快速搭建一个概念验证系统 in no time 是非常吸引力的,但问题在于,若是刚开始就用框架,你往往不知道 how your system behaves or what primitives it uses. you’ve deferred design decisions before you’ve understood your constraints. 如果不了解约束,也就无法优化你的解决方案。
所以 我们认为,更好的方法是 first build with primitives

#这个观点,和 Anthropic 的观点是一致的,参见 Building effective agents

2 start simple
刚开始就 直接设计复杂的系统,multi-agent system, agents calling agents, coordinating tasks, dynamically reasoning over long trajectories. 这听起来很厉害,但过早去做 就会创造很多 未知。

所以我们建议,starting with a single agent , that’s purpose-built for a single task
put that into production ,with a limited set of users and observe how it performs.
(#类似 MVP,还有很多 startup 的运作思路)

3 use a network of agents for complex tasks
虽然从简单开始,但我们也知道 complexity is where true value is realized, 组装一个 agent 的网络,不同擅长的 agent 放在不同的 节点

4 keep prompts simple, use guardrails to handle edge case
guardrails 不一定要成为 main prompts 的一部分,但要并行运行


再补充一个小细节
翻看 github库之 toml 文 发现 ,openai 疑似不再使用 httpx, 而改用回 requests
(要设置proxy 操作不一样了)

依赖信息对比 openai-agents vs. openai

新的 openai-agents 库:

dependencies = [
“openai>=1.66.2”,
“pydantic>=2.10, <3”,
“griffe>=1.5.6, <2”,
“typing-extensions>=4.12.2, <5”,
requests>=2.0, <3”,
“types-requests>=2.0, <3”,
]

openai 库的依赖:

dependencies = [
httpx>=0.23.0, <1”,
“pydantic>=1.9.0, <3”,
“typing-extensions>=4.11, <5”,
“anyio>=3.5.0, <5”,
“distro>=1.7.0, <2”,
“sniffio”,
“tqdm > 4”,
“jiter>=0.4.0, <1”,
]


16 个赞

等大佬测试

1 个赞

感谢总结~

还得是closeai,虽然整烂活,至少还是有东西的

3 个赞

httpx VS requests 这点,明显就是两拨人搞的

1 个赞

等大佬们测试