Hierarchical multi-agent orchestration
Several domain specialists must be coordinated by one central decision-maker.
AI Agents · Const
createSupervisor builds a hierarchical multi-agent supervisor that routes tasks among specialized agents using handoff tools. Configure the supervisor model, managed agents, prompt, naming mode, output-history mode, and optional pre-model processing.
createSupervisor builds a hierarchical multi-agent workflow in which a language model routes work among specialized agents through handoff tools. The returned workflow must be compiled before invocation; optional settings control agent-name exposure, message-history forwarding, and preprocessing before the supervisor model runs.
createSupervisor({ agents, llm, prompt?, agentNameMode?, outputMode?, preModelHook?, ... })| Name | Type | Description |
|---|---|---|
agents | PregelNode[] | Managed worker agents that the supervisor can delegate to. |
llm | LanguageModelLike | Language model used by the supervisor. |
prompt | string | SystemMessage | SystemMessagePromptTemplate | ... | Instructions that guide supervisor routing and coordination. |
agentNameMode | "inline" | "tool" | Controls how managed-agent names are exposed to the supervisor model. |
outputMode | "full_history" | "last_message" | Controls whether full worker history or only the last message is added. |
preModelHook | RunnableLike | Optional node run before the supervisor LLM, useful for trimming or summarizing history. |
A supervisor graph that coordinates the supplied agents and must be compiled before execution.
import { createSupervisor } from "@langchain/langgraph-supervisor";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { ChatOpenAI } from "@langchain/openai";
const model = new ChatOpenAI({ model: "gpt-4o-mini" });
const researcher = createReactAgent({ model, tools: [] });
const supervisor = createSupervisor({
agents: [researcher],
llm: model,
prompt: "Delegate research tasks to the researcher.",
}).compile();
const result = await supervisor.invoke({
messages: [{ role: "user", content: "Research LangGraph." }],
});
console.log(result.messages.at(-1)?.content);Creates one worker agent, places it under a supervisor, compiles the workflow, and invokes it with a user message.
Several domain specialists must be coordinated by one central decision-maker.
Worker outputs need controlled context sharing with the coordinator.
Long conversations require preprocessing before model calls.
The model needs explicit worker identity in routed messages.
createSupervisor constructs a multi-agent supervisor that coordinates specialized agents. It uses an LLM to decide which managed agent to invoke and exposes handoff tools for agent-to-agent communication.
Follow-up: How would you reduce context growth? Configure the documented pre-model node to trim or summarize history before the supervisor LLM runs, and consider forwarding only the last worker message.
The supervisor receives managed agents and an LLM, along with optional prompt and configuration settings. The resulting workflow is compiled and then invoked like a LangGraph application.
Follow-up: Why compile it? Compilation turns the graph definition into an executable workflow that can be invoked and used with LangGraph runtime features.
Agent-name handling controls how a managed agent's identity is exposed to the supervisor model. The documented modes include adding the name inline in message content with XML-style tags or using the alternative name-exposure behavior.
Follow-up: When would inline naming help? It can make the worker identity explicit in the model-visible content, which is useful when the supervisor must distinguish similarly shaped outputs.
LangGraph Multi-Agent SupervisorcreateSupervisorhandoff toolsfull_historylast_messagepreModelHookagentNameMode