OpenAI Introduces Swarm, a Framework for Building Multi-Agent Systems
Aditi Khare
AWS & AI Research Specialist-Principal Machine Learning Scientist & AI Architect | IIM-A | Author | AI Research [Portfolio] Build Production-Grade AI Products from Scratch | Vision Transformers??Open-Source Contributor
#openai #ai #airesearch #airesearchpapers #researchskills
For more information on AI Research Papers you can visit my Github Profile -
For Receving latest updates on Latest Advancements in AI Research Papers Summaries @Generative AI @Quantum AI @GPUs Optimzation @Deep Learning @Vision you can subscribe to my AI Research Papers Summaries Newsletter using below link -
Thank you & Happy Reading !!
Swarm vs Assistant API - Why Swarm
Swarm is lightweight, scalable, and highly customizable by design. It is best suited for situations dealing with a large number of independent capabilities and instructions that are difficult to encode into a single prompt.
The Assistants API is a great option for developers looking for fully-hosted threads and built in memory management and retrieval. where as Swarm is optimal for developers who want full transparency and fine-grained control over context, steps, and tool calls. Swarm runs (almost) entirely on the client and, much like the Chat Completions API, does not store state between calls.
Examples
Running Swarm -
Start by instantiating a Swarm client (which internally just instantiates an OpenAI client).
from swarm import Swarm
client = Swarm()
client.run()
Swarm's run() function is analogous to the chat.completions.create() function in the Chat Completions API – it takes messages and returns messages and saves no state between calls. Importantly, however, it also handles Agent function execution, hand-offs, context variable references, and can take multiple turns before returning to the user.
At its core, Swarm's client.run() implements the following loop:
Agents
An Agent simply encapsulates a set of instructions with a set of functions (plus some additional settings below), and has the capability to hand off execution to another Agent.
While it's tempting to personify an Agent as "someone who does X", it can also be used to represent a very specific workflow or step defined by a set of instructions and functions (e.g. a set of steps, a complex retrieval, single step of data transformation, etc). This allows Agents to be composed into a network of "agents", "workflows", and "tasks", all represented by the same primitive.
Functions
领英推荐
Function Schemas
Swarm automatically converts functions into a JSON Schema that is passed into Chat Completions tools.
def greet(name, age: int, location: str = "New York"):
"""Greets the user. Make sure to get their name and age before calling.
Args:
name: Name of the user.
age: Age of the user.
location: Best place on earth.
"""
print(f"Hello {name}, glad you are {age} in {location}!")
{
"type": "function",
"function": {
"name": "greet",
"description": "Greets the user. Make sure to get their name and age before calling.\n\nArgs:\n name: Name of the user.\n age: Age of the user.\n location: Best place on earth.",
"parameters": {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"},
"location": {"type": "string"}
},
"required": ["name", "age"]
}
}
}
Streaming
stream = client.run(agent, messages, stream=True)
for chunk in stream:
print(chunk)
Uses the same events as Chat Completions API streaming . See process_and_print_streaming_response in /swarm/repl/repl.py as an example.
Two new event types have been added:
Evaluations
Evaluations are crucial to any project, and we encourage developers to bring their own eval suites to test the performance of their swarms. For reference, we have some examples for how to eval swarm in the airline, weather_agent and triage_agent quickstart examples. See the READMEs for more details.
Utils
Use the run_demo_loop to test out your swarm! This will run a REPL on your command line. Supports streaming.
from swarm.repl import run_demo_loop
...
run_demo_loop(agent, stream=True)
Summary -
Swarm is a Framework for building, orchestrating and deploying multi-agent systems. Managed by OpenAI Solutions team. Experimental framework.
References -
Reference Reading Link -