Get startedGet started for free

Multi-agent frameworks

1. Multi-agent frameworks

Now that you're getting comfortable with LangGraph and have mastered the single-agent case, let's talk about multiple agents.

2. Example: website creator system

Imagine you want to create an agentic system to design a website. There's a number of tasks that might be performed here: creating a design specification, writing the codebase for the website backend, aligning on branding, and so on. There are some dependencies between these tasks, for example, the specifications will likely precede every other task, but some tasks could, in theory, be performed in parallel, such as branding and writing the codebase for the backend. If we continue to give a single agent more tools and a broader scope, we will likely see it struggle to choose which tools to use and when, and it won't be able to handle concurrent tasks. Instead, we could build multiple agents specialized to specific tasks, like a coding agent and design agent, that can collaborate to complete the task.

3. Multi-agent design patterns

There are many emerging design patterns for multi-agent system. In this course we'll focus on two of the most popular: swarm, or network multi-agents, and supervisor multi-agents.

4. Swarm multi-agents

The swarm multi-agent architecture gives multiple agents their own sets of tools and prompts to define their scope of operation.

5. Swarm multi-agents

Each agent can either progress the task through using its functional tools,

6. Swarm multi-agents

or choose to handoff to the other agent if it believes that it is better-suited for the task. For our example,

7. Swarm multi-agents

we create a research agent responsible for retrieving summaries and stock performance data, and an analyst agent responsible for generating plots. The two agents are essentially looping, calling tools and collecting their results until the task is completed. To start this workflow,

8. Swarm multi-agents

an initial agent must be chosen. Here, it makes sense to start with the research agent, as the analyst agent actually can't complete anything without the stock performance data.

9. Swarm multi-agents

Under-the-hood, each of these agent nodes is an LLM node and a tool node, connected with conditional edges that either route to the end node if the task has been completed, or route to the other agent if not. This architecture is fairly simplistic in structure, and extends naturally from the single-agent case; however, there are some drawbacks.

10. Swarm multi-agents

First, these agents can get stuck in infinite loops, as it might turn out that neither agent can complete the task, but they still continue to handoff in the hope that the other agent can complete the task. Second, the architecture requires choosing an agent to start the workflow with. For some cases, choosing this initial agent may be obvious, but for other cases, it could introduce challenges and redundancy. An alternative to this is to introduce a third agent: a supervisor!

11. Supervisor multi-agents

In this case, the user input first reaches the supervisor, which is responsible for enabling meaningful collaboration between the agents, and bringing together their respective outputs. The supervisor decides how the tasks should be delegated, and the agents hand off back to the supervisor, which can then determine if the task has been completed or if the worker agents need to continue their work.

12. Example: website creator system

In our website agent, this supervisor agent would act like a product manager, who acts as the go-between for the coding, design, and other agents in use. This supervisor may also decide that a task doesn't require a tool call and delegation to the worker agents below it. In this case, the supervisor will provide a standard LLM response back to the user.

13. Let's practice!

We've looked at two approaches to multi-agent collaboration: swarms and supervisors. Time to have a go at coding these in the exercises.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.