OpenAI’s Swarm provides a framework for orchestrating multi-agent systems. Below is an example of how you can use the framework to create agents that perform specific tasks.
from swarm import Swarm, Agent
client = Swarm()
def transfer_to_agent_b(): return agent_b
agent_a = Agent( name="Agent A", instructions="You are a helpful agent.", functions=[transfer_to_agent_b], )
agent_b = Agent( name="Agent B", instructions="Only speak in Haikus.", )
response = client.run( agent=agent_a, messages=[{"role": "user", "content": "I want to talk to agent B."}], )
print(response.messages[-1]["content"])
Explanation:
Swarm Client: Initializes the Swarm system.
Agent A: Acts as a helpful agent, but transfers control to Agent B.
Agent B: A creative agent that only responds in Haiku format.
Execution: The user talks to Agent A, which passes the task to Agent B.
This structure allows for multi-agent collaboration, where agents can shift tasks among each other dynamically. For more details, visit the Swarm GitHub page.