https://github.com/tdiprima/langchain-lab
langchain, langgraph, langsmith
https://github.com/tdiprima/langchain-lab
langchain langgraph langsmith
Last synced: about 2 months ago
JSON representation
langchain, langgraph, langsmith
- Host: GitHub
- URL: https://github.com/tdiprima/langchain-lab
- Owner: tdiprima
- License: mit
- Created: 2025-03-13T15:19:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-13T16:14:57.000Z (over 1 year ago)
- Last Synced: 2025-03-13T16:29:29.073Z (over 1 year ago)
- Topics: langchain, langgraph, langsmith
- Language: Python
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LangChain Lab
A hands-on sandbox for exploring LangChain, LangGraph, and LangSmith — covering chains, agents, RAG, memory, tools, and stateful graph workflows through runnable examples and tutorials.
## The Learning Curve Is Steep
The LangChain ecosystem spans multiple libraries (LangChain, LangGraph, LangSmith), each with distinct abstractions and use cases. Documentation is dense, API patterns shift between versions, and it's not obvious where to start or how the pieces fit together — especially when you're trying to build something real, not just follow a toy example.
## Working Code You Can Actually Run
This repo is organized by library, with each module focused on a single concept. Every script is self-contained, pulls credentials from environment variables, and demonstrates one clear pattern. Tutorials include inline documentation that explains the *why*, not just the *what*. The goal is to build genuine intuition by running and modifying real examples.
## Concrete Example
A multi-step medical diagnosis agent (`LangChain/diagnose.py`) that:
1. Retrieves clinical guidelines via FAISS vector search
2. Queries a symptom database through a custom tool
3. Combines both into a structured hypothesis using GPT-4
```python
# Run the diagnosis agent
export OPENAI_API_KEY=your_key_here
python LangChain/diagnose.py
```
## Usage
**Prerequisites**
- Python 3.10+
- API keys for the providers you want to use (OpenAI, Anthropic, Ollama for local)
**Install dependencies**
```bash
pip install -r requirements.txt
```
**Set environment variables**
```bash
export OPENAI_API_KEY=your_openai_key
export ANTHROPIC_API_KEY=your_anthropic_key # optional
export LANGSMITH_API_KEY=your_langsmith_key # optional, for tracing
export SERPAPI_API_KEY=your_serpapi_key # optional, for web search
```
**Run any example directly**
```bash
# Core LangChain concepts
python LangChain/Tutorial/chains_example.py # LCEL pipe operator and RunnableSequence
python LangChain/Tutorial/agents_example.py # LLM math agent with tools
python LangChain/Tutorial/memory_example.py # Conversation memory
python LangChain/chat_with_memory.py # Persistent chat history across sessions
# Real-world agents
python LangChain/spy_agent_rag.py # RAG with FAISS and RetrievalQA
python LangChain/diagnose.py # Clinical symptom analysis with RAG + tools
python LangChain/Tutorial1/web_search_agent.py # Web search agent via Tavily
# LangGraph stateful workflows
python LangGraph/chatgraph.py # Intent-aware chat router
python LangGraph/mathgraph.py # Multi-step math reasoning graph
python LangGraph/calculator.py # Minimal graph with tool use
# LangSmith tracing
python LangSmith/hello_langsmith.py # Instrument a chain with tracing
```
## Project Structure
```
langchain-lab/
├── LangChain/
│ ├── Tutorial/ # Foundational concepts: chains, memory, agents, tools, models
│ ├── Tutorial1/ # Intermediate patterns: web search, task processing, RAG
│ └── *.py # Applied examples: medical advisor, RAG, diagnosis agent
├── LangGraph/ # Stateful graph workflows with StateGraph and branching logic
├── LangSmith/ # Tracing, debugging, and evaluation instrumentation
├── docs/ # Concept notes and framework comparisons
└── requirements.txt
```
## License
This project is licensed under a modified MIT License. See [LICENSE](LICENSE) for details.