LLM之Agent(十二)| OpenAI Agent-Swarm简单入门

项目地址: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 osos.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?

参考文献:https://cookbook.openai.com/examples/orchestrating_agents

相关推荐
染指11103 小时前
26.RAG进阶(Advanced RAG)-假设性问题索引
人工智能·windows·agent·rag·advanced rag
闵孚龙3 小时前
动态图机制:为什么 PyTorch 调试起来更舒服
人工智能·pytorch·python
甲维斯4 小时前
还要啥Codex!DeepSeek接入Zcode远程连接!
人工智能
百胜软件@百胜软件4 小时前
百胜软件亮相“AI消费新生活”主题日活动,AI智能运营平台入选市级案例征集
人工智能·生活·零售数字化·数智中台·珠宝行业
专注搞钱5 小时前
GPT-4o写设备Recipe:从3小时到10分钟
数据库·人工智能·gpt·半导体
闻道参看6 小时前
贝芯宠AI灵兽 ELFVET 大模型聚焦临床应用,强化宠物诊疗综合能力
人工智能·宠物
MartinYeung56 小时前
[论文学习]重新思考大型语言模型忘却目标:梯度视角与超越
人工智能·学习·语言模型
财经资讯数据_灵砚智能6 小时前
基于全球经济类多源新闻的NLP情感分析与数据可视化(夜间-次晨)2026年6月14日
大数据·人工智能·python·ai·信息可视化·自然语言处理·灵砚智能
m0_380167146 小时前
加密货币价格 API、市场数据 API 与 分析 API 有什么区别?
人工智能·ai·区块链
zyplayer-doc6 小时前
企业知识库安全与权限管理完全指南:从加密到审计的六层防护
人工智能·安全·pdf·编辑器·创业创新