Skip to content
Open
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
60 changes: 60 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
venv/
ENV/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Jupyter Notebook
.ipynb_checkpoints
*.ipynb_checkpoints/

# Poetry
poetry.lock

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db

# Git
.git/
.gitignore

# Docker
Dockerfile
.dockerignore

# Documentation
*.md
!README.md

# Other
.pytest_cache/
.coverage
htmlcov/

43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Use Python 3.11 slim image as base
FROM python:3.11-slim

# Set working directory
WORKDIR /app

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1

# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
&& rm -rf /var/lib/apt/lists/*

# Install Poetry
RUN pip install poetry==1.7.1

# Configure poetry: Don't create virtual env, install dependencies to system
RUN poetry config virtualenvs.create false

# Copy poetry files
COPY pyproject.toml poetry.lock* ./

# Install dependencies
RUN poetry install --no-interaction --no-ansi --no-root

# Copy the rest of the application
COPY . .

# Install the package itself
RUN poetry install --no-interaction --no-ansi

# Expose Jupyter port
EXPOSE 8888

# Default command: start Jupyter Lab
CMD ["jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--allow-root", "--NotebookApp.token=''", "--NotebookApp.password=''"]

96 changes: 92 additions & 4 deletions SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ Each notebook can be opened directly in Google Colab by clicking on the "Open in

This is the quickest way to get started as it requires no local setup.

### Option 2: Local Jupyter Server
### Option 2: Local Setup

To run the notebooks locally, follow these steps:
You can run the notebooks locally using either a traditional Python virtual environment or Docker. Choose the method that best suits your needs.

#### Option 2.1: Local Jupyter Server with Virtual Environment

To run the notebooks locally with a Python virtual environment, follow these steps:

1. **Clone the repository**
```bash
Expand All @@ -44,6 +48,90 @@ To run the notebooks locally, follow these steps:
jupyter notebook
```

5. **Navigate to the `notebooks` directory** in the Jupyter interface and select the notebook you want to run.
5. **Navigate to the chapter directories** in the Jupyter interface and select the notebook you want to run.

**Note:** Some notebooks may require additional dependencies or environment variables. Check the notebook header for specific requirements.

#### Option 2.2: Local Jupyter Server with Docker (Recommended)

This option uses Docker and Poetry for dependency management, providing a consistent environment across all platforms. **All dependencies are pre-installed**, so you won't need to run installation cells (`!pip install`) in the notebooks.

**Prerequisites:**
- Docker and Docker Compose installed on your system
- Git (to clone the repository)

**Setup Steps:**

1. **Clone the repository**
```bash
git clone https://github.com/PacktPublishing/Building-Agentic-AI-Systems.git agentic-systems
cd agentic-systems
```

2. **Build and start the Docker container**
```bash
docker-compose up -d
```

This command will:
- Build a Docker image with Python 3.11
- Install all dependencies using Poetry
- Start Jupyter Lab on port 8888

3. **Access Jupyter Lab**

Open your browser and navigate to:
```
http://localhost:8888/lab
```

No password or token is required (configured for development).

4. **Working with notebooks**

All notebooks are available in their respective chapter directories. Any changes you make are automatically saved to your local filesystem.

**Useful Docker Commands:**

```bash
# View Jupyter logs
docker-compose logs -f jupyter

# Stop Jupyter
docker-compose down

# Restart Jupyter
docker-compose restart

# Rebuild the image (after updating dependencies)
docker-compose build
```

**Advantages of Docker Setup:**
- Consistent environment across all platforms (macOS, Linux, Windows)
- All dependencies pre-installed via Poetry
- No need to run `!pip install` cells in notebooks
- Isolated environment that doesn't affect your system Python
- Easy to reset or rebuild if needed
- Includes all frameworks: OpenAI, CrewAI, LangChain, LangGraph, AutoGen, PyTorch, etc.

**Managing Dependencies:**

Dependencies are managed with Poetry via `pyproject.toml`. To add new packages:

```bash
# Enter the running container
docker-compose exec jupyter bash

# Add a new package
poetry add package-name

# Exit the container
exit

# Rebuild to persist changes
docker-compose build
```


Note: Some notebooks may require additional dependencies or environment variables. Check the notebook header for specific requirements.
**Note:** Some notebooks in Chapter 7 use `langmem` which is installed from GitHub. If you encounter issues, you can install it manually in the container with `poetry add git+https://github.com/langchain-ai/langmem.git`.
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3.8'

services:
jupyter:
build:
context: .
dockerfile: Dockerfile
container_name: building-agentic-ai-systems
ports:
- "8888:8888"
volumes:
- .:/app
- jupyter-data:/root/.jupyter
environment:
- JUPYTER_ENABLE_LAB=yes
restart: unless-stopped

volumes:
jupyter-data:

57 changes: 57 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[tool.poetry]
name = "building-agentic-ai-systems"
version = "0.1.0"
description = "Building Agentic AI Systems - Code repository with examples and implementations"
authors = ["Anjanava Biswas", "Wrick Talukdar", "Mario Navarrete <mario.np@live.com>"]
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.10,<=3.13"
# Core dependencies
faker = "^20.0.0"
jupyter = "^1.0.0"
ipywidgets = "^8.1.0"

# OpenAI and LLM frameworks
openai = "^1.0.0"
langchain-openai = "^0.3.1"
crewai = "^0.80.0"

# Agent frameworks
langgraph = "^0.6.0"
autogen-agentchat = "^0.4.2"
autogen-ext = {extras = ["openai"], version = "^0.4.2"}

# Memory management
# Note: langmem may need to be installed manually if Git source fails
# Try: pip install langmem or poetry add git+https://github.com/langchain-ai/langmem.git
langmem = {git = "https://github.com/langchain-ai/langmem.git", branch = "main"}
# pysqlite3-binary removed - not available for all platforms, install manually if needed

# Deep learning and XAI
torch = {version = "^2.0.0", optional = true}
transformers = "^4.35.0"
captum = {version = "^0.6.0", optional = true}

# Visualization
matplotlib = "^3.8.0"
seaborn = "^0.13.0"

# Data handling
pydantic = "^2.5.0"

[tool.poetry.extras]
torch = ["torch", "captum"]
memory = ["langmem"]

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
black = "^23.11.0"
flake8 = "^6.1.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]