General Introduction
Swarm is an experimental educational framework developed by OpenAI to explore lightweight, controlled, and easily testable interfaces for multi-agent systems. The framework is primarily used to demonstrate handoffs and routine patterns between agents, and to help developers understand and implement the coordination and execution of multi-agent systems.Swarm is not a stand-alone library, but is primarily used for educational purposes, and is suitable for developers interested in learning and experimenting with multi-agent systems.Swarm uses the Chat Completions API, and supports Python 3.10 and above.
Function List
- Agent Creation: Define and create agents with specific instructions and functions.
- Agent Handover: Enables task handover between agents and enhances system flexibility.
- function call: Agents can invoke predefined functions to perform specific tasks.
- streaming assessment: Supports real-time evaluation and adjustment of agent behavior.
- stateless call: No state is saved between each call, ensuring a lightweight and efficient system.
Using Help
Installation process
- Ensure that Python 3.10 or later is installed.
- Use the following command to install Swarm:
pip install git+https://github.com/openai/swarm.git
Guidelines for use
- Creating a Proxy::
from swarm import Swarm, Agent
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.",
)
- Running Agents::
client = Swarm()
response = client.run(
agent=agent_a,
messages=[{"role": "user", "content": "I want to talk to agent B."}],
)
print(response.messages[-1]["content"])
- Agent Handover: In the above example.
agent_a
Will hand over the task toagent_b
and returnsagent_b
The response. - function call: Proxies can call predefined functions, such as the one in the example above
transfer_to_agent_b
function. - streaming assessment: Swarm supports real-time evaluation and adjustment of agent behavior, ensuring system flexibility and efficiency.
Detailed Operation Procedure
- Defining Agents: Create different agents by defining their names, commands and functions.
- Setting up handover rules: Handover of tasks between agents is achieved by defining handover functions.
- Running Agent System: Use the Swarm client to run the agent system, process user input and return a response.
- Real-time assessment and adjustment: Evaluate and adjust system configurations in real time based on agent behavior and response.
With these steps, developers can easily get started with the Swarm framework and explore the implementation and application of multi-agent systems.