A specialist agent can handle a bounded request without sharing its whole conversation with the caller. In LangChain, a supervisor calls subagents through tools and combines their returned answers into a final response.
Each tool description tells the supervisor when to delegate, while the wrapper controls what the specialist receives. Passing a self-contained request and returning only the specialist's final message keeps its internal tool calls out of the supervisor's conversation. Without a checkpointer, each specialist invocation starts with fresh conversation state.
A pricing specialist provides a small working case, with an arithmetic tool that calculates an order total and a supervisor that explains the quote. Both agents use a local Ollama model without an API key. Several model calls are needed for one request, so response time depends on the machine running the model.
Steps to build a multi-agent supervisor with subagents in LangChain:
- Activate a Python 3.11 or newer project virtual environment.
LangChain 1.5 requires Python 3.11 or newer. A new project environment keeps dependency upgrades separate from existing applications.
Related: How to create a virtual environment for LangChain
Related: How to install Python 3 on Ubuntu or Debian - Install LangChain and its Ollama integration in the active environment.
This uses the current create_agent API, without the legacy langgraph-supervisor package. Upgrading an existing pre-v1 environment can break old imports.
Related: How to install LangChain with pip
Related: How to migrate a Python application to LangChain v1
Related: Migrate from langgraph-supervisor$ python -m pip install --upgrade langchain langchain-ollama
- Pull the qwen3:4b model into a running local Ollama server.
$ ollama pull qwen3:4bThe model download needs about 2.5 GB of disk space, plus working memory for inference. The server must remain available while the Python program runs.
Related: How to install Ollama on Linux
Related: How to start the Ollama server
Related: How to pull an Ollama model - Create supervisor.py in the project directory using your text editor with the following model configuration.
- supervisor.py
import os from langchain.agents import create_agent from langchain.tools import tool from langchain_ollama import ChatOllama model = ChatOllama( model="qwen3:4b", base_url=os.environ.get("OLLAMA_BASE_URL", "http://localhost:11434"), reasoning=True, temperature=0.6, top_p=0.95, top_k=20, num_ctx=8192, num_thread=4, )
reasoning=True keeps the model's thinking separate from its answer content. The sampling values follow Qwen3's thinking-mode recommendations; greedy sampling can cause repetition. This model tag reports thinking support without a hard off switch. num_ctx=8192 provides room for the prompts, tool schemas and results. num_thread=4 limits CPU inference to four threads; the value can match the CPU capacity available to the server. OLLAMA_BASE_URL is optional when the server is on the same machine; for a separate server, it holds the reachable base URL without /api. The unauthenticated API should stay on a trusted private connection.
Related: How to connect LangChain to an Ollama chat model
Related: Qwen3 sampling recommendations - Append the arithmetic tool and pricing agent after the model configuration in supervisor.py.
@tool def order_total(quantity: int, unit_price: int, delivery: int) -> int: """Calculate an order total in whole credits, including delivery once.""" return quantity * unit_price + delivery pricing_agent = create_agent( model=model, tools=[order_total], system_prompt=( "You are a pricing specialist. Use order_total for every calculation. " "Return the quantity, unit price, delivery charge and total in credits." ), )
The integer arguments represent whole credits. Only the specialist receives order_total; the supervisor will receive the specialist's wrapper instead. The tool performs arithmetic without reading files, executing shell commands or placing orders.
Related: How to define a tool in LangChain
Related: How to build a tool-calling agent in LangChain - Append the specialist tool wrapper after pricing_agent in supervisor.py.
@tool def pricing_specialist(request: str) -> str: """Ask the pricing specialist to calculate a quote from quantity, price and delivery.""" result = pricing_agent.invoke( {"messages": [{"role": "user", "content": request}]} ) return result["messages"][-1].content
This is the delegation boundary. A supervisor tool call enters the wrapper, which invokes a separate agent and waits for its generated answer. Returning the final message content makes that answer the supervisor's tool result. Calling this function directly would skip the supervisor's routing decision.
- Append the supervisor and customer request after pricing_specialist in supervisor.py.
supervisor = create_agent( model=model, tools=[pricing_specialist], system_prompt=( "You coordinate customer quotes. Delegate pricing calculations to " "pricing_specialist. Use its returned total and breakdown in your answer." ), ) result = supervisor.invoke( {"messages": [{ "role": "user", "content": "Quote 12 notebooks at 7 credits each, with 5 credits delivery.", }]} )
The supervisor and specialist can share one model instance while keeping separate prompts, tools and message histories. The supervisor decides whether to call pricing_specialist from its instructions and tool description.
Related: LangChain subagents pattern - Append message printing at the end of supervisor.py.
for message in result["messages"]: message.pretty_print()
The returned conversation includes the original request, the supervisor's tool-call arguments, the specialist's returned answer and the supervisor's final response. The specialist's internal conversation stays inside its invocation.
- Save supervisor.py.
- Run supervisor.py to verify the delegation and final quote. Example output:
$ python supervisor.py ##### snipped ##### Tool Calls: pricing_specialist (7d41d6c8-18e5-4c53-804b-8886d33003f4) ##### snipped ##### request: 12 notebooks at 7 credits each, with 5 credits delivery ================================= Tool Message ================================= Name: pricing_specialist ##### snipped ##### Total: 89 credits ================================== Ai Message ================================== ##### snipped ##### **Total: 89 credits**
A completed quote must include a pricing_specialist call, a tool message returning its answer, and a final supervisor answer using the total of 89 credits. A final answer without that tool call does not demonstrate delegation. Wording and tool-call identifiers vary between runs.