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

相关推荐
程序员X小鹿3 小时前
这5个AI文本可视化工具太强了!一键把文本转信息图、流程图等多种可视化形式!PPT秒变高级!(建议收藏)
aigc
学历真的很重要4 小时前
VsCode+Roo Code+Gemini 2.5 Pro+Gemini Balance AI辅助编程环境搭建(理论上通过多个Api Key负载均衡达到无限免费Gemini 2.5 Pro)
前端·人工智能·vscode·后端·语言模型·负载均衡·ai编程
普通网友4 小时前
微服务注册中心与负载均衡实战精要,微软 2025 年 8 月更新:对固态硬盘与电脑功能有哪些潜在的影响。
人工智能·ai智能体·技术问答
苍何4 小时前
一人手搓!AI 漫剧从0到1详细教程
人工智能
苍何4 小时前
Gemini 3 刚刷屏,蚂蚁灵光又整活:一句话生成「闪游戏」
人工智能
墨风如雪4 小时前
智谱GLM-4.6V开源:不仅仅是“看懂”,它终于长出了“双手”
aigc
苍何4 小时前
越来越对 AI 做的 PPT 敬佩了!(附7大用法)
人工智能
苍何4 小时前
超全Nano Banana Pro 提示词案例库来啦,小白也能轻松上手
人工智能
阿杰学AI5 小时前
AI核心知识39——大语言模型之World Model(简洁且通俗易懂版)
人工智能·ai·语言模型·aigc·世界模型·world model·sara
智慧地球(AI·Earth)5 小时前
Vibe Coding:你被取代了吗?
人工智能