This repository contains example scripts demonstrating various features of LangGraph.
It is recommended to use uv for managing dependencies and running the scripts.
-
Install
uvif you haven't already: https://github.com/astral-sh/uv#installation -
Create a virtual environment (optional but recommended):
uv venv source .venv/bin/activate -
Install required packages (check individual script requirements):
uv pip install langgraph typing_extensions # Base packages uv pip install pyppeteer nest_asyncio # For PNG visualization # Install pyppeteer browser dependencies if needed # playwright install --with-deps # Only needed if using playwright backend
Purpose: Demonstrates how to define and execute both a linear and a parallel workflow using LangGraph.
Functionality:
- Defines Nodes: Creates simple placeholder functions (
search_web,search_vector_db,aggregate_results) representing tasks. - Builds Linear Graph: Constructs a graph where nodes execute sequentially:
START->search_web->search_vector_db->aggregate_results->END. - Builds Parallel Graph: Constructs a graph where
search_webandsearch_vector_dbexecute in parallel afterSTART, with both feeding intoaggregate_resultsbeforeEND. - Visualizes Graphs: Generates PNG images (
linear_graph.png,parallel_graph.png) visualizing the structure of both graphs usingdraw_mermaid_png. This requirespyppeteerand its Chromium dependency. - Invokes Graphs: Runs both the linear and parallel graphs, printing messages to the console indicating which node is executing.
Dependencies:
langgraphtyping_extensionspyppeteer(for visualization)nest_asyncio(often needed withpyppeteer)
To Run:
# Ensure pyppeteer's browser is downloaded (happens automatically on first run)
uv run python parallel-execution.pyOutput:
- Console output showing the execution flow of nodes for both graphs.
linear_graph.png: Visualization of the sequential workflow.parallel_graph.png: Visualization of the parallel workflow.