RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Fredoline Eruo
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /LangGraph for Local Agents
  6. /Ch. 10
LangGraph for Local Agents

10. Supervisor Agent

Chapter 10 of 18 · 15 min
KEY INSIGHT

A model-based supervisor replaces hard-coded routing with LLM reasoning over the shared state. The validation fallback is critical—unexpected model outputs should gracefully terminate rather than crash the graph.

The supervisor agent is a specialized node that uses a language model to make routing decisions, rather than hard-coded if/else logic. This makes the team more flexible—a model-based supervisor can read task descriptions, worker outputs, and decide dynamically which worker to call next without you pre-programming every branch.

from langchain_ollama import OllamaLLM
from langgraph.prebuilt import create_react_agent

llm = OllamaLLM(model="llama3.2:latest", temperature=0.3)
llm_for_supervisor = OllamaLLM(model="llama3.2:latest", temperature=0)

worker_tools = [search_web, read_file, write_code]
worker_app = create_react_agent(model=llm, tools=worker_tools)

def model_supervisor(state: SupervisorState) -> SupervisorState:
    prompt = build_supervisor_prompt(state)
    response = llm_for_supervisor.invoke(prompt)
    # Parse response to extract routing decision
    decision = parse_routing_decision(response)
    return {"next_worker": decision}

The prompt must include enough context from the shared state for the supervisor to make an informed decision. Include the original task, completed worker results, pending assignments, and a description of available workers. Without this context, the supervisor model guesses rather than reasons.

The failure mode: model-based supervisors can hallucinate routing decisions—returning a worker name that does not exist in the graph. Validate the returned decision against the set of valid worker names in the routing function:

VALID_WORKERS = {"researcher", "coder", "done"}

def safe_route(state: SupervisorState) -> Literal["researcher", "coder", "done"]:
    decision = model_supervisor(state)
    if decision not in VALID_WORKERS:
        return "done"  # fallback to termination rather than crash
    return decision

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

EXERCISE

Replace the hard-coded supervisor from Chapter 9 with an Ollama-powered model supervisor. Compare the routing decisions between the rule-based and model-based supervisors for five different task inputs.

← Chapter 9
Multi-Agent Teams
Chapter 11 →
Specialized Worker Agents