Skip to content

Commit e3ab561

Browse files
committed
feat(redis): enhance checkpoint handling and add example notebooks
Core changes: - Fix Redis key parsing to handle additional components in _parse_redis_checkpoint_writes_key method - Modify error handling to accept keys with more than 6 components by slicing (parts[:6]) - Update error message to indicate "at least 6 parts" needed rather than "expected 6" Added comprehensive test suites: - Basic key parsing tests (test_key_parsing.py) - Subgraph key parsing tests (test_subgraph_key_parsing.py) - Fix verification tests (test_fix_verification.py) - Semantic search key tests (test_semantic_search_keys.py) - Streaming tests (test_streaming_modes.py, test_streaming.py) Added new example notebooks: - Memory management examples (add-summary-conversation-history, delete-messages, etc.) - Human-in-the-loop examples (breakpoints, edit-graph-state, time-travel, etc.) - Subgraph management notebooks (subgraph-persistence, subgraphs-manage-state) - Agent creation examples with history management and HITL
1 parent e3b902a commit e3ab561

36 files changed

+10997
-78
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,4 @@ pip-selfcheck.json
220220
libs/redis/docs/.Trash*
221221
.python-version
222222
.idea/*
223+
examples/.Trash*

examples/Dockerfile.jupyter

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ RUN useradd -m jupyter
55

66
WORKDIR /home/jupyter/workspace
77

8-
# Copy the library files (only copy the checkpoint-redis directory)
9-
COPY ./libs/checkpoint-redis /home/jupyter/workspace/libs/checkpoint-redis
8+
# Copy notebook files to the workspace
9+
COPY ./ /home/jupyter/workspace/examples/
1010

11-
# Create necessary directories and set permissions
12-
RUN mkdir -p /home/jupyter/workspace/libs/checkpoint-redis/examples && \
13-
chown -R jupyter:jupyter /home/jupyter/workspace
11+
# Set permissions
12+
RUN chown -R jupyter:jupyter /home/jupyter/workspace
1413

1514
# Switch to non-root user
1615
USER jupyter
@@ -21,15 +20,17 @@ ENV PATH="/home/jupyter/venv/bin:$PATH"
2120

2221
# Install dependencies
2322
RUN pip install --no-cache-dir --upgrade pip && \
24-
pip install --no-cache-dir langgraph>=0.3.0 && \
25-
pip install --no-cache-dir -e /home/jupyter/workspace/libs/checkpoint-redis && \
26-
pip install --no-cache-dir jupyter redis>=5.2.1 redisvl>=0.5.1 langchain-openai langchain-anthropic python-ulid
23+
pip install --no-cache-dir "httpx>=0.24.0,<1.0.0" && \
24+
pip install --no-cache-dir "langgraph>=0.3.0" && \
25+
pip install --no-cache-dir "langgraph-checkpoint-redis>=0.0.4" && \
26+
pip install --no-cache-dir jupyter "redis>=5.2.1" "redisvl>=0.5.1" langchain-openai langchain-anthropic python-ulid
27+
# Note: Notebook-specific dependencies will be installed in the notebook cells as needed
2728

2829
# Set the working directory to the examples folder
29-
WORKDIR /home/jupyter/workspace/libs/checkpoint-redis/examples
30+
WORKDIR /home/jupyter/workspace/examples
3031

3132
# Expose Jupyter port
3233
EXPOSE 8888
3334

3435
# Start Jupyter Notebook with checkpoints disabled
35-
CMD ["jupyter", "notebook", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--NotebookApp.token=''", "--NotebookApp.password=''", "--NotebookApp.allow_root=True", "--NotebookApp.disable_check_xsrf=True", "--FileContentsManager.checkpoints_kwargs={'root_dir':'/tmp/checkpoints'}"]
36+
CMD ["jupyter", "notebook", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--ServerApp.token=''", "--ServerApp.password=''", "--ServerApp.allow_root=True", "--NotebookApp.disable_check_xsrf=True", "--FileContentsManager.checkpoints_kwargs={'root_dir':'/tmp/checkpoints'}"]

examples/README.md

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This directory contains Jupyter notebooks demonstrating the usage of Redis with
44

55
## Running Notebooks with Docker
66

7-
To run these notebooks using the local development version of the Redis checkpoint package:
7+
To run these notebooks using Docker (recommended for consistent environment):
88

99
1. Ensure you have Docker and Docker Compose installed on your system.
1010
2. Navigate to this directory (`examples`) in your terminal.
@@ -15,21 +15,57 @@ To run these notebooks using the local development version of the Redis checkpoi
1515
```
1616

1717
4. Look for a URL in the console output that starts with `http://127.0.0.1:8888/tree`. Open this URL in your web browser to access Jupyter Notebook.
18-
5. You can now run the notebooks, which will use the local development version of the Redis checkpoint package.
18+
5. You can now run the notebooks with all dependencies pre-installed.
1919

20-
Note: The first time you run this, it may take a few minutes to build the Docker image.
20+
Note:
21+
- The first time you run this, it may take a few minutes to build the Docker image.
22+
- The Docker setup uses a simplified structure where the examples are self-contained, making it portable and independent of the repository structure.
2123

2224
To stop the Docker containers, use Ctrl+C in the terminal where you ran `docker compose up`, then run:
2325

2426
```bash
2527
docker compose down
2628
```
2729

30+
## Running Notebooks Locally
31+
32+
If you prefer to run these notebooks locally without Docker:
33+
34+
1. Make sure you have Redis running locally or accessible from your machine.
35+
2. Install the required dependencies:
36+
37+
```bash
38+
pip install langgraph-checkpoint-redis
39+
pip install langgraph>=0.3.0
40+
pip install jupyter redis>=5.2.1 redisvl>=0.5.1
41+
pip install langchain-openai langchain-anthropic
42+
pip install python-ulid "httpx>=0.24.0,<1.0.0"
43+
44+
# Some notebooks may require additional packages, which will be installed
45+
# within the notebooks themselves when needed
46+
```
47+
48+
3. Set the appropriate Redis connection string in the notebooks.
49+
4. Launch Jupyter Notebook:
50+
51+
```bash
52+
jupyter notebook
53+
```
54+
55+
5. Navigate to the notebook you want to run and open it.
56+
2857
## Notebook Contents
2958

30-
- `persistence_redis.ipynb`: Demonstrates the usage of `RedisSaver` and `AsyncRedisSaver` checkpoint savers with LangGraph.
59+
- `persistence-functional.ipynb`: Demonstrates the usage of `RedisSaver` and functional persistence patterns with LangGraph.
3160
- `create-react-agent-memory.ipynb`: Shows how to create an agent with persistent memory using Redis.
3261
- `cross-thread-persistence.ipynb`: Demonstrates cross-thread persistence capabilities with Redis.
33-
- `persistence-functional.ipynb`: Shows functional persistence patterns with Redis.
62+
- `cross-thread-persistence-functional.ipynb`: Shows functional cross-thread persistence patterns with Redis.
63+
- `create-react-agent-manage-message-history.ipynb`: Shows how to manage conversation history in a ReAct agent with Redis.
64+
- `subgraph-persistence.ipynb`: Demonstrates persistence with subgraphs using Redis.
65+
- `subgraphs-manage-state.ipynb`: Shows how to manage state in subgraphs with Redis.
66+
- `create-react-agent-hitl.ipynb`: Demonstrates human-in-the-loop (HITL) capabilities with Redis.
67+
- `human_in_the_loop/*.ipynb`: Demonstrates various human-in-the-loop interaction patterns with LangGraph and Redis.
68+
69+
All notebooks have been updated to use the Redis implementation instead of memory implementation, showcasing the proper usage of Redis integration with LangGraph.
3470

3571
These notebooks are designed to work both within this Docker environment (using local package builds) and standalone (using installed packages via pip).

0 commit comments

Comments
 (0)