LLM之Agent(十二)| OpenAI Agent-Swarm简单入门
作者:weixin01 · 2024-12-06 · 阅读时间:2分钟
参考文献:https://cookbook.openai.com/examples/orchestrating_agents
项目地址:https://github.com/openai/swarm
本文简单介绍一下如何使用Swarm:
一、首先需要安装环境(python3.10+)
# 创建python虚拟环境(可选)
conda create -n python=3.10
pip install git+ssh://git@github.com/openai/swarm.git
二、设置OpenAI API
import os
os.environ['OPENAI_API_KEY'] =''
三、下面是一个handoff的例子
from swarm import Swarm, Agent
client = Swarm()
english_agent = Agent(
name="English Agent",
instructions="You only speak English.",
)
spanish_agent = Agent(
name="Spanish Agent",
instructions="You only speak Spanish.",
)
def transfer_to_spanish_agent():
"""Transfer spanish speaking users immediately."""
return spanish_agent
english_agent.functions.append(transfer_to_spanish_agent)
messages = [{"role": "user", "content": "Hola. ¿Como estás?"}]
response = client.run(agent=english_agent, messages=messages)
print(response.messages[-1]["content"])
输出:
¡Hola! Estoy bien, gracias. ¿Y tú, cómo estás?
文章转自微信公众号@ArronAI
热门推荐
一个账号试用1000+ API
助力AI无缝链接物理世界 · 无需多次注册
3000+提示词助力AI大模型
和专业工程师共享工作效率翻倍的秘密
最新文章
- 用 Poe-API-wrapper 连接 DALLE、ChatGPT,批量完成AI绘图或文字创作
- RESTful Web API 设计中要避免的 6 个常见错误
- LangGraph 工具详解:构建 AI 多步骤流程的关键利器
- GitHubAPI调用频率限制的增加方法
- 如何使用Route Optimization API优化配送路线
- 什么是聚类分析?
- 安全好用的OpenApi
- 医疗数据管理与fhir api的未来发展趋势
- 为什么要使用Google My Business Reviews API
- 2025年7月第2周GitHub热门API推荐:rustfs/rustfs、pocketbase/pocketbase、smallcloudai/refact
- API设计的首要原则
- 左手用R右手Python系列——百度地图API调用与地址解析/逆解析
热门推荐
一个账号试用1000+ API
助力AI无缝链接物理世界 · 无需多次注册