Hands-on examples for building AI agents with LangGraph and Ollama.
This repository contains practical examples demonstrating modern agentic patterns using:
- LangGraph for agent orchestration and state management
- Ollama for local LLM inference
- Python 3.10+ with modern tooling (uv, Jupyter)
All examples run locally - no API keys required! 🚀
agents-hands-on/
├── pyproject.toml # Shared dependencies for all examples
├── uv.lock # Locked dependency versions
├── .venv/ # Shared virtual environment
├── ollama/ # Ollama configuration
│ ├── OLLAMA_API_GUIDE.md
│ ├── ollama.env
│ └── start-ollama.sh
└── agents-examples/ # Agent examples
├── README.md
└── parallel-topic-analyzer/
├── main.py # CLI interface
├── notebooks/ # Jupyter notebooks
│ └── demo.ipynb
├── src/ # Source code
└── README.md
- Python 3.10+
- uv (fast Python package manager)
curl -LsSf https://astral.sh/uv/install.sh | sh - Ollama (local LLM runtime)
# Install from https://ollama.ai # Or with Homebrew brew install ollama
# Clone the repository
git clone https://github.com/JoySnow/agents-hands-on.git
cd agents-hands-on
# Install all dependencies (creates .venv at repo root)
uv sync
# Start Ollama server
ollama serve
# Pull a model (in another terminal)
ollama pull deepseek-r1:1.5b# Activate the environment
source .venv/bin/activate
# Run an example
cd agents-examples/parallel-topic-analyzer
python main.py "Artificial Intelligence"
# Or use uv run without activation
uv run python agents-examples/parallel-topic-analyzer/main.py "Artificial Intelligence"# Start Jupyter (from repo root)
source .venv/bin/activate
jupyter notebook
# Navigate to agents-examples/parallel-topic-analyzer/notebooks/demo.ipynbLocation: agents-examples/parallel-topic-analyzer/
Demonstrates LangGraph's parallel execution with three concurrent LLM tasks.
Features:
- ✅ Parallel task execution (~3x speedup vs sequential)
- ✅ LangGraph StateGraph architecture
- ✅ Clean modular structure
- ✅ CLI and Jupyter notebook interfaces
Quick Run:
cd agents-examples/parallel-topic-analyzer
uv run python main.py "Quantum Computing" --verboseLearn More: See agents-examples/parallel-topic-analyzer/README.md
This repository uses a single shared virtual environment at the root level:
# Install/update dependencies
uv sync
# Add a new dependency
uv add package-name
# Add a dev dependency
uv add --dev package-name
# Activate the environment
source .venv/bin/activate- Create a directory under
agents-examples/ - Add your code (scripts and/or notebooks)
- Update
agents-examples/README.md - No separate
pyproject.tomlneeded - use the shared environment
# Install dev dependencies
uv sync --extra dev
# Run tests (when available)
pytest- Single source of truth for dependencies
- Faster setup - install once, use everywhere
- Consistency - all examples use the same package versions
- Easy maintenance - update dependencies in one place
Each example should include:
main.py- CLI entry pointnotebooks/- Interactive Jupyter notebookssrc/- Source code modulesREADME.md- Example-specific documentationEXAMPLES.md- Real usage examples with outputs
The ollama/ directory contains configuration for running Ollama:
# Start with custom configuration
cd ollama
source ollama.env
ollama serveKey Settings (ollama.env):
OLLAMA_HOST=0.0.0.0:11434- Listen on all interfacesOLLAMA_NUM_PARALLEL=4- Handle 4 concurrent requestsOLLAMA_DEBUG=1- Enable debug logging
# List installed models
ollama list
# Pull recommended models
ollama pull deepseek-r1:1.5b # Fast, good reasoning
ollama pull deepseek-r1:8b # Better quality
ollama pull granite3.2:2b # Very fast, smaller# Register the kernel
uv run python -m ipykernel install --user --name=agents-hands-on
# Start Jupyter
jupyter notebook- Use the
agents-hands-onkernel - Import from example
src/directories - Include markdown explanations
- Show both code and output
# Check if Ollama is running
curl http://localhost:11434/api/version
# Should return: {"version":"0.x.x"}# List available models
ollama list
# Pull missing model
ollama pull deepseek-r1:1.5b# Remove and recreate
rm -rf .venv
uv sync# Ensure kernel is registered
uv run python -m ipykernel install --user --name=agents-hands-on
# Restart Jupyter and select "agents-hands-on" kernelContributions are welcome! Please:
- Follow the existing code structure
- Add tests for new examples
- Update documentation
- Include both
.pyand.ipynbversions when applicable - Test with the shared environment
- LangGraph Documentation: https://langchain-ai.github.io/langgraph/
- Ollama Documentation: https://ollama.ai/docs
- LangChain Ollama Integration: https://python.langchain.com/docs/integrations/chat/ollama
MIT License - see LICENSE file for details
Built with: