所有文章 > AI驱动 > LLM之Agent(十二)| OpenAI Agent-Swarm简单入门

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

参考文献: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

#你可能也喜欢这些API文章!