diff --git a/docs/docs/concepts/multi_agent.md b/docs/docs/concepts/multi_agent.md index a6f4ad5c1..d6ccb5529 100644 --- a/docs/docs/concepts/multi_agent.md +++ b/docs/docs/concepts/multi_agent.md @@ -241,7 +241,7 @@ To address this, you can design your system _hierarchically_. For example, you c from typing import Literal from langchain_openai import ChatOpenAI from langgraph.graph import StateGraph, MessagesState, START, END - +from langgraph.types import Command model = ChatOpenAI() # define team 1 (same as the single supervisor example above) @@ -286,7 +286,7 @@ team_2_graph = team_2_builder.compile() # define top-level supervisor builder = StateGraph(MessagesState) -def top_level_supervisor(state: MessagesState): +def top_level_supervisor(state: MessagesState) -> Command[Literal["team_1_graph", "team_2_graph", END]]: # you can pass relevant parts of the state to the LLM (e.g., state["messages"]) # to determine which team to call next. a common pattern is to call the model # with a structured output (e.g. force it to return an output with a "next_team" field) @@ -297,10 +297,11 @@ def top_level_supervisor(state: MessagesState): builder = StateGraph(MessagesState) builder.add_node(top_level_supervisor) -builder.add_node(team_1_graph) -builder.add_node(team_2_graph) - +builder.add_node("team_1_graph", team_1_graph) +builder.add_node("team_2_graph", team_2_graph) builder.add_edge(START, "top_level_supervisor") +builder.add_edge("team_1_graph", "top_level_supervisor") +builder.add_edge("team_2_graph", "top_level_supervisor") graph = builder.compile() ```