Route Between Models in LangGraph: Cheap vs. Hard Reasoning
Advanced · 30 minutes · 5 tasks, checked automatically · 100 points
Build a LangGraph workflow that intelligently routes user queries between two Gemini model tiers inside the same graph. Simple classification tasks go to the fast, cheap Gemini Flash model, while complex multi-step reasoning is escalated to the larger Gemini 1.5 Pro model. You will implement a StateGraph with a classifier node, a conditional routing edge, two specialized worker nodes, and verify the routing logic with deterministic output checks.
What you’ll learn
- Install LangGraph and the Google Generative AI LangChain integration inside the toolbox container
- Define a TypedDict graph state that carries the query, a route decision, and the final answer
- Implement a classifier node that uses gemini-2.0-flash to label a query as 'simple' or 'complex'
- Implement a conditional routing edge that reads the classifier output and dispatches to the correct worker node
- Implement two worker nodes — one backed by gemini-2.0-flash and one by gemini-1.5-pro — and verify routing is correct via deterministic output markers
How this lab works
- Start the lab: One click starts a sandbox with a local model and the agent’s toolbox: no API key and no token bill.
- Work through 5 tasks: Each task says what to build or fix. You do it yourself, in a real terminal, with hints when you get stuck.
- Check your work: Check my work inspects the agent, its config and its output, and says what passed and what to fix.
- Finish and keep going: 100 points, your progress saved, and the next lab to try.
What it runs on
- Runs: Locally, against a model on your computer: no API key, no tokens
- Model: gemini-2.0-flash
- Open source: github.com/langchain-ai/langgraph
What you need
- A free LearnXops account
- The LearnXops desktop app for macOS, Windows or Linux
- A hosted Gemini sandbox started in the Agent Playground with GEMINI_API_KEY injected
Topics: langgraph, routing, multi-model, gemini, conditional-edges, StateGraph, orchestration, cost-optimization, gemini-flash, gemini-pro
Create a free account to start this lab.
Keep going
- Hierarchical CrewAI on Claude: Manager-Delegate Orchestration with Acceptance Criteria
- Persistent OpenClaw: docker-compose with Surviving Volumes
- Lock OpenClaw Down: Pairing Approval, Per-Skill Permission Scoping, and Shell Command Allowlisting
- Autonomous File Triage & Daily Digest with OpenClaw
- Harden Hermes: Route All Tool Calls Through Docker Containers
- Run the Hermes Gateway as a Persistent Service with Request Logging and Clean Shutdown