Skip to content

Bsb/new notebooks fix key issues #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,4 @@ pip-selfcheck.json
libs/redis/docs/.Trash*
.python-version
.idea/*
examples/.Trash*
21 changes: 11 additions & 10 deletions examples/Dockerfile.jupyter
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ RUN useradd -m jupyter

WORKDIR /home/jupyter/workspace

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

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

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

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

# Set the working directory to the examples folder
WORKDIR /home/jupyter/workspace/libs/checkpoint-redis/examples
WORKDIR /home/jupyter/workspace/examples

# Expose Jupyter port
EXPOSE 8888

# Start Jupyter Notebook with checkpoints disabled
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'}"]
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'}"]
46 changes: 41 additions & 5 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This directory contains Jupyter notebooks demonstrating the usage of Redis with

## Running Notebooks with Docker

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

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

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.
5. You can now run the notebooks, which will use the local development version of the Redis checkpoint package.
5. You can now run the notebooks with all dependencies pre-installed.

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

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

```bash
docker compose down
```

## Running Notebooks Locally

If you prefer to run these notebooks locally without Docker:

1. Make sure you have Redis running locally or accessible from your machine.
2. Install the required dependencies:

```bash
pip install langgraph-checkpoint-redis
pip install langgraph>=0.3.0
pip install jupyter redis>=5.2.1 redisvl>=0.5.1
pip install langchain-openai langchain-anthropic
pip install python-ulid "httpx>=0.24.0,<1.0.0"

# Some notebooks may require additional packages, which will be installed
# within the notebooks themselves when needed
```

3. Set the appropriate Redis connection string in the notebooks.
4. Launch Jupyter Notebook:

```bash
jupyter notebook
```

5. Navigate to the notebook you want to run and open it.

## Notebook Contents

- `persistence_redis.ipynb`: Demonstrates the usage of `RedisSaver` and `AsyncRedisSaver` checkpoint savers with LangGraph.
- `persistence-functional.ipynb`: Demonstrates the usage of `RedisSaver` and functional persistence patterns with LangGraph.
- `create-react-agent-memory.ipynb`: Shows how to create an agent with persistent memory using Redis.
- `cross-thread-persistence.ipynb`: Demonstrates cross-thread persistence capabilities with Redis.
- `persistence-functional.ipynb`: Shows functional persistence patterns with Redis.
- `cross-thread-persistence-functional.ipynb`: Shows functional cross-thread persistence patterns with Redis.
- `create-react-agent-manage-message-history.ipynb`: Shows how to manage conversation history in a ReAct agent with Redis.
- `subgraph-persistence.ipynb`: Demonstrates persistence with subgraphs using Redis.
- `subgraphs-manage-state.ipynb`: Shows how to manage state in subgraphs with Redis.
- `create-react-agent-hitl.ipynb`: Demonstrates human-in-the-loop (HITL) capabilities with Redis.
- `human_in_the_loop/*.ipynb`: Demonstrates various human-in-the-loop interaction patterns with LangGraph and Redis.

All notebooks have been updated to use the Redis implementation instead of memory implementation, showcasing the proper usage of Redis integration with LangGraph.

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