buildfastwithai
GenAI Bootcamp
Daily GenAI Quiz
BuildFast Studio
Resources
buildfastwithai
BuildFast Bot
Ask to

BuildFast Bot

BuildFast Bot

Hey! Wanna know about Generative AI Crash Course?

LangGraph-Supervisor: Building Multi-Agent Workflows

March 10, 2025
4 min read
Published
LangGraph-Supervisor: Building Multi-Agent Workflows
LangGraph-Supervisor: Building Multi-Agent Workflows - BuildFast with AI

Do you want to be remembered as someone who waited or someone who created?

Gen AI Launch Pad 2025 is your platform to innovate.

Introduction

Artificial intelligence (AI) workflows often require multiple agents to collaborate on different tasks, such as research, calculations, or creative content generation. LangGraph-Supervisor simplifies the creation of hierarchical multi-agent systems, allowing a central supervisor agent to manage task delegation and communication between specialized agents efficiently.

In this tutorial, we will:

  • Set up LangGraph-Supervisor and its dependencies.
  • Create AI agents for different tasks.
  • Implement a supervisor agent to orchestrate them.
  • Run and test the multi-agent workflow.

By the end, you'll have a functional system where AI agents collaborate effectively, improving automation in your applications.

Step 1: Install Dependencies

Before we start coding, ensure you have LangGraph-Supervisor and LangChain installed. You can install them using pip:

pip install langgraph-supervisor langchain-openai

Also, set up your OpenAI API key:

from google.colab import userdata
import os

os.environ["OPENAI_API_KEY"] = userdata.get('OPENAI_API_KEY')

This ensures your AI models can interact with OpenAI’s services.

Step 2: Import Required Libraries

Now, import the necessary libraries:

from langchain_openai import ChatOpenAI
from langgraph_supervisor import create_supervisor
from langgraph.prebuilt import create_react_agent

We will use ChatOpenAI as the underlying AI model and create specialized AI agents with LangGraph-Supervisor.

Step 3: Initialize the AI Model

Define the AI model that our agents will use:

model = ChatOpenAI(model="gpt-4o")

This model will power the agents responsible for different tasks in our system.

Step 4: Define AI Agent Functions

Our multi-agent system will include a math expert and a research expert. First, define the functions these agents will use:

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 is the latest data available for your query."

Step 5: Create AI Agents

Now, create the specialized agents:

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 time."
)

research_agent = create_react_agent(
    model=model,
    tools=[web_search],
    name="research_expert",
    prompt="You are a research expert with web access. Do not perform calculations."
)

These agents are designed to focus on their respective tasks without overlapping responsibilities.

Step 6: Create the Supervisor Workflow

The supervisor agent will manage communication between the specialized agents:

workflow = create_supervisor(
    [research_agent, math_agent],
    model=model,
    prompt=(
        "You are a team supervisor managing a research expert and a math expert. "
        "For research tasks, use research_agent. "
        "For math tasks, use math_agent."
    )
)

The supervisor dynamically delegates tasks based on user input.

Step 7: Running the Workflow

Compile and execute the workflow:

app = workflow.compile()
result = app.invoke({
    "messages": [
        {"role": "user", "content": "What is the sum of 10 and 20?"}
    ]
})

for m in result["messages"]:
    m.pretty_print()

This process:

  1. The supervisor agent receives the user request.
  2. It delegates the request to the math expert.
  3. The math expert processes the request and returns the result.
  4. The supervisor presents the final response.

Step 8: Adding Memory to Supervisor

To make the workflow remember previous interactions, we introduce memory:

from langgraph.checkpoint.memory import InMemorySaver
from langgraph.store.memory import InMemoryStore

checkpointer = InMemorySaver()
store = InMemoryStore()

app = workflow.compile(
    checkpointer=checkpointer,
    store=store
)

This allows agents to recall past queries and maintain context over multiple interactions.

Conclusion

By following this tutorial, you’ve built a multi-agent system where a supervisor agent effectively delegates tasks between a math expert and a research expert. With LangGraph-Supervisor, complex AI workflows become more structured and efficient.

Key Takeaways:

  • LangGraph-Supervisor simplifies multi-agent coordination.
  • AI agents specialize in specific tasks, improving efficiency.
  • The supervisor agent dynamically routes tasks based on user input.
  • Adding memory enhances AI interaction capabilities.

References

  1. LangGraph Documentation
  2. LangChain Supervisor GitHub
  3. LangChain Official Website
  4. LangGraph-Supervisor Experiment Notebook

---------------------------

Stay Updated:- Follow Build Fast with AI pages for all the latest AI updates and resources.

Experts predict 2025 will be the defining year for Gen AI Implementation. Want to be ahead of the curve?

Join Build Fast with AI’s Gen AI Launch Pad 2025 - your accelerated path to mastering AI tools and building revolutionary applications.

---------------------------

Resources and Community

Join our community of 12,000+ AI enthusiasts and learn to build powerful AI applications! Whether you're a beginner or an experienced developer, our resources will help you understand and implement Generative AI in your projects.

  • Website: www.buildfastwithai.com
  • LinkedIn: linkedin.com/company/build-fast-with-ai/
  • Instagram: instagram.com/buildfastwithai/
  • Twitter: x.com/satvikps
  • Telegram: t.me/BuildFastWithAI
BuildFastwithAI
satvik@buildfastwithai.com

Koramangala, Bengaluru, 560034

Support

  • Consulting
  • GenAI Course
  • BuildFast Studio

Company

  • Resources
  • Events

Legal

  • Privacy
  • Terms
  • Refund

Our Products

Educhain

Educhain

AI-powered education platform for teachers

BuildFast Studio

BuildFast Studio

The Indian version of CharacterAI but even more varieties.

LinkedInInstagramTwitterGitHub

© 2025 Intellify Edventures Private Limited All rights reserved.