t# LangChain & LangGraph Projects
A collection of 6 small projects exploring LangChain and LangGraph — from a one-line OpenAI call to a self-correcting RAG pipeline. Each project lives in its own folder with its own requirements.txt and .env file.
| # | Project | What It Does |
|---|---|---|
| 1 | simple_message/ |
Basic LLM calls — direct, with output parser, with prompt template, and served via FastAPI. |
| 2 | chating_history/ |
A chatbot that remembers the conversation using RunnableWithMessageHistory. |
| 3 | vector_store/ |
Embed documents, store them in Chroma, and run similarity search. |
| 4 | rag_project/ |
A simple RAG pipeline: load a blog post, chunk it, retrieve, answer. |
| 5 | agents/ |
A ReAct agent that can search the web with Tavily. |
| 6 | advanced_rag/ |
Self-correcting RAG with LangGraph: routing, document grading, hallucination check, web fallback. |
The projects are roughly ordered from easy to hard. If you're new to LangChain, follow them in order.
You'll need Python 3.10+. Each folder has its own dependencies, so install them per project:
# Clone the repo
git clone <repo-url>
cd langchain-projects
# Pick a project
cd simple_message
# (Optional) Create a virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install
pip install -r requirements.txtThen run the script:
python simplemessage.pyEvery project needs at least an OpenAI API key. Some need extra keys (Tavily for web search, LangSmith for tracing). Each folder already contains a .env file with the key names — you just need to fill in the values.
⚠️ Never commit real API keys to GitHub. Add.envto your.gitignore(one is already provided inadvanced_rag/).
| Key | Used by | Get it from |
|---|---|---|
OPENAI_API_KEY |
All projects | https://platform.openai.com/api-keys |
TAVILY_API_KEY |
agents/, advanced_rag/ |
https://tavily.com (free tier available) |
LANGCHAIN_API_KEY |
LangSmith tracing (optional) | https://smith.langchain.com |
LANGCHAIN_TRACING_V2 |
Set to true to enable tracing |
— |
LANGCHAIN_PROJECT |
Project name shown in LangSmith | Any string, e.g. my-rag |
| Project | Required keys | Optional keys |
|---|---|---|
simple_message/ |
OPENAI_API_KEY |
LangSmith vars |
chating_history/ |
OPENAI_API_KEY |
LangSmith vars |
vector_store/ |
OPENAI_API_KEY |
LangSmith vars |
rag_project/ |
OPENAI_API_KEY |
LangSmith vars |
agents/ |
OPENAI_API_KEY, TAVILY_API_KEY |
LangSmith vars |
advanced_rag/ |
OPENAI_API_KEY, TAVILY_API_KEY |
LangSmith vars |
OPENAI_API_KEY=sk-...
TAVILY_API_KEY=tvly-...
LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=ls__...
LANGCHAIN_PROJECT=my-langchain-projectload_dotenv() is called at the top of every script, so the keys are picked up automatically.
Four small scripts that build up the basic LangChain pattern step by step:
simplemessage.py— the simplest case: send messages, get a response.simplemessagewithoutparser.py— same, but pipe the output throughStrOutputParser.simplemessagewithtemplates.py— useChatPromptTemplateso the prompt is reusable.serve.py— wrap the chain in a FastAPI app with LangServe.
Run any of them with python <filename>.py. For serve.py, open http://localhost:8080/chain/playground after starting it.
A chatbot that keeps track of the conversation. Uses InMemoryChatMessageHistory with a session_id so multiple users can have separate conversations. The session ID is currently hardcoded — change it to support multiple users.
python main.py
> Hello!
> What did I just say?Embeds 5 short documents about pets, stores them in Chroma, and shows three ways to query: by text, by text with score, and by vector. main.py extends this into a full retrieval-augmented chain that answers questions using only the stored context.
A classic RAG pipeline:
- Load a blog post about LLM agents using
WebBaseLoader. - Split it into chunks with
RecursiveCharacterTextSplitter. - Embed and store in Chroma.
- Retrieve relevant chunks for a question.
- Generate an answer with the retrieved context.
The output streams as it's generated.
A ReAct-style agent built with create_react_agent from LangGraph. The agent has one tool — Tavily web search — and can decide when to use it. Try asking it about current weather or recent news, things the LLM doesn't know on its own.
The most complex project. A self-correcting RAG pipeline built as a LangGraph state machine. The flow:
- Route — decide whether the question goes to the vector store or directly to web search.
- Retrieve — get documents from Chroma.
- Grade documents — check whether the retrieved docs are actually relevant.
- Generate — produce an answer.
- Hallucination check — verify the answer is grounded in the docs.
- Answer check — verify the answer addresses the question.
- Fall back to web search if any check fails.
The graph is in graph/graph.py; nodes and chains are in their own modules. Run python main.py to test it end-to-end.
| Term | What It Means |
|---|---|
| Chain | A pipeline of steps connected with |, e.g. prompt | model | parser. |
| Runnable | The base interface for anything that can be .invoke()-d in LangChain. |
| Embedding | A vector that represents the meaning of a piece of text. |
| Vector store | A database that lets you search documents by semantic similarity. |
| RAG | Retrieval-Augmented Generation — fetch relevant docs, then ask the LLM to answer using them. |
| ReAct agent | An agent that alternates between Reasoning (thinking) and Acting (using a tool). |
| LangGraph | A library for building LLM workflows as state machines. |
- Costs add up. Each call to
OpenAIEmbeddingsorChatOpenAIcosts money. The advanced RAG project re-builds the vector store on every run — add apersist_directorycheck to skip re-embedding. - LangSmith helps a lot. Set
LANGCHAIN_TRACING_V2=trueand you'll see every step of every chain in https://smith.langchain.com — invaluable for debugging. - Watch your model name. GPT-4 is much pricier than GPT-3.5. For simple translations or routing,
gpt-3.5-turbois more than enough.
Provided for educational purposes.
LangChain · LangGraph · LangServe · LangSmith · OpenAI · Chroma · Tavily · FastAPI