08. Hierarchical Multi-Agent Teams

In this tutorial Hierarchical agent team Let's look at how to configure.

Complex tasks that are difficult to respond with a single agent or a single level supervisor Hierarchical structure Split through, and implement the way each sub-level supervisor manages a worker agent specialized in that area.

This hierarchical approach helps to efficiently solve complex tasks that are difficult for a single worker to handle, if there are too many workers.

This example AutoGen thesis An example of implementing the idea through LangGraph, which organizes two sub-tasks of web research and documentation into different teams, and suggests how to manage the entire process through top and middle level supervisors.

Copy

 Start tracking LangSmith. 
[Project name] 
CH17-LangGraph-Use-Cases 

Copy

# Set up LangSmith tracking. https://smith.langchain.com
# !pip install -qU langchain-teddynote
from langchain_teddynote import logging

# Enter a project name.
logging.langsmith("CH17-LangGraph-Use-Cases")

Copy

 True 

Copy

# Configuration file for managing API keys as environment variables
from dotenv import load_dotenv

# Load API key information
load_dotenv()

Preferences

Reference


  1. Tool creation : Define agent tools for web research and documentation

  2. Agent team definition : Hierarchically define and organize research teams and documentation teams

  3. Add layer : Tiered the entire task through high-level graphs and mid-level supervisors

  4. Combination : Integrate all elements to build a final hierarchical agent team

What to cover in this tutorial


In this situation, the higher level supervisor is the lower level sub-supervisor Assign tasks to the people, each sub-supervisor You can construct a hierarchical structure where you are reassigned to a team of specialized workers.

  • Increased work complexity : A single supervisor may require expertise from various sub-areas that cannot be handled at once.

  • Increase in the number of workers : When managing a large number of workers, the administrative burden increases when a single supervisor gives orders directly to all workers.

In the previous Supervisor example, we looked at the process of one supervisor node assigning tasks to multiple worker nodes and gathering results. This method is efficient in simple cases. However, hierarchical structures may be necessary in the following situations:

Why a hierarchical agent team?

Copy

This tool allows agents to access the file system, which may not be safe. Therefore, attention is required to use.

Next, define the tools (file access tools) that the documentation team will use.

Documenting team tools

Copy

Copy

ResearchTeam can use search engines and URL scrapers to find information on the web. To improve the performance of ResearchTeam, you can freely add additional features below.

ResearchTeam tools

Let's look at the research team first.

Each team consists of one or more agents, and each agent is equipped with one or more tools. Below we define all the tools to be used by various teams.

Tool creation

Copy

Copy

Here are the code execution tools PythonREPLTool Defines.

Copy

Define utility functions for multi-agent creation

Here's how to create some utility functions to concisely perform tasks.

At this time, covered in the previous tutorial functools.partial Create an agent node using functions.

  1. worker agent create.

  2. sub-graph of supervisor create.

Copy

Below AgentFactory An example of using to generate an agent node.

In the example, we will look at how to create a search agent.

Copy

Here is a function that creates a Team Supervisor.

Copy

Agent team definition

Define the Research Team and the Doc Writing Team.

Research Team

The research team search agent Wow web scraping In charge research_agent Ra has two worker nodes. Let's create these and set up a team supervisor.

Copy

Next, define the function that selects the node to be routed to.

Copy

Research Team Graph Creation

Copy

Copy

Copy

Copy

Copy

Copy

Doc Writing Team

This time create a documenting team. At this time, each agent is given access to different file-writing tools.

Copy

Create Doc Writing Team graph

Copy

Visualize the graph.

Copy

Copy

Copy

Copy

Super-Graph generation

for this Super Graph We will define the previous two graphs, and add connection elements that define how these higher-level states are shared between different graphs. First, create a total supervisor node.

In this design Bottom-up planning policy Is applied. I have already created two graphs, but I have to decide how to route the work between them.

Copy

Copy

Visualize the graph.

Copy

Now define a Super-Graph that connects 2 teams.

Super-Graph definition

Copy

Super-Graph simply plays the role of routing Task.

The following defines the status and nodes of the Super-Graph.

Copy

Copy

Copy

Outputs the final result in a markdown format.

Copy

Copy

Last updated