Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Agents · Const

Supervisor Agent

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.

How it works

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.

Syntax

createSupervisor({ agents, llm, prompt?, agentNameMode?, outputMode?, preModelHook?, ... })

Parameters

NameTypeDescription
agentsPregelNode[]Managed worker agents that the supervisor can delegate to.
llmLanguageModelLikeLanguage model used by the supervisor.
promptstring | 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.
preModelHookRunnableLikeOptional node run before the supervisor LLM, useful for trimming or summarizing history.

Returns

A supervisor graph that coordinates the supplied agents and must be compiled before execution.

Key points

  • The factory creates a central coordinator for a hierarchical multi-agent workflow.
  • Managed agents communicate through handoff tools exposed to the supervisor workflow.
  • The full-history mode preserves all messages produced by a managed agent when adding its result to the shared workflow history.
  • The default last-message mode limits forwarded worker output to the most recent message.
  • Agent-name configuration determines how worker identity is presented to the supervisor model.

Common mistakes

  • Choose message-history mode deliberately: the documented setting can forward the full agent history or only the last message, with the latter as the default.
  • Use the pre-model hook for long histories when trimming or summarization is needed before the supervisor calls its language model.
  • Workers are coordinated by the supervisor; design specialized agents and avoid assuming that workers communicate directly with one another.

Example: Create and invoke a supervisor

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.

When to use it

Hierarchical multi-agent orchestration

Several domain specialists must be coordinated by one central decision-maker.

Message-history management

Worker outputs need controlled context sharing with the coordinator.

History trimming or summarization

Long conversations require preprocessing before model calls.

Agent-name exposure

The model needs explicit worker identity in routed messages.

Interview questions

QWhat does createSupervisor do?

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.

QWhat are the core inputs and lifecycle?

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.

QHow can agent names be exposed to the supervisor?

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 Supervisor
  • createSupervisor
  • handoff tools
  • full_history
  • last_message
  • preModelHook
  • agentNameMode

Source: createSupervisor | LangGraph.js API Reference. Checked 2026-10-15.