This directory contains examples of implementing parallel processing workflows using LangGraph. These examples demonstrate how to execute multiple independent tasks simultaneously and then combine their results.
File: practice.ipynb
This example demonstrates parallel processing of cricket statistics to calculate various performance metrics for a batsman. The workflow calculates three independent metrics in parallel:
- Strike Rate: (Runs / Balls) * 100
- Balls per Boundary: Total balls / (Fours + Sixes)
- Boundary Percentage: ((Fours4) + (Sixes6)) / Runs * 100
-
State Management: Uses
TypedDictto track:- Runs, balls, fours, sixes
- Calculated metrics (strike rate, balls per boundary, boundary percentage)
- Summary string combining all metrics
-
Parallel Processing:
- Three independent calculation nodes run in parallel
- Results are combined in a summary node
- Demonstrates fan-out/fan-in pattern
File: practice2.ipynb
This example shows a more complex parallel workflow for evaluating essays using multiple criteria simultaneously. The system evaluates an essay on different aspects in parallel:
- Language and Structure
- Content and Argumentation
- Originality and Insight
- Grammar and Style
- Structured Output: Uses Pydantic models for consistent evaluation criteria
- Parallel Evaluation: Multiple evaluators analyze different aspects simultaneously
- Result Aggregation: Combines individual evaluations into a comprehensive review
- Google's Gemini Model: Leverages AI for sophisticated essay analysis
-
Install the required dependencies:
pip install -r requirements.txt
-
For the essay evaluation example, you'll need a Google API key for the Gemini model:
- Obtain an API key from Google AI Studio
- Set it in the notebook or as an environment variable
- Open
practice.ipynb - Modify the initial state with cricket statistics:
initial_state = { "runs": 120, "balls": 100, "fours": 10, "sixes": 3 }
- Run the cells to see parallel processing in action
- Open
practice2.ipynb - Set your Google API key if not using environment variables
- Modify the essay text as needed
- Run the workflow to see parallel evaluation results
- Parallel Execution: Running multiple independent tasks simultaneously
- State Management: Maintaining and updating shared state across parallel nodes
- Fan-out/Fan-in Pattern: Splitting work into parallel tasks and combining results
- Structured Output: Using Pydantic models for consistent data validation
- AI Integration: Leveraging language models for content analysis
- Python 3.8+
- langgraph
- langchain-google-genai (for essay evaluation)
- pydantic
Check out other workflow examples in the parent directory for different LangGraph patterns and use cases, including conditional logic and iterative refinement.