Posted on

OpenAI releases Swarm, an experimental open source framework for multi-agent orchestration

OpenAI releases Swarm, an experimental open source framework for multi-agent orchestration

Swarm was recently released as an experimental tool and is intended to allow developers to explore how they can coordinate multiple agents together to complete tasks Routines And Handovers.

Multi-agent systems are an approach to building more complex AI systems in which a task is divided into subtasks. Each task is then assigned to a specialized agent who is able to select the most appropriate solution strategy. For example, you could create a buyer agent with two subagents, one managing refunds and the other managing sales, with a third agent, a triage agent, who determines which subagent should handle a new request.

Swarm explores patterns that are lightweight, scalable, and highly customizable by design. Swarm-like approaches are best suited to situations involving a large number of independent functions and statements that are difficult to encode in a single prompt.

As mentioned earlier, Swarm is based on the concepts of routines and handoffs. In this context, a routine is a set of steps and tools for executing it, while a handoff represents the action of an agent handing off a conversation to another agent. This means that the corresponding routine is loaded and provided with all the context collected during the previous conversation. For example, the following snippet shows how you can define a sales and refund agent:


def execute_refund(item_name):
    return "success"

refund_agent = Agent(
    name="Refund Agent",
    instructions="You are a refund agent. Help the user with refunds.",
    tools=[execute_refund],
)

def place_order(item_name):
    return "success"

sales_assistant = Agent(
    name="Sales Assistant",
    instructions="You are a sales assistant. Sell the user a product.",
    tools=[place_order],
)

To manage handoffs, you can define a triage agent like the following snippet, which includes two functions: transfer_to_sales_agent, transfer_to_refund_agent which return to their respective agent. You also need to add one transfer_to_triage_agent tool to ours refund_agent And sales_assistant Definitions.


triage_agent = Agent(
    name="Triage Agent",
    instructions=(
        "Gather information to direct the customer to the right department."
    ),
    tools=[transfer_to_sales_agent, transfer_to_refund_agent],
)
...
refund_agent = Agent(
...
    tools=[execute_refund, transfer_to_triage_agent],
)
...
sales_assistant = Agent(
...
    tools=[place_order, transfer_to_triage_agent],
)

The pattern described above, where you use a triage agent, is just one way to manage handoffs, and Swarm supports the use of different solutions.

Examples of alternative frameworks for creating multi-agent systems include AutoGen, CrewAI and AgentKit from Microsoft. Each of them takes a different stance on how agents are orchestrated and what aspects are essential to it.

Multi-agent systems aim to enable the creation of more complex systems by circumventing some limitations of LLMs, such as: B. Single-turn answers, lack of long-term memory and depth of reasoning.

However, it is important to understand that decomposing a complex agent into a multi-agent system is not necessarily an easy task. However, as Hacker News commentator ValentinA23 points out, the process is “very time-consuming because it requires experimentation to figure out how best to break a task into subtasks, including writing code to parse, clean, and retry each task output into the rest.” However, the agent graph, as it requires experimentation to figure out how best to break a task into subtasks, including writing code to parse and clean up each task output and put it back into the rest of the agent graph to include.”

Another Hacker News commentator, LASR, expresses concern that the different agents will diverge over time

The problem with agents is divergence. Very quickly a group of agents starts doing their own tasks and it is impossible to get anything that consistently achieves the desired state.

Finally, Hacker News user dimitri-vs mentions that the rapid development of current LLMs, e.g. B. GPT o1 and Sonnet 3.5, “makes it much easier to build in a single API call and change one or two prompts than to refactor them.” a complicated agent approach, especially when it is clear that the same prompts cannot be reliably transferred between different ones Models can be reused.”