07. Multi-Agent Supervisor

In this tutorial LangGraph Let's take a look at how to leverage to build a multi-agent system, efficiently coordinate inter-agent operations, and manage them through Supervisor. It covers multiple agents at the same time, manages each agent to perform its own role, and covers the process of properly handling it upon completion of work.


summary

Previous tutorials showed how to automatically route messages based on the output of the initial Researcher agent. However, if the agents are growing in multiple, and if they need to be adjusted, there is a limit to simple branch logic alone. here Supervisor using LLM Introducing how to manage agents through and coordinate the entire team based on the results of each agent node.

Focus : -Supervisor brings together various professional agents and serves as a team (team). -Supervisor agents observe the progress of the team and perform logic such as calling the appropriate agent for each step or ending the task.


What to cover in this tutorial

  • Setup : How to install the required package and set the API key

  • Tool Creation : Define tools for agents to use, such as web browsing and plot creation

  • Helper Utilities : Define utility functions required to generate agent nodes

  • Agent supervisor creation (Creating the Supervisor) : Selection of worker nodes and creation of Supervisor with processing logic upon completion of work

  • Graph Configuration (Constructing the Graph) : Define the state and worker nodes to configure the entire graph

  • Team Call (Invoking the Team) : Call graph to see how multiple agent systems actually work

LangGraph's pre-built in this process create_react_agent Utilize functions to simplify each agent node.

This way of using "advanced agents" is to demonstrate specific design patterns in LangGraph, and you can combine them with other basic patterns as needed to achieve optimal results.


Reference

Preferences

Copy

Copy

Copy

Copy

Set the model name to use for this tutorial.

Copy

Copy

Status definition

Defines the state to utilize in the multi-agent system.

Copy

Agent creation

Create tool

In this example, we use search engines to create agents that perform web investigations and agents that generate plots.

Define the tools to use below.

  • Research : TavilySearch Perform a web survey using tools.

  • Coder : PythonREPLTool Run code using tools.

Copy

Implement Utility to create Agent

When building a multi-agent system using LangGraph, helper function plays an important role in creating and managing agent nodes. These functions increase the reusability of the code and simplify the interaction between agents.

  • Generate agent nodes : Define functions to generate nodes for each agent's role

  • Workflow management : Provide utilities to adjust and optimize workflow between agents

  • Error processing : Includes mechanisms to efficiently handle errors that may occur during agent execution next agent_node LA is an example that defines a function.

This function creates an agent node using a given state and agent. Later this function functools.partial I will call it using.

Copy

Reference

functools.partial Role of

functools.partial Is used to create new functions by pre-fixing some of the existing functions or keyword factors. In other words, it helps to simplify the frequently used function calling pattern.

role

  1. Generate new functions with predefined values : Returns a new function by pre-specifying some of the existing functions.

  2. Code brevity : Simplifies frequently used function call patterns to reduce code redundancy.

  3. Improved readability : Customize the behavior of the function to suit a specific task, making it more intuitively available.

Yeshikid

Copy

  1. agent_node Ra assumes that there is an existing function.

  2. This function can receive multiple factors and keyword factors.

  3. functools.partial Silver to this function agent=research_agent Wow names="Researcher" Fixed value.

  4. In other words, now research_node has agent_node When calling agent Wow names You don't have to specify a value separately.

  5. For example: python agent_node(state, agent=research_agent, names="Researcher") instead, python research_node(state) You can use it like. Below functools.partial Using research_node This is an example that produces.

Copy

Run the code to confirm the result.

Copy

Copy

Agent Supervisor creation

Generate a supervisor agent that oversees the agent.

Copy

Copy

Graph configuration

Copy

Visualize the graph.

Copy

Copy

Now you are ready to build the graph. Below, using the function you just defined state Wow worker Define nodes.

Team call

The generated graph can now confirm performance.

Copy

Copy

Copy

Last updated