ProjectBuild an AI-Powered Digital Bank with RAG: the explanation · Module 11: Model routing: two models, one answer · part 13 of 20
Part 13 · Module 11: Model routing: two models, one answer

Module 11: Model routing: two models, one answer

22 min read·
About 35 minutes · Needs: Module 1 (kinds of questions) and Module 10 (the agent graph) · Code: backend/app/agent/router.py, backend/app/agent/llm.py, backend/app/observability/costs.py

Where this fits

WHERE THIS FITS The Kestrel Bank system this module CLIENT API LAYER FastAPI SAFETY AGENT LangGraph MODELS RETRIEVAL DATA AND INGESTION Postgres, Redis QUALITY Langfuse Customer app React Admin app React FastAPI REST + streaming Auth + RBAC tokens, roles Document upload admin only, checked Guardrails injection, PII Router small or large Agent LangGraph Banking tools ledger, transfers LLMs Groq, Gemini Retrieval hybrid + rerank Ingestion parse, chunk, embed PostgreSQL + pgvector ledger, chunks, state Redis limits, queue Observability Langfuse, metrics, logs Evaluation golden set, release gate
The router sits between the guardrails and the agent (blue: this module's parts); its decision picks the model, and every call's cost lands in observability.

Every message passes the input guardrails and reaches the router before the agent calls any model. The router picks the model for this turn, the agent can change that mid-turn, each model has a fallback provider, and every call's cost lands in observability.

The rest of this project is yours to keep

This project is bought on its own, once, and stays readable afterwards, including the parts added to it later.

Or open everything with a plan