AI Hints
Home›LangGraph Tutorial›Patterns and Models
LangGraph · Lesson 113 of 120

Choosing Models per Node

Big and small.

⏱ 2 min read▶ Video at 2:01:45🎓 Free
Watch this lesson in the LangGraph courseWatch on YouTube ↗Full LangGraph course

Every node can use a different model. That's a big advantage of graphs. Use a small, fast, cheap model where the job is easy, and save a larger model for the hard steps.

Choosing Models per Node
From the video: Choosing Models per Node
  • A model per node
  • Small for easy jobs
  • Large for hard steps

Two models, two jobs

A small model, with structured output, classifies the message. That's an easy job. A second model writes the reply. In this demo both are Gemini flash lite, but in a real app, you'd point the writer at a larger model, by changing one string. Run it. The classifier picks the topic, and the writer replies.

two_models.pypython
from typing import Literal
from pydantic import BaseModel
from langchain.chat_models import init_chat_model

SMALL = "google_genai:gemini-flash-lite-latest"   # fast and cheap
LARGE = "google_genai:gemini-flash-lite-latest"   # swap in a bigger model here

class Topic(BaseModel):
    topic: Literal["books", "orders", "other"]

classifier = init_chat_model(SMALL, temperature=0).with_structured_output(Topic)
writer = init_chat_model(LARGE, temperature=0)

message = "Can you suggest a gripping fantasy series for a long holiday?"
print("topic:", classifier.invoke(message).topic)
print("reply:", writer.invoke(f"One sentence reply: {message}").text.strip())
Output
topic: books
reply: Lose yourself in Brandon Sanderson's *Stormlight Archive*, a massive, epic
fantasy series filled with intricate world-building, high stakes, and unforgettable
characters that will easily consume your entire holiday.

Which model where

Routing, grading, and extraction suit small models. Most agent steps, and RAG answers, suit mid sized models. Planning, tricky reasoning, and critiques of important work suit the largest. Test each choice with your test set.

Node jobModel
Route, grade, extractsmall
Agent steps, RAG answersmid
Plan, reason, critiquelarge
Alwaystest with your test set

Summary

Give each node the smallest model that does its job well. Graphs make mixing models easy. Next, the advanced quiz.

Key takeaways
  • Small for routing
  • Large for reasoning
  • Test each choice
Next up: Advanced Quiz — test yourself