How to Build Multi-Agent Systems with LangGraph

36.2K views
•
July 2, 2025
by
Krish Naik
YouTube video player
How to Build Multi-Agent Systems with LangGraph

TL;DR

Build a LangGraph multi-agent system by defining shared message state, creating specialized agents, binding each agent to appropriate tools, and routing outputs through the graph. The demonstrated workflow uses a researcher with Tavily web search and a writer that summarizes findings, while supervisor, swarm, and hierarchical patterns provide options for coordinating more complex tasks.

Transcript

Hello all, my name is Krishna and welcome to my YouTube channel. So guys, we are going to continue the discussion with respect to agentic AI with langraph. Already in my previous video, I have uploaded a crash course on agentic AI with langraph along with MCP where we discussed how to work with AI agents, how to create a simple aentic application a... Read More

Key Insights

  • A multi-agent system is a workflow in which independent AI agents communicate and pass information to solve a complex request. LangGraph models this workflow as a graph containing a start point, specialized agent nodes, directed transitions, and an endpoint.
  • The simple architecture is a sequential handoff from a researcher to a writer. The researcher gathers relevant information with a web-search tool, then places its response in shared state and identifies the writer as the next agent responsible for producing the summary.
  • A supervisor architecture is a centralized coordination pattern in which a supervisor routes work to specialized roles such as an analyst, researcher, or writer. Completed work returns to the supervisor, which decides whether another assignment is necessary or the workflow should end.
  • A hierarchical architecture is presented as a third major technique for implementing multi-agent workflows. Together with simple and supervisor patterns, it provides another way to structure agent responsibilities and communication when a workflow contains multiple specialized tasks or levels of coordination.
  • AgentState is the shared data structure that carries information throughout the graph. It inherits from MessagesState, retains the workflow's messages, and adds a next_agent string so nodes can communicate which specialized agent should receive control after the current step finishes.
  • Tools give specialized agents distinct operational capabilities. The research tool invokes Tavily Search Results with a maximum of three results, while the summary tool processes findings and returns summary content limited to the first 500 values or characters shown in the implementation.
  • The researcher node is guided by a system message that identifies it as a research assistant and instructs it to use web search for the user's request. The language model is bound specifically to the search_web tool before being invoked with the system message and conversation messages.
  • The demonstrated model setup uses LangChain's chat-model initializer with Groq and the Llama 3.1 8B Instant model. Environment variables loaded from a dotenv file supply the Groq API key, while additional imports support graph state, tool nodes, messages, and memory saving.

Install to Summarize YouTube Videos and Get Transcripts

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: How do you build a simple multi-agent system with LangGraph?

Define a shared AgentState, create one node function for each specialized agent, bind each agent to the tool required for its role, and connect the nodes in the intended execution order. In the demonstrated design, the researcher searches the web, stores its response in the message state, sets next_agent to the writer, and hands the collected information to that writer for summarization.

Q: What is the role of AgentState in a LangGraph workflow?

AgentState carries the information needed across the entire graph. The implementation inherits from MessagesState, which supplies a messages field for retaining conversation and agent outputs. It also defines a next_agent string. Each node can update that value to identify the agent that should execute next, allowing information and routing decisions to travel together through the workflow.

Q: How does the researcher agent use web search?

The researcher node receives the current AgentState and extracts its messages. It adds a system instruction that describes the model as a research assistant and tells it to use the search_web tool for the user's request. The language model is bound to that tool, invoked with the system instruction and stored messages, and its response is forwarded to the writer.

Q: What does the writer agent do in the simple workflow?

The writer receives the information produced by the researcher and turns those findings into a summary. The tutorial creates a separate write_summary tool for this responsibility, keeping research and writing as distinct roles. This separation allows the researcher to focus on retrieving relevant material while the writer focuses on presenting the collected material as a coherent result.

Q: How does a supervisor multi-agent architecture work?

A supervisor controls the flow among specialized workers such as an analyst, researcher, or writer. It chooses which worker should receive a task, waits for that worker to complete the assignment, and receives the result back. The supervisor then evaluates whether additional work is required, delegates again when necessary, or ends the graph when the requested workflow is complete.

Q: What multi-agent architectures are covered in the tutorial?

The tutorial organizes multi-agent implementation around three major architectures: a simple multi-agent flow, a supervisor architecture, and a hierarchical architecture. The description also names a swarm pattern and dynamic handoffs using the Command primitive. The simple example directly connects a researcher and writer, while the supervisor design repeatedly routes work through a central coordinating agent.

Q: Which model, libraries, and tools are used in the implementation?

The implementation uses LangGraph components such as StateGraph, END, ToolNode, MessagesState, and MemorySaver. It initializes a Groq-backed Llama 3.1 8B Instant chat model through LangChain, loads the Groq API key from environment variables, and uses Tavily Search Results for web research. Message imports include base, human, AI, and system message types.

Q: Why is the next_agent field needed in the shared state?

The next_agent field records where control should move after a node completes its work. In the simple workflow, the researcher sets this value to the writer after producing a response. Keeping the destination inside AgentState makes the routing decision available throughout the graph and supports workflows in which execution moves among multiple agents according to the current task and result.

Summary & Key Takeaways

  • The tutorial continues an Agentic AI series that previously covered basic applications, MCP, debugging, monitoring, and LangGraph Studio. It introduces multi-agent systems as workflows in which specialized AI agents exchange information and cooperate on complex requests, with LangGraph representing agents and transitions as nodes and connections within an executable graph.

  • Three coordination patterns organize the course: simple multi-agent workflows, supervisor architectures, and hierarchical architectures. A simple workflow passes work directly from a researcher to a writer. A supervisor instead selects workers, receives their completed results, evaluates whether more work remains, and either delegates another task or ends the workflow.

  • The implementation defines an AgentState derived from MessagesState, including a next_agent string that records where execution should continue. It initializes a Groq-hosted Llama 3.1 8B Instant model, creates Tavily search and summary tools, and configures a researcher node that searches for information before passing its response to the writer.


Read in Other Languages (beta)

Share This Summary 📚

Explore More Summaries from Krish Naik 📚