Practice: Shop Team
Supervisor and specialists.
Let's practise with a three member team. A supervisor routes to books, orders, or a friendly general assistant, for everything else. Then we'll watch which member answers each question.

- Three specialists
- A supervisor routes
- Watch who answers
The shop team
The general node is a simple model call. The supervisor chooses between three members now. We stream with updates mode, to see which node handles each question. Run it. Each question is routed to the right team member, and we see their name next to the answer.
from typing import Literal
from pydantic import BaseModel
from langchain.chat_models import init_chat_model
from langgraph.graph import MessagesState, StateGraph, START
from langgraph.types import Command
from specialists import books, orders
model = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0)
class Pick(BaseModel):
agent: Literal["books", "orders", "general"]
def supervisor(s: MessagesState) -> Command[Literal["books", "orders", "general"]]:
return Command(goto=model.with_structured_output(Pick).invoke(s["messages"]).agent)
def general(s: MessagesState):
return {"messages": [model.invoke([("system", "Friendly shop assistant. One sentence.")] + s["messages"])]}
b = StateGraph(MessagesState); b.add_edge(START, "supervisor")
for name, node in [("supervisor", supervisor), ("books", books), ("orders", orders), ("general", general)]: b.add_node(name, node)
for q in ["Is Dune in stock?", "Where's order RB-1234?", "Thanks, you have been very helpful!"]:
for step in b.compile().stream({"messages": [{"role": "user", "content": q}]}, stream_mode="updates"):
if "supervisor" not in step: print(q, "->", *step, "|", list(step.values())[0]["messages"][-1].text.strip()[:70])Is Dune in stock? -> books | Yes, we have 3 copies of Dune in stock. Where's order RB-1234? -> orders | Order RB-1234 has shipped and is arriving Thursday. Thanks, you have been very helpful! -> general | You are very welcome, and please let me know if you need anything else
Also uses shop_tools.py
from langchain.tools import tool
BOOKS = {
"The Hobbit": {"stock": 7, "price": 8.99, "author": "J.R.R. Tolkien"},
"Dune": {"stock": 3, "price": 9.99, "author": "Frank Herbert"},
"Circe": {"stock": 0, "price": 10.99, "author": "Madeline Miller"},
}
@tool
def check_stock(title: str) -> int:
"""Copies of a book in stock at Riverside Books."""
return BOOKS.get(title, {}).get("stock", 0)
@tool
def get_price(title: str) -> float:
"""Price of a book in pounds."""
return BOOKS.get(title, {}).get("price", 0.0)
@tool
def get_author(title: str) -> str:
"""Author of a book."""
return BOOKS.get(title, {}).get("author", "unknown")Also uses specialists.py
from langchain.agents import create_agent
from langchain.tools import tool
from shop_tools import check_stock, get_price, get_author
@tool
def order_status(order_id: str) -> str:
"""Status of an order. Order ids look like RB-1234."""
return {"RB-1234": "shipped, arriving Thursday", "RB-5678": "being packed"}.get(order_id, "not found")
MODEL = "google_genai:gemini-flash-lite-latest"
books = create_agent(MODEL, tools=[check_stock, get_price, get_author], name="books",
system_prompt="You are the books specialist at Riverside Books. Be brief.")
orders = create_agent(MODEL, tools=[order_status], name="orders",
system_prompt="You are the orders specialist at Riverside Books. Be brief.")What you practised
You built a team with a supervisor, two tool using specialists, and a simple general node. Streaming updates showed which member answered. Try adding a fourth member, like an events specialist for story time.
| key | value |
|---|---|
| Supervisor | routes |
| Specialists | tools + prompt |
| General | simple node |
| Try | an events specialist |
Summary
A supervisor and focused members make a shop team. Streaming shows who answered. Next, a quiz on multi agent systems.
Key takeaways- Supervisor
- Specialists
- Stream to watch