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

相关推荐
风象南2 小时前
我把大脑开源给了AI
人工智能·后端
Johny_Zhao4 小时前
OpenClaw安装部署教程
linux·人工智能·ai·云计算·系统运维·openclaw
飞哥数智坊4 小时前
我帮你读《一人公司(OPC)发展研究》
人工智能
冬奇Lab8 小时前
OpenClaw 源码精读(3):Agent 执行引擎——AI 如何「思考」并与真实世界交互?
人工智能·aigc
量子位9 小时前
全球首份大模型业绩报!MiniMax预判2026三大超级PMF,AI平台公司启程了
aigc·ai编程
量子位9 小时前
这届MWC真成了中国AI主场,小米直接把AI从对话框里拽出来接管物理世界了
llm·aigc
闯荡9 小时前
智能故障分析器工作总结
aigc
没事勤琢磨9 小时前
如何让 OpenClaw 控制使用浏览器:让 AI 像真人一样操控你的浏览器
人工智能
用户51914958484510 小时前
CrushFTP 认证绕过漏洞利用工具 (CVE-2024-4040)
人工智能·aigc
牛马摆渡人52810 小时前
OpenClaw实战--Day1: 本地化
人工智能