A comprehensive, hands-on tutorial that teaches all LangGraph capabilities through a progressive project that evolves from a basic local LLM-powered assistant to a sophisticated AI research system with human-in-the-loop capabilities, memory, and advanced orchestration.
This tutorial builds a Research Assistant AI that can:
- Answer questions using local Ollama LLMs and knowledge bases
- Maintain conversation memory and context
- Handle complex multi-step research tasks
- Collaborate with humans through approval workflows
- Recover from errors gracefully
- Scale across multiple agents and tools
- Run completely offline and private - no external API calls required
Key Learning Philosophy: Each chapter builds upon the previous one, enhancing the same codebase rather than starting from scratch. By the end, you'll have a production-ready AI system showcasing all LangGraph capabilities.
What you'll build: Basic Q&A bot with local Ollama LLM and knowledge base LangGraph concepts: Nodes, edges, state management, basic graphs, local LLM integration
# Simple flow: Question โ Knowledge Search โ Local LLM Query โ Format Answer
User Question โ Search Knowledge Base โ Query Ollama โ Format ResponseFeatures introduced:
- Basic
StateGraphcreation - Simple node functions
- Linear workflow execution
- State passing between nodes
- Local LLM integration with Ollama
- Knowledge base search and context provision
- Privacy-first AI development
Enhancement: Smart routing based on question type LangGraph concepts: Conditional edges, decision nodes
# Enhanced flow with routing
Question โ Classify Intent โ [Local LLM | Knowledge Base | Web Search*] โ ResponseNew features:
- Conditional routing with
add_conditional_edges() - Intent classification node
- Multiple execution paths
- Dynamic workflow decisions
- *Optional web search integration for comparison
Enhancement: Multiple LLM models and document processing LangGraph concepts: Tool calling, error handling, model switching
# Multi-model integration
Question โ Route โ [Ollama Models | Document Analysis | Optional APIs] โ Synthesize โ ResponseNew features:
- Multiple Ollama model integrations (different sizes/specializations)
- Document upload and processing with local models
- Tool error handling and fallbacks
- Result synthesis from multiple local sources
- Optional external API integration for comparison
Enhancement: Conversation history and contextual responses LangGraph concepts: Persistent state, memory management
# Context-aware conversations
[Previous Context] โ Question โ Enhanced Routing โ Tools โ Context Update โ ResponseNew features:
- Conversation memory implementation
- Context-aware question processing
- State persistence between sessions
- Follow-up question handling
Enhancement: Human approval for sensitive operations LangGraph concepts: Interrupts, human feedback, approval workflows
# Human collaboration workflow
Question โ Plan โ [Auto Execute | Request Approval] โ Execute โ Human Review โ FinalizeNew features:
- Human approval nodes with
interrupt_before - Approval workflow implementation
- Human feedback integration
- Sensitive operation detection
Enhancement: Specialized agents working together LangGraph concepts: Sub-graphs, agent delegation, complex orchestration
# Multi-agent system
Main Agent โ Task Analysis โ [Research Agent | Analysis Agent | Writing Agent] โ Coordination โ Final OutputNew features:
- Multiple specialized agents
- Sub-graph implementation
- Agent-to-agent communication
- Task delegation and coordination
Enhancement: Comprehensive error handling and self-recovery LangGraph concepts: Error nodes, retry logic, fallback strategies
# Robust error handling
Any Node โ [Success | Error] โ [Continue | Retry | Fallback | Human Escalation] โ RecoveryNew features:
- Comprehensive error handling
- Automatic retry mechanisms
- Fallback strategies
- Human escalation for critical failures
Enhancement: Real-time streaming responses and live updates LangGraph concepts: Streaming execution, real-time updates
# Streaming workflow
Question โ Stream Planning โ Stream Execution โ Live Updates โ Final ResponseNew features:
- Streaming response generation
- Real-time progress updates
- Live workflow visualization
- Asynchronous processing
Enhancement: Sophisticated state handling and data transformation LangGraph concepts: Custom state classes, state transformations, parallel processing
# Complex state management
Multi-Input โ Parallel Processing โ State Merging โ Complex Transformations โ OutputNew features:
- Custom state classes
- Parallel node execution
- State transformation functions
- Complex data flow patterns
Enhancement: Production-ready deployment with monitoring LangGraph concepts: Deployment patterns, monitoring, scaling
# Production system
Load Balancer โ Multiple Graph Instances โ Monitoring โ Logging โ AnalyticsNew features:
- Docker containerization
- Kubernetes deployment manifests
- Monitoring and observability
- Performance optimization
- Scaling strategies
# Python 3.9+
python --version
# Install Ollama (visit https://ollama.ai for your platform)
# macOS/Linux:
curl -fsSL https://ollama.ai/install.sh | sh
# Install Python dependencies
pip install langgraph langchain-ollama ollama python-dotenv streamlit# Clone and setup
git clone <your-repo>
cd langgraph-mastery
# Start Ollama server
ollama serve
# Pull the model (in another terminal)
ollama pull llama3.2:latest
# Setup environment
cp env.example .env
# Defaults should work, but you can customize Ollama settings
# Install all dependencies
pip install -r requirements.txt# Quick setup verification
python setup_chapter1.py
# Start with the basics
python chapter_01_foundation/basic_workflow.py
# Or run the demo
python chapter_01_foundation/demo.pylanggraph-mastery/
โโโ README.md # This file
โโโ requirements.txt # Python dependencies
โโโ env.example # Environment variables template
โโโ OLLAMA_SETUP.md # Comprehensive Ollama setup guide
โโโ docker-compose.yml # Local development setup
โโโ kubernetes/ # K8s deployment manifests
โ โโโ namespace.yaml
โ โโโ deployment.yaml
โ โโโ service.yaml
โโโ setup_chapter1.py # Chapter 1 setup verification script
โโโ app.py # Main Streamlit application
โโโ shared/ # Shared utilities and components
โ โโโ __init__.py
โ โโโ state.py # State management classes
โ โโโ tools.py # Tool implementations (Ollama, Knowledge Base)
โ โโโ agents.py # Agent definitions
โ โโโ utils.py # Helper functions
โโโ chapter_01_foundation/
โ โโโ README.md # Chapter-specific instructions
โ โโโ basic_workflow.py # Simple linear workflow
โ โโโ state_management.py # Basic state handling
โ โโโ tests/ # Unit tests
โโโ chapter_02_conditional/
โ โโโ README.md
โ โโโ conditional_routing.py # Enhanced workflow with routing
โ โโโ intent_classifier.py # Question classification
โ โโโ tests/
โโโ chapter_03_tools/
โ โโโ README.md
โ โโโ multi_tool_integration.py # Multiple tool usage
โ โโโ tool_implementations.py # Custom tools
โ โโโ tests/
โโโ chapter_04_memory/
โ โโโ README.md
โ โโโ persistent_memory.py # Conversation memory
โ โโโ context_management.py # Context handling
โ โโโ tests/
โโโ chapter_05_human_loop/
โ โโโ README.md
โ โโโ approval_workflow.py # Human-in-the-loop
โ โโโ human_interface.py # Human interaction
โ โโโ tests/
โโโ chapter_06_multi_agent/
โ โโโ README.md
โ โโโ agent_orchestration.py # Multi-agent coordination
โ โโโ specialized_agents.py # Individual agents
โ โโโ tests/
โโโ chapter_07_error_handling/
โ โโโ README.md
โ โโโ robust_workflows.py # Error handling
โ โโโ recovery_strategies.py # Recovery mechanisms
โ โโโ tests/
โโโ chapter_08_streaming/
โ โโโ README.md
โ โโโ streaming_responses.py # Real-time streaming
โ โโโ live_updates.py # Progress tracking
โ โโโ tests/
โโโ chapter_09_advanced_state/
โ โโโ README.md
โ โโโ complex_state.py # Advanced state management
โ โโโ parallel_processing.py # Concurrent execution
โ โโโ tests/
โโโ chapter_10_production/
โโโ README.md
โโโ production_app.py # Production-ready application
โโโ monitoring.py # Observability
โโโ Dockerfile # Container definition
โโโ tests/
Each chapter includes a Streamlit web interface for interactive exploration:
# Run specific chapter
streamlit run app.py --chapter 3
# Compare chapters
streamlit run app.py --compare "1,3,5"
# Full application (Chapter 10)
streamlit run app.py --production# Test individual components
python -m chapter_03.tools.test_ollama_models
# Run workflow with custom input
python -m chapter_05.approval_workflow --input "Research quantum computing applications"
# Performance benchmarking
python -m chapter_10.benchmark --iterations 100
# Ollama model management
ollama list # Show available models
ollama pull llama3.2:3b # Pull different model sizes
ollama rm old-model # Remove unused modelsEach chapter includes comprehensive tests:
# Run all tests
pytest
# Test specific chapter
pytest chapter_03/tests/
# Integration tests
pytest tests/integration/
# Performance tests
pytest tests/performance/ --benchmark-only- Chapter 1: Create basic linear workflow
- Chapter 2: Implement conditional routing
- Chapter 3: Integrate multiple tools
- Chapter 4: Add persistent memory
- Chapter 5: Build human approval system
- Chapter 6: Create multi-agent system
- Chapter 7: Implement error recovery
- Chapter 8: Add streaming capabilities
- Chapter 9: Master advanced state management
- Chapter 10: Deploy production system
By completion, you'll master:
- โ LangGraph fundamentals and architecture
- โ State management and data flow
- โ Conditional logic and routing
- โ Tool integration and API usage
- โ Memory and context management
- โ Human-AI collaboration patterns
- โ Multi-agent orchestration
- โ Error handling and recovery
- โ Streaming and real-time processing
- โ Production deployment and scaling
# Development server with hot reload
streamlit run app.py --server.runOnSave true
# Debug mode
python -m debugpy --listen 5678 --wait-for-client app.py# Build and run locally
docker-compose up --build
# Development with volume mounts
docker-compose -f docker-compose.dev.yml up# Apply namespace and resources
kubectl apply -f kubernetes/
# Port forward for local access
kubectl port-forward service/research-assistant 8501:80
# View logs
kubectl logs -f deployment/research-assistant- Multi-Agent Coordination: Specialized local LLM agents for research, analysis, and writing
- Dynamic Model Selection: AI chooses optimal Ollama models based on task complexity
- Adaptive Workflows: Graphs that modify themselves based on performance
- Human Collaboration: Seamless human-AI teamwork with approval workflows
- Error Recovery: Self-healing systems that recover from local LLM failures
- Performance Optimization: Parallel processing, model caching, and load balancing
- Horizontal Scaling: Multiple Ollama instances with load balancing
- Monitoring Dashboard: Real-time performance and usage analytics
- A/B Testing: Compare different model configurations
- Resource Management: Intelligent model loading/unloading
- Privacy Compliance: Complete local processing for sensitive data
- Audit Logging: Complete interaction history without external dependencies
We welcome contributions! Please see our Contributing Guide for details.
- Follow the established structure in
chapter_XX/ - Ensure backward compatibility with previous chapters
- Include comprehensive tests and documentation
- Update the main application to support the new chapter
- LangChain - Core framework
- Ollama - Local LLM runtime
- Streamlit - Web interface
- Docker - Containerization
- Kubernetes - Orchestration
Complete all chapters and pass the final assessment to earn your LangGraph Mastery Certificate!
- All chapter checkpoints completed โ
- Final project demonstrates all learned concepts โ
- Code quality meets production standards โ
- Successful deployment to Kubernetes โ
Begin your LangGraph mastery journey with local LLMs:
# 1. Start Ollama
ollama serve
# 2. Pull the model (in another terminal)
ollama pull llama3.2:latest
# 3. Verify setup
python setup_chapter1.py
# 4. Start learning!
cd chapter_01_foundation
python basic_workflow.pyHappy Learning! ๐
Why Local LLMs with Ollama?
- โ Complete Privacy: No data sent to external services
- โ Zero API Costs: No per-token charges or rate limits
- โ Offline Capable: Works without internet connection
- โ Full Control: Choose your models and update schedules
- โ Production Ready: Deploy anywhere without external dependencies
- โ Learning Focused: Understand AI systems from the ground up
This project is designed to take you from LangGraph beginner to expert through hands-on, incremental learning with privacy-first local LLMs. Each chapter builds real capabilities while teaching core concepts. By the end, you'll have both deep knowledge and a production-ready AI system that runs completely under your control.