Final Project: Build a Typed RAG Assistant with LangChain.js and LangGraph.js
Combine everything from this course, typed chains, retrieval, tools, and LangGraph.js, into one working research assistant, given a question, it should decide whether it needs more retrieved context, pull from a small local knowledge base, and produce a final grounded, typed answer.
Requirements
- Set up a real API key and install
@langchain/core,@langchain/openai(or your provider's package), and@langchain/langgraph. - Build a small local knowledge base (3-5 short text documents on any topic you like) and set up a retriever for it, using the splitting and vector store pattern from the Retrieval lesson.
- Define a typed state with
Annotation.Root, at least aquestion,context, andanswerfield. - Build a LangGraph.js graph with at least three nodes: one that retrieves context for the question, one that decides (via
addConditionalEdges) whether the retrieved context is sufficient or another retrieval pass is needed, and one that generates the final answer using an LCEL chain (.pipe()) grounded in the retrieved context. - Compile and run the graph on at least three different questions, one clearly answerable from your knowledge base and one that isn't, confirm the assistant behaves sensibly in both cases (e.g. says it doesn't know, rather than making something up).
Stretch goals
- Add a Zod-defined tool (e.g. a calculator, or a fake "current date" function) and a node that lets the model call it when relevant, on top of retrieval.
- Add a loop limit (a counter field in state) so a conditional edge can't send the graph back to retrieval forever.
- Type the graph's final result end to end, so
result.answeris astringyour calling code can rely on without a cast.
Submit a link to your finished project (a repo or gist) below, an instructor will review it before you can mark this lesson complete.