当前位置: 首页 > news >正文

可做产品预售的网站九江有限公司

可做产品预售的网站,九江有限公司,可以做分销的网站,徐州网站建设网络推广rag系列文章目录 文章目录 rag系列文章目录前言一、openai agent简介二、openai agent实践总结 前言 2025开年以来,随着deepseek的爆火,大模型以及应用正在快速的迭代。随着一款大模型agent,即manus,横空出世,openai也…

rag系列文章目录

文章目录

  • rag系列文章目录
  • 前言
  • 一、openai agent简介
  • 二、openai agent实践
  • 总结


前言

2025开年以来,随着deepseek的爆火,大模型以及应用正在快速的迭代。随着一款大模型agent,即manus,横空出世,openai也紧接着发布了openai agent,下面主要简要介绍下这个agent。

一、openai agent简介

OpenAI Agent SDK 是一个由 OpenAI 发布的框架,旨在帮助开发者构建多代理 AI 应用。它提供代理(Agents)、交接(Handoffs)和防护栏(Guardrails)等基本组件,支持创建复杂的多代理工作流,如客户支持系统或任务路由系统。它轻量级,易于学习,适合快速原型开发和生产环境。

与其他 AI 代理框架(如 LangChain 和 LlamaIndex)相比,OpenAI Agent SDK 有以下不同:

• 多代理协作:特别强调代理之间的交接,适合需要分工的场景,如 triage 代理路由任务。LangChain 和 LlamaIndex 更注重单个代理的功能扩展。
• 简单性:提供少量抽象,学习曲线低,相比 LangChain 的丰富功能更易上手。
• 内置追踪:自带追踪功能,方便调试,LangChain 和 LlamaIndex 可能需额外配置。

二、openai agent实践

1.工具调用
Agent基本的功能就是工具调用,以下是openai agent的工具调用,和langchain的工具调用有类似之处。

import agents
from agents import Agent, Runner, function_tool, handoff, OpenAIChatCompletionsModel@function_tool
def web_search(query: str) -> str:"""Simulate a web search for the given query."""# In a real application, this would call a web search APIwith agents.custom_span("WebSearch"):  # Add a custom span for tracing this actionreturn f"Web search results for '{query}': [Sample result 1, Sample result 2]"@function_tool
def get_weather(city: str) -> str:"""Fetch the weather for a given city."""# Placeholder for a real API callprint("---------------------------")return f"The weather in {city} is sunny."

2.大模型
大模型是agent的大脑,这里定义大模型的client,在创建agent时可以引用这个client。

from openai import AsyncOpenAIopenai_client = AsyncOpenAI(api_key="sk-S",base_url="https://ss/v1"
)

3.构建agent
这里构建了一个天气agent,负责处理天气相关的工作。

weather_agent = Agent(name="Weather Assistant",instructions="Help users with weather queries.",model=OpenAIChatCompletionsModel(openai_client=openai_client,model="gpt-4o-2024-05-13"), tools=[get_weather]
)

4.handoff
openai agent的一大亮点就是多个agent之间的交接,如下所示,有一个专门负责处理天气问题的agent,主agent需要做天气相关的工作时,可以把它交接给天气agent处理,这个agent进行tool调用查询天气情况。

# Create the main support agent with tools and handoff
main_agent = Agent(name="SupportAssistant",instructions=("You are a customer support assistant. Answer user queries and use the web search tool ""when needed. For get weather , hand off to Weather Assistant."),tools=[web_search],  # Equip the agent with the web search toolhandoffs=[handoff(weather_agent)],  # Configure handoff to the specialized agentmodel=OpenAIChatCompletionsModel(openai_client=openai_client,model="gpt-4o-2024-05-13")
)

5.agent执行
以下是agent开始启动执行的代码,agent的整个执行过程,可以开启日志,详细观察里面的调用过程。

# Enable verbose logging to see detailed output in the console
agents.enable_verbose_stdout_logging()if __name__ == '__main__':# Run the agent synchronously with a sample input and handle exceptionstry:with agents.trace("CustomerSupportQuery"):  # Start a trace to monitor the entire operationresult = Runner.run_sync(main_agent, "What's the weather in Paris?")print("Final Output:", result.final_output)  # Print the agent's responseexcept agents.InputGuardrailTripwireTriggered as e:print("Input was rejected by guardrail:", e)except agents.OutputGuardrailTripwireTriggered as e:print("Output was rejected by guardrail:", e)except agents.MaxTurnsExceeded:print("Agent exceeded maximum turns.")except agents.ModelBehaviorError as e:print("Model produced an invalid response:", e)except agents.AgentsException as e:print("An error occurred:", e)

总结

OpenAI Agent是一个轻量级框架,适合构建多代理 AI 应用,强调简单性和协作,没有langchain复杂。虽然很多功能还不是特别成熟完善,但是它在快速发展,相信更多的人后面会使用它。

http://www.dtcms.com/a/532604.html

相关文章:

  • 设计模式-状态模式(State)
  • 强化学习推荐系统:不同的探索策略——贪心探索策略(4.1)
  • Git学习-1
  • 如何运营一个行业网站dede建设网站
  • 找公司网站建设3网站有哪些后台
  • 15.如何利用ArcGIS提取出线要素数据所经过的格网
  • 数据结构<C++>——数组
  • vidhub v1.3.13 |聚合主流网盘,自动刮削整理影视资源,有网盘会员的可入,或者使用不限速网盘
  • 专业网站制作地址杭州网站怎么制作
  • 免费素材网站排行榜征求网站建设
  • 汉口网站制作公司营销网站模板下载
  • 将有序数组转换为二叉搜索树解题思路
  • c语言实现栈【由浅入深-数据结构】
  • 教做家常菜的视频网站wordpress 搭建个人博客
  • 【Go】C++ 转 Go 第(五)天:Goroutine 与 Channel | Go 并发编程基础
  • 算法:283. 移动零
  • 设计微信公众号的网站吗举例说明seo
  • 欧米伽男士手表官方网站wordpress下载类型主题
  • Chrome离线版下载版,Chrome离线版安装文件,Chrome离线包
  • 上饶网站建设多少钱分销网站有哪些
  • 阿里云 Qwen 模型的 OpenAI SDK 调用
  • 什么是提示词(Prompt),提示词类型、结构解析
  • MES系列-制造流程数字化的实现
  • 我想在网站上卖食品怎么做百度知道网址
  • 对于使用队列实现栈以及用栈实现队列的题目的解析
  • Spring Boot3零基础教程,事件驱动开发,设计登录成功后增加积分记录信息功能,笔记61
  • 网站开发进度表网络电话免费版
  • 两种Redis序列化对比
  • 精确优化长尾关键词以提升SEO效果的战略分析
  • 分析对手网站wordpress制作功能型网站