2025年3月12日,OpenAI夜间突袭!重磅推出Agent SDK

Open AI Agent  https://openai.com/index/new-tools-for-building-agents/

一 Responses API

一个专门为 Agent 进行优化的 API,支持以往 API (Chat Completions API)的所有功能,重点:Responses API 支持新的内置工具,并支持可预测性的流式事件,极大的简化了项目的复杂度。

2025年3月12日,OpenAI夜间突袭!重磅推出Agent SDK_第1张图片

2025年3月12日,OpenAI夜间突袭!重磅推出Agent SDK_第2张图片

能力对比:

2025年3月12日,OpenAI夜间突袭!重磅推出Agent SDK_第3张图片

from openai import OpenAI
client = OpenAI()

response = client.responses.create(
    model: "适用模型",  // computer-use-preview或gpt-4o等
    tools: [{          
        type: "工具名称",  // web_search_preview, file_search, computer_use_preview         
         // 工具特定参数...     
    }],
    truncation: "auto",  // computer_use必需
    input="What was a positive news story from today?"
    // 其他参数...
)

print(response.output_text)

1.1,Web Search / 网页搜索

2025年3月12日,OpenAI夜间突袭!重磅推出Agent SDK_第4张图片

1.2,File Search / 文件搜索

不是新功能,之前就推出过,算版本更新。

使用流程大抵是:

  • 上传文件到 OpenAI 的向量库
  • 它会处理一阵子,完了就可以使用了
  • 使用 file_search 来获取回答

2025年3月12日,OpenAI夜间突袭!重磅推出Agent SDK_第5张图片

1.3,Computer Use Agent (CUA)

目前支持 9 种行为,这些行为,将会被 CUA 进行自动的组合和执行,达到操作电脑的效果

2025年3月12日,OpenAI夜间突袭!重磅推出Agent SDK_第6张图片

二  Agents SDK

Git 地址:https://github.com/openai/openai-agents-python

这是一个支持 multi-agent 的框架,任何符合 OpenAI Chat Completions API 的模型都可以来用。

因此,DeepSeek 也能用 OpenAI 的这个框架。

2.1 基础示例

pip install openai-agents
from agents import Agent, Runner

agent = Agent(name="Assistant", instructions="You are a helpful assistant")

result = Runner.run_sync(agent, "Write a haiku about recursion in programming.")
print(result.final_output)
# 输出: Code within the code,
#      Functions calling themselves,
#      Infinite loop's dance.

2.2 代理交接

pip install openai-agents
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())

2.3 函数工具

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())

你可能感兴趣的:(java,前端,服务器)