AI Personal Learning
and practical guidance

LangGraph Supervisor: a tool for managing multi-intelligence collaboration using supervising intelligences

General Introduction

LangGraph Supervisor is a Python library based on the LangGraph framework designed for creating and managing multi-intelligent body systems. The library coordinates the work of multiple specialized agents through a central supervisory agent, ensuring efficient management of communication flows and task assignments.LangGraph Supervisor supports both router and coordinator modes, provides instrumented agent handoff mechanisms, flexible message history management, and is suitable for application scenarios in streaming processing, short- and long-term memory, and human-in-the-loop.

LangGraph Supervisor: A Python Library for Creating and Managing Multi-Intelligent Body Systems-1


 

Function List

  • Create supervisory agents to coordinate multiple specialized agents
  • Supports router and coordinator modes
  • Instrumentalized proxy handover mechanisms
  • Flexible message history management
  • Supports streaming processing, short-term and long-term memory
  • Human-in-the-loop application scenario support

 

Using Help

Installation process

  1. Ensure that the Python environment is installed.
  2. Install the LangGraph Supervisor library using pip:
   pip install langgraph-supervisor
  1. Install the LangChain and OpenAI libraries:
   pip install langchain-openai
  1. Set the OpenAI API key:
   export OPENAI_API_KEY=

usage example

The following is a simple example showing how to manage two specialized agents using the LangGraph Supervisor:

  1. Import the necessary libraries and modules:
   from langchain_openai import ChatOpenAI
from langgraph_supervisor import create_supervisor
from langgraph.prebuilt import create_react_agent
  1. Create specialized agents:
   def add(a: float, b: float) -> float.
"""Add two numbers.""""
return a + b
def multiply(a: float, b: float) -> float.
"""Multiply two numbers.""""
return a * b
def web_search(query: str) -> str.
"""Search the web for information.""""
return "Here are the headcounts for each of the FAANG companies in 2024:..."
model = ChatOpenAI(model="gpt-4o")
math_agent = create_react_agent(model=model, tools=[add, multiply], name="math_expert", prompt="You are a math expert. Always use one tool at a Always use one tool at a time.")
research_agent = create_react_agent(model=model, tools=[web_search], name="research_expert", prompt="You are a world class researcher with Do not do any math.")
  1. Create the supervisor agent and compile and run it:
   workflow = create_supervisor([research_agent, math_agent], model=model, prompt="You are a team supervisor managing a research expert and a math expert.")
app = workflow.compile()
result = app.invoke({
"messages": [
{ "role": "user", "content": "what's the combined headcount of the FAANG companies in 2024?"}
]
})

Detailed function operation flow

  1. Creating Supervisory Agents: Bycreate_supervisorfunction creates a supervisory agent that is responsible for coordinating the work of multiple specialized agents.
  2. Defining Specialized Agents: Usecreate_react_agentFunctions define specialized agents for different functions, such as mathematical computation agents and web search agents.
  3. Compile and run workflows: Byworkflow.compile()Compile the workflow and use theapp.invoke()Runs a workflow that processes user input and returns results.

LangGraph Supervisor provides a flexible multi-intelligence system management solution for automating and coordinating a variety of complex tasks.

May not be reproduced without permission:Chief AI Sharing Circle " LangGraph Supervisor: a tool for managing multi-intelligence collaboration using supervising intelligences

Chief AI Sharing Circle

Chief AI Sharing Circle specializes in AI learning, providing comprehensive AI learning content, AI tools and hands-on guidance. Our goal is to help users master AI technology and explore the unlimited potential of AI together through high-quality content and practical experience sharing. Whether you are an AI beginner or a senior expert, this is the ideal place for you to gain knowledge, improve your skills and realize innovation.

Contact Us
en_USEnglish