A comprehensive LangGraph project demonstrating multi-node workflows, state management, and Ollama integration.
-
Install Ollama (if not already installed):
- Visit https://ollama.ai
- Download and install for your OS
-
Start Ollama and pull a model:
ollama serve ollama pull llama3.2
-
Install Python dependencies:
cd backend pip install -r requirements.txt -
Run the demo:
python main.py
-
2 Processing Nodes:
input_processor: Analyzes text and counts wordssummarizer: Generates summary and sentiment analysis
-
State Management: TypedDict-based state with 4 fields:
input_text: Original user inputword_count: Calculated by first nodesummary: Generated by second nodesentiment: Generated by second node
- ✅ Configurable Ollama model selection
- ✅ Memory persistence with checkpointing
- ✅ Streaming support for real-time updates
- ✅ Multiple output formats (text, JSON, markdown)
- ✅ Comprehensive logging
- ✅ Error handling
- ✅ CLI interface with arguments
- ✅ Example scripts
from src.graph.workflow import run_workflow
result = run_workflow("Your text here...")
print(result["summary"])
print(result["sentiment"])result = run_workflow(
input_text="Your text...",
model_name="llama3.2"
)from src.graph.workflow import stream_workflow
for update in stream_workflow("Your text..."):
print(update)# Use sample text
python main.py --sample 0
# Custom text
python main.py --text "Your custom text here"
# Different model
python main.py --sample 0 --model llama3.2
# JSON output
python main.py --sample 1 --format json
# Streaming mode
python main.py --sample 0 --streambackend/
├── src/
│ ├── config/
│ │ └── models.py # Model configuration & initialization
│ ├── graph/
│ │ ├── state.py # State schema (TypedDict)
│ │ ├── nodes.py # Node implementations
│ │ └── workflow.py # Graph construction & compilation
│ └── utils/
│ └── helpers.py # Utility functions
├── examples/
│ └── examples.py # Usage examples
├── main.py # CLI entry point
├── requirements.txt
└── README.md
from src.config.models import get_model_from_preset
# Use predefined configurations
model = get_model_from_preset("creative") # High temperature
model = get_model_from_preset("precise") # Low temperature
model = get_model_from_preset("balanced") # Defaultworkflow = create_workflow()
# First conversation
result1 = workflow.invoke(
{"input_text": "First text..."},
{"configurable": {"thread_id": "user-123"}}
)
# Continue same conversation
result2 = workflow.invoke(
{"input_text": "Second text..."},
{"configurable": {"thread_id": "user-123"}}
)from src.graph.nodes import input_processor, summarizer
state = {"input_text": "Your text..."}
state.update(input_processor(state))
state.update(summarizer(state))This workflow implements a text analysis pipeline:
- Input Stage: User provides text
- Processing Stage: Calculate word count and metadata
- Analysis Stage: Generate summary and sentiment
- Output Stage: Return comprehensive results
Perfect for:
- Content analysis
- Document summarization
- Sentiment monitoring
- Text preprocessing pipelines
Create a .env file:
OLLAMA_BASE_URL=http://localhost:11434
DEFAULT_MODEL=llama3.2Edit src/config/models.py to customize:
- Default model name
- Temperature settings
- Context window size
- Sampling parameters
- Python 3.11+
- Ollama running locally
- At least one Ollama model installed
Model not found:
ollama pull llama3.2Connection refused:
ollama serveImport errors:
pip install -r requirements.txtRun the examples script to see all features:
cd examples
python examples.pyThis project is designed to be extensible. Consider adding:
- Additional analysis nodes (keyword extraction, entity recognition)
- Database persistence
- API endpoints
- Frontend interface
- Batch processing
- Advanced error recovery
- Custom reducers for state management
MIT License - feel free to use and modify for your needs.