AI Personal Learning
and practical guidance
豆包Marscode1

Swarm: an experimental pedagogical program for learning lightweight multi-intelligent body systems (OpenAI example)

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.

Swarm:学习轻量级多智能体系统的实验性教学项目(OpenAI示例)-1


 

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

  1. Ensure that Python 3.10 or later is installed.
  2. Use the following command to install Swarm:
   pip install git+https://github.com/openai/swarm.git

Guidelines for use

  1. 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.",
)
  1. 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"])
  1. Agent Handover: In the above example.agent_aWill hand over the task toagent_band returnsagent_bThe response.
  2. function call: Proxies can call predefined functions, such as the one in the example abovetransfer_to_agent_bfunction.
  3. streaming assessment: Swarm supports real-time evaluation and adjustment of agent behavior, ensuring system flexibility and efficiency.

Detailed Operation Procedure

  1. Defining Agents: Create different agents by defining their names, commands and functions.
  2. Setting up handover rules: Handover of tasks between agents is achieved by defining handover functions.
  3. Running Agent System: Use the Swarm client to run the agent system, process user input and return a response.
  4. 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.

May not be reproduced without permission:Chief AI Sharing Circle " Swarm: an experimental pedagogical program for learning lightweight multi-intelligent body systems (OpenAI example)
en_USEnglish