- Easy to visualize,
- Highly modular, and
- A practical, real-world use case you can adapt for your organization.

High-level objective
- Build a chatbot that:
- Understands user intent,
- Decides whether to answer directly or perform a document search, and
- Returns a formatted response.
- Adhere to LangGraph principles: modular nodes, explicit state, and declarative routing.
High-level flow
- Receive user input — an entry node persists the user’s message into the graph state.
- Classify intent — a lightweight LLM or classifier marks whether the user expects a direct answer or a search.
- Conditional routing — route to search or answer branches based on intent.
- External search (optional) — perform retrieval when external knowledge is required.
- Answer generation — use an LLM to produce the response (with or without retrieved context).
- Merge and respond — format a final response in a shared node so output formatting or streaming can be centralized.
About the entry node and state
- The entry node’s responsibility is to persist the raw user message into graph state (for example:
state.user_message). - Every subsequent node reads from and writes to
state; this keeps each node small, composable, and independently testable.
Design the entry node to only persist input (avoid embedding logic here). Separating intent classification, retrieval, and generation makes each piece replaceable and easier to maintain or extend.
Routing and branching
- After intent classification, treat the graph like a decision tree: if
intent == "search", route to the retrieval branch; ifintent == "answer", route to the direct answer branch. - Converge both branches into a common response node. Centralizing response formatting makes it trivial to add streaming, templating, or channel-specific outputs without changing upstream logic.
- Because nodes are independent and routing is declarative, you can swap or instrument nodes without refactoring unrelated components.
Extensibility and observability
- Replace the intent classifier with a fine-tuned model when higher accuracy is required.
- Add a fallback node to handle empty search results or low-confidence classifications.
- Swap the final response generator for a streaming responder to enable real-time outputs.
- Use LangGraph observability tools (logs, metrics, traces) to debug node behavior and routing decisions.

Quick reference: Node responsibilities and example state
Minimal node pseudocode
Below is an illustrative pseudocode sketch of node behaviors and state transitions:Recap
- Nodes are chainable functions: LLM calls, retrievers, classifiers, and formatters.
- State captures user input and intermediate results, enabling small, testable nodes.
- Conditional routing makes flow explicit and predictable.
- The pattern is readable, testable, reusable, and ready to extend with cycles, memory, or streaming.
Links and references
- LangGraph documentation
- Retrieval-Augmented Generation patterns
- Best practices for prompt design and LLM safety