OpenAI Introduces Swarm, a Framework for Building Multi-Agent Systems

OpenAI Introduces Swarm, a Framework for Building Multi-Agent Systems

#openai #ai #airesearch #airesearchpapers #researchskills

For more information on AI Research Papers you can visit my Github Profile -

https://github.com/aditikhare007/AI_Research_Junction_Aditi_Khare

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 -

https://www.dhirubhai.net/newsletters/7152631955203739649/

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

  • basic: Simple examples of fundamentals like setup, function calling, handoffs, and context variables
  • triage_agent: Simple example of setting up a basic triage step to hand off to the right agent
  • weather_agent: Simple example of function calling
  • airline: A multi-agent setup for handling different customer service requests in an airline context.
  • support_bot: A customer service bot which includes a user interface agent and a help center agent with several tools
  • personal_shopper: A personal shopping agent that can help with making sales and refunding orders.

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:

  1. Get a completion from the current Agent
  2. Execute tool calls and append results
  3. Switch Agent if necessary
  4. Update context variables, if necessary
  5. If no new function calls, return

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

  • Swarm Agents can call python functions directly.
  • Function should usually return a str (values will be attempted to be cast as a str).
  • If a function returns an Agent, execution will be transfered to that Agent.
  • If a function defines a context_variables parameter, it will be populated by the context_variables passed into client.run().

Function Schemas

Swarm automatically converts functions into a JSON Schema that is passed into Chat Completions tools.

  • Docstrings are turned into the function description.
  • Parameters without default values are set to required.
  • Type hints are mapped to the parameter's type (and default to string).
  • Per-parameter descriptions are not explicitly supported, but should work similarly if just added in the docstring. (In the future docstring argument parsing may be added.)

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:

  • {"delim":"start"} and {"delim":"start"}, to signal each time an Agent handles a single message (response or function call). This helps identify switches between Agents.
  • {"response": Response} will return a Response object at the end of a stream with the aggregated (complete) response, for convenience.

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 -

https://github.com/openai/swarm



要查看或添加评论,请登录

社区洞察

其他会员也浏览了