Skip to content

EconoBen/langgraph-redis-workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Practical AI Agent Architecture: Memory Systems and Semantic Caching

Addressing the AI Implementation Crisis

"Nearly half of Fortune 500 executives believe artificial intelligence is actively damaging their organizations... Business leaders are making a category error, treating AI transformation like previous technology rollouts and delegating it to IT departments."

β€” May Habib, CEO, Writer AI | TED AI Conference 2024

Workshop Duration: 60 minutes | Level: Intermediate | Last Updated: January 2025

The Problem

Billions of dollars are being spent on AI initiatives that failβ€”not because the technology is flawed, but because organizations fundamentally misunderstand how to implement AI systems. The most common error: treating AI agents as stateless services rather than stateful cognitive systems.

This workshop demonstrates foundational patterns for building AI agents that actually work.

About Workhelix

At Workhelix, our mission is understanding what makes workers more productiveβ€”beyond the hypeβ€”and empowering organizations to leverage that understanding. This workshop represents one small step toward equipping leadership and employees to use AI correctly: implementing memory systems and cost optimization patterns that enable measurable productivity gains.

Focus: Implementation patterns that deliver results, not promises that don't.

Learning Objectives

By the end of this workshop, you will have implemented:

  1. Stateful agent architecture with LangGraph checkpointers and stores for memory persistence
  2. Memory type classification applying semantic, episodic, and procedural memory patterns
  3. Semantic caching system using Redis to reduce LLM API costs and improve latency
  4. Quantitative measurement framework for tracking cost optimization and productivity impact

Theoretical Foundation

This workshop provides rigorous theoretical grounding in:

  • LangGraph graph-based orchestration for stateful multi-step reasoning
  • Memory architecture based on Von Neumann and cognitive science principles
  • Semantic caching theory including similarity metrics and cost economics
  • Production patterns for persistence, scaling, and observability

All concepts demonstrated through hands-on Python implementation.

What You'll Build

  1. Memory-Enabled Agent - Chatbot with semantic, episodic, and procedural memory
  2. Cached Agent System - Multi-step workflow with Redis LangCache integration
  3. Cost Tracking Dashboard - Metrics to measure optimization impact

πŸš€ Quick Start

Prerequisites

# Clone the repository
git clone https://github.com/EconoBen/langgraph-redis-workshop.git
cd langgraph-redis-workshop

# Start Redis with Docker
docker-compose up -d

# Create virtual environment (using uv recommended)
uv venv --python python3.12
source .venv/bin/activate

# Install dependencies
uv pip install -r requirements.txt

# Copy and configure environment variables
cp .env.example .env
# Edit .env with your API keys (ANTHROPIC_API_KEY or OPENAI_API_KEY)

Start the Workshop

# Start Jupyter
jupyter notebook

# Open notebooks in order:
# 1. notebooks/01_memory_implementation.ipynb
# 2. notebooks/02_redis_caching.ipynb
# 3. notebooks/03_cost_optimization.ipynb

See SETUP.md for detailed setup instructions.

πŸ“‹ Prerequisites

Required Knowledge

  • Python 3.10+: Intermediate proficiency with Python programming
  • LLMs & APIs: Basic understanding of large language models and API usage
  • REST APIs: Familiarity with making HTTP requests

Required Software

  • Python 3.10+ with pip or uv
  • Docker (for local Redis container)
  • Jupyter notebook environment

Required Accounts (Free Tier OK)

No Prior Experience Required

  • LangGraph
  • Redis
  • Agent frameworks

πŸ“– Workshop Materials

πŸ“Š Slides

πŸ’» Notebooks

Located in notebooks/:

  1. 01_memory_implementation.ipynb - Implement short-term and long-term memory
  2. 02_redis_caching.ipynb - Add semantic caching with Redis
  3. 03_cost_optimization.ipynb - Measure and optimize costs

Solutions available in notebooks/solutions/

πŸ”¨ Code Examples

Located in src/ and examples/:

πŸ“š Documentation

Located in docs/:

πŸ—“οΈ Workshop Schedule (60 minutes)

Time Section Format
0-5 min Introduction & Setup Slides
5-15 min Memory Architecture Theory Slides
15-30 min Exercise 1: Memory Implementation Hands-on (Jupyter)
30-40 min Memory Types Deep Dive Slides + Live Demo
40-50 min Exercise 2: Redis Caching Hands-on (Jupyter)
50-58 min Exercise 3: Cost Metrics Hands-on (Jupyter)
58-60 min Wrap-up & Resources Slides

🧠 Core Concepts

Memory Types in LangGraph

1. Semantic Memory

Store facts, preferences, and structured knowledge:

store.put(
    namespace=("user_123", "preferences"),
    key="food_preference",
    value={"type": "cuisine", "preference": "Italian", "source": "conversation"}
)

2. Episodic Memory

Maintain conversation history and context:

checkpointer = PostgresSaver.from_conn_string(DATABASE_URL)
graph = builder.compile(checkpointer=checkpointer)
# Automatic thread-based history

3. Procedural Memory

Adapt agent behaviors based on outcomes:

store.put(
    namespace=("agent_strategies",),
    key=f"success_pattern_{task_type}",
    value={"approach": strategy, "success_rate": 0.85}
)

Redis Semantic Caching

Reduce costs and latency by caching LLM responses:

from langchain_redis import RedisCache

cached_llm = llm.with_cache(
    RedisCache(
        redis_url=REDIS_URL,
        ttl=3600,
        similarity_threshold=0.95
    )
)

Impact: 40-70% cost reduction for typical multi-step agent workflows

πŸ“Š Expected Results

After completing this workshop, you'll have:

Metric Before Optimization After Optimization Improvement
Token Usage (multi-step task) ~15,000 tokens ~5,000 tokens 67% reduction
Cost per Interaction $0.30 $0.10 67% reduction
Average Latency 3.2s 1.8s 44% improvement
Cache Hit Rate 0% 65% N/A

Results based on typical chatbot with 5-turn conversations

πŸ› οΈ Technology Stack

  • LangGraph 0.2+: Agent orchestration framework
  • LangChain 0.3+: LLM integration
  • Redis 7+: Semantic caching layer
  • LangMem SDK: Memory management utilities
  • Python 3.10+: Programming language

LLM Provider Support

This workshop supports both OpenAI and Anthropic. All code includes provider abstraction:

# Toggle between providers
llm = get_llm(provider="anthropic")  # or "openai"

πŸ“ Repository Structure

langgraph-redis-workshop/
β”œβ”€β”€ README.md                          # This file
β”œβ”€β”€ SETUP.md                           # Detailed setup guide
β”œβ”€β”€ docker-compose.yml                 # Local Redis container
β”œβ”€β”€ slides/                            # MARP presentation
β”œβ”€β”€ notebooks/                         # Jupyter notebook exercises
β”œβ”€β”€ src/                               # Reusable code modules
β”œβ”€β”€ examples/                          # Complete working examples
β”œβ”€β”€ tests/                             # Test suite
β”œβ”€β”€ docs/                              # Additional documentation
β”œβ”€β”€ requirements.txt                   # Python dependencies
└── .env.example                       # Environment template

🀝 Contributing

Found an issue or have improvements? Contributions welcome!

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/improvement)
  3. Commit changes (git commit -m 'Add improvement')
  4. Push to branch (git push origin feature/improvement)
  5. Open a Pull Request

πŸ“ License

MIT License - See LICENSE for details

πŸ”— Resources

Official Documentation

Additional Learning

Community

πŸ‘€ Author

Ben Labaschin

  • GitHub: @EconoBen
  • Workshop Date: [Your Conference/Event Name]

πŸ“„ Citation

If you use this workshop material, please cite:

@misc{labaschin2025langgraph,
  author = {Labaschin, Ben},
  title = {Building Stateful AI Agents: Memory Management and Optimization with LangGraph and Redis},
  year = {2025},
  publisher = {GitHub},
  url = {https://github.com/EconoBen/langgraph-redis-workshop}
}

⭐ Star this repo if you found it helpful! πŸ› Report issues to help improve the workshop πŸ’¬ Share feedback to make future workshops better

About

Building Stateful AI Agents

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors