LangSmith Masterclass is a comprehensive, hands-on repository designed to teach and demonstrate advanced concepts in building LLM-powered applications using LangChain, LangSmith, and LangGraph. The project covers:
- Simple LLM prompt chaining
- Sequential multi-step chains
- Retrieval-Augmented Generation (RAG) pipelines with PDF data
- Custom agents with web search and API tools
- Graph-based workflows for structured evaluation
Each script is crafted for clarity and experimentation, making this repo ideal for learners, researchers, and developers who want to master modern AI application development.
- Project Structure
- Setup Instructions
- Environment Variables
- Detailed File Explanations
- Requirements
- Usage Guide
- Troubleshooting
- References
langsmith-masterclass/
├── 1_simple_llm_call.py
├── 2_sequential_chain.py
├── 3_rag_v1.py
├── 3_rag_v2.py
├── 3_rag_v3.py
├── 3_rag_v4.py
├── 4_agent.py
├── 5_langgraph.py
├── islr.pdf
├── requirements.txt
├── myvenv/
│ └── ... (virtual environment files)
└── .gitignore
- 1_simple_llm_call.py: Basic LLM prompt chaining example.
- 2_sequential_chain.py: Sequential multi-step LLM chain for report generation and summarization.
- 3_rag_v1.py - 3_rag_v4.py: Progressive Retrieval-Augmented Generation (RAG) pipelines using PDFs, embeddings, and FAISS vector stores. Each version adds more features (tracing, caching, modularity).
- 4_agent.py: Custom agent using LangChain's ReAct framework, with web search and weather data tools.
- 5_langgraph.py: Advanced graph-based workflow using LangGraph for structured evaluation and feedback.
- islr.pdf: Sample PDF for RAG demos.
- requirements.txt: All required Python packages.
- myvenv/: Local Python virtual environment.
- .gitignore: Standard ignores for Python, virtualenv, Jupyter, and VS Code files.
-
Clone the repository
git clone <repo-url> cd langsmith-masterclass
-
Create and activate a virtual environment
python -m venv myvenv .\myvenv\Scripts\Activate.ps1
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
- Create a
.env
file in the root directory with your API keys:OPENAI_API_KEY=your_openai_key LANGCHAIN_API_KEY=your_langchain_key LANGCHAIN_TRACING_V2=true LANGCHAIN_PROJECT=your_project_name
- Create a
OPENAI_API_KEY
: Required for OpenAI LLM and embedding models.LANGCHAIN_API_KEY
: Required for LangSmith tracing and analytics.LANGCHAIN_TRACING_V2
: Enables advanced tracing (recommended:true
).LANGCHAIN_PROJECT
: Project name for LangSmith dashboard.
- Loads environment variables.
- Sets up a simple prompt and runs a question through an OpenAI chat model.
- Demonstrates a multi-step chain: generates a report, then summarizes it.
- Uses two different LLM models and prompt templates.
- Shows how to pass config metadata for tracing.
- Loads a PDF, splits it into chunks, embeds with OpenAI, and builds a FAISS vector store.
- Runs a RAG pipeline to answer questions from the PDF context.
- Adds LangSmith tracing to each pipeline step using
@traceable
decorators. - Shows how to organize and trace modular pipeline functions.
- Further modularizes the RAG pipeline and traces parent setup functions.
- Demonstrates advanced tracing and pipeline composition.
- Adds caching, fingerprinting, and index management for efficient RAG workflows.
- Uses
Path
,hashlib
, and JSON for robust file handling.
- Implements a ReAct agent with custom tools (web search, weather API).
- Uses LangChain Hub for prompt templates.
- Demonstrates agent creation, tool registration, and invocation.
- Builds a graph-based workflow for essay evaluation using LangGraph.
- Defines structured schemas and feedback models.
- Shows how to use state graphs and custom evaluation logic.
All dependencies are listed in requirements.txt
. Key packages include:
langchain
,langchain-openai
,langchain-community
,langsmith
,langgraph
faiss-cpu
,pypdf
,python-dotenv
,openai
,pandas
,streamlit
, etc.- See the full list in
requirements.txt
for exact versions.
- Run any script directly after activating the virtual environment:
python 1_simple_llm_call.py python 2_sequential_chain.py python 3_rag_v1.py # ... and so on
- For RAG scripts, ensure
islr.pdf
is present in the root directory. - For agent scripts, internet access is required for API calls.
- For LangSmith tracing, ensure your API keys and project name are set in
.env
.
- Missing packages: Run
pip install -r requirements.txt
again. - API errors: Check your
.env
file for correct keys. - PDF not found: Ensure
islr.pdf
exists in the root directory. - Virtual environment issues: Recreate with
python -m venv myvenv
. - Windows activation: Use
Activate.ps1
for PowerShell.
For questions or contributions, please open an issue or pull request.