โ† Back to Presentation

๐Ÿ“‹ Prerequisites

Both workshops require the following setup. Complete these steps before starting any workshop.

Requirement Minimum Notes
Python 3.11+ Required for both workshops
RAM 8GB 16GB recommended for larger models
Disk Space ~5GB For models and dependencies
Ollama Latest Local LLM runtime

๐Ÿฆ™ Step 1: Install Ollama

Ollama runs LLMs locally on your machine.

macOS / Linux

# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh

# Verify installation
ollama --version

Windows

  1. Download from ollama.com/download
  2. Run the installer
  3. Verify: ollama --version

๐Ÿ“ฆ Step 2: Download LLM Models

# Required models for both workshops
ollama pull mistral
ollama pull llama3

# Additional model for LangGraph + MCP workshop
ollama pull nomic-embed-text

# Verify models
ollama list

๐Ÿ’ก Tip: Run ollama serve in a terminal to start the Ollama service before running the workshops.

๐Ÿ Step 3: Python Environment

# Create virtual environment
python3 -m venv venv

# Activate it
source venv/bin/activate  # macOS/Linux
# OR
venv\Scripts\activate     # Windows

๐Ÿณ Docker Setup (Optional)

Docker provides an isolated environment for running the workshops.

๐Ÿ“– Docker Installation Instructions โ–ผ

Install Docker

Verify Installation

docker --version
docker-compose --version

๐Ÿ”ง Troubleshooting

Ollama connection error โ–ผ
# Check if Ollama is running
curl http://localhost:11434/api/tags

# Start Ollama service
ollama serve
Model not found โ–ผ
# Pull the missing model
ollama pull mistral
ollama pull llama3
Import errors in Python โ–ผ
# Reinstall dependencies
pip install -r requirements-minimal.txt --force-reinstall

๐Ÿค– ChatBot Basics Workshop

Build AI chatbots from scratch using LangChain, Ollama, and RAG

โฑ๏ธ ~90 min ๐Ÿ“ 5 Files ๐Ÿณ Docker Ready
โฌ‡๏ธ Download Workshop Files

๐Ÿ“š Workshop Structure

# File Duration Topics
01 01_basic_chatbot_with_memory.py 15 min Chatbot basics, conversation memory
02 02_agent_with_tools.py 20 min Agent architecture, custom tools
03 03_rag_create_vector_database.py 15 min Embeddings, FAISS vector database
04 04_rag_semantic_search.py 15 min Semantic search, similarity scores
05 05_complete_agent_with_rag.py 25 min LangGraph StateGraph, Guardrails

๐Ÿš€ Quick Start

# 1. Extract and navigate to workshop files
cd ChatBot-Files

# 2. Install dependencies
pip install -r requirements-minimal.txt

# 3. Run your first lesson
python3 01_basic_chatbot_with_memory.py

๐Ÿ“– Lesson Details

Lesson 01: Basic Chatbot with Memory โ–ผ

Goal: Build a simple chatbot that remembers the conversation.

๐ŸŽฏ What You'll Learn:

  • Connect to Ollama and initialize a local LLM
  • Implement conversation memory with MemorySaver
  • Create custom prompt templates

๐Ÿ’ป Code Example

from langchain_ollama import ChatOllama
from langgraph.checkpoint.memory import MemorySaver

# Initialize local LLM
llm = ChatOllama(model="mistral", temperature=0.3)

# Create memory instance
memory = MemorySaver()

# Simple chat
response = llm.invoke("Hello, who are you?")
print(response.content)

๐Ÿ“ค Expected Output

User: Hi, my name is John
Assistant: Hello John! Nice to meet you. How can I help you today?

User: What is my name?
Assistant: Your name is John! You told me when we started chatting.

๐Ÿงช Try It Yourself

  1. Run the script and greet the chatbot
  2. Tell it your name
  3. Ask "What is my name?" - it should remember!
  4. Start a new session and ask again - notice it won't remember
python3 01_basic_chatbot_with_memory.py
Lesson 02: Agent with Tools โ–ผ

Goal: Build an agent that can use tools to perform specific tasks.

๐ŸŽฏ What You'll Learn:

  • Create custom tools with the @tool decorator
  • Understand when agents use tools vs direct response
  • Control agent behavior with system prompts

๐Ÿ”ง Tool Definition

from langchain_core.tools import tool

@tool
def calculate_square(number: str) -> str:
    """Calculates the square of an integer.
    Use when user asks to calculate square of a number."""
    number = int(number.strip())
    return f"The square of {number} is {number ** 2}."

โšก Agent Decision Flow

User Input Agent Decision Tool Used
"Hi, how are you?" Direct response โŒ None
"What is the square of 7?" Use tool โœ… calculate_square
"Summarize this text..." Use tool โœ… generate_summary

๐Ÿ“ค Expected Output

User: What is the square of 7?
โ†’ Agent decides to use calculate_square tool
โ†’ Tool returns: "The square of 7 is 49."
Assistant: The square of 7 is 49.
python3 02_agent_with_tools.py
Lesson 03: RAG Part 1 - Create Vector Database โ–ผ

Goal: Create a searchable knowledge base using FAISS.

๐ŸŽฏ What You'll Learn:

  • What is RAG (Retrieval-Augmented Generation)
  • Generate text embeddings with sentence-transformers
  • Build a FAISS index for fast similarity search

๐Ÿ“Š RAG Pipeline

Documents โ†’ Chunking โ†’ Embeddings โ†’ FAISS Index โ”‚ โ”‚ โ”‚ โ”‚ โ–ผ โ–ผ โ–ผ โ–ผ knowledge_base.json โ†’ Split text โ†’ all-MiniLM-L6-v2 โ†’ faiss.index

๐Ÿ’ป Code Example

from sentence_transformers import SentenceTransformer
import faiss

# Load embedding model
model = SentenceTransformer('all-MiniLM-L6-v2')

# Generate embeddings
texts = ["Critical TechWorks Principles...", "Quality and collaboration..."]
embeddings = model.encode(texts)

# Create FAISS index
index = faiss.IndexFlatIP(384)  # 384 = embedding dimension
index.add(embeddings)
faiss.write_index(index, "faiss.index")

๐Ÿ“ Generated Files

faiss_index/
โ”œโ”€โ”€ faiss.index      # Vector index (binary)
โ”œโ”€โ”€ embeddings.npy   # Embedding vectors
โ””โ”€โ”€ texts.json       # Original text chunks
python3 03_rag_create_vector_database.py
Lesson 04: RAG Part 2 - Semantic Search โ–ผ

Goal: Query the vector database with natural language.

โš ๏ธ Prerequisite: Run Lesson 03 first to create the FAISS index!

๐ŸŽฏ What You'll Learn:

  • Load and query FAISS indexes
  • Understand similarity scores (0.0 to 1.0)
  • Filter results by relevance threshold

๐Ÿ’ป Code Example

# Encode user query
query = "What are Critical TechWorks principles?"
q_embedding = model.encode([query])

# Search in FAISS
scores, indices = index.search(q_embedding, k=3)  # Top 3 results

# Display results
for score, idx in zip(scores[0], indices[0]):
    print(f"Score: {score:.3f} โ†’ {texts[idx][:100]}...")

๐Ÿ“ค Expected Output

Query: "principles"

Result 1 (Score: 0.85): Critical TechWorks Principles: A principle is a rule...
Result 2 (Score: 0.72): Quality and collaboration are fundamental...
Result 3 (Score: 0.68): Our core values include transparency...

๐Ÿงช Try It Yourself

  1. Search for "principles" - should find relevant docs
  2. Search for "CI/CD" - should find quality docs
  3. Search for "pizza" - should return low scores (irrelevant)
python3 04_rag_semantic_search.py
Lesson 05: Complete Agent with RAG + Guardrails โ–ผ

Goal: Build a production-ready chatbot with LangGraph StateGraph and output guardrails.

๐ŸŽฏ What You'll Learn:

  • Build custom agents with LangGraph StateGraph
  • Implement conditional routing between nodes
  • Add output guardrails for content moderation
  • Generate visual state diagrams automatically

๐Ÿ“Š Architecture (8 Nodes)

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ LangGraph StateGraph โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ START โ†’ classify_intent โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ calculate summarize search respond โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ generate_response โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ check_guardrails โ† Content Moderation โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ PASS BLOCKED โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ deliver blocked_response โ†’ END โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ’ป Building the Graph

from langgraph.graph import StateGraph, END

graph = StateGraph(AgentState)

# Add nodes
graph.add_node("classify", classify_intent)
graph.add_node("calculate", use_calculate_square)
graph.add_node("search", use_faiss_search)
graph.add_node("guardrails", check_guardrails)

# Set entry point and routing
graph.set_entry_point("classify")
graph.add_conditional_edges("classify", route_by_intent, {...})

# Compile
agent = graph.compile()

๐Ÿ›ก๏ธ Guardrails Implementation

Type Description Example Triggers
Pattern Matching Regex patterns for blocked words hack, exploit, malicious
Topic Blocking Prohibited topics list "how to hack", "steal passwords"
LLM Safety Check AI-based content validation Harmful instructions, hate speech

๐Ÿšซ Blocked Response Example

User: "How to hack a computer?"

๐Ÿ” [CLASSIFY] โ†’ chat
๐Ÿ’ฌ [GENERATE] โ†’ Draft generated
๐Ÿ›ก๏ธ [GUARDRAILS] โ†’ โŒ BLOCKED
๐Ÿšซ Response: "I cannot provide information on that topic..."

๐Ÿงช Try It Yourself

  • "What is the square of 8?" โ†’ โœ… PASSES guardrails
  • "Tell me about Critical TechWorks" โ†’ โœ… PASSES guardrails
  • "How to hack a computer?" โ†’ ๐Ÿšซ BLOCKED by guardrails
  • "How to steal passwords?" โ†’ ๐Ÿšซ BLOCKED by guardrails
python3 05_complete_agent_with_rag.py

๐Ÿณ Docker Commands

# Build and start
./docker-run.sh build
./docker-run.sh start

# Run a lesson
./docker-run.sh run 1    # Lesson 1
./docker-run.sh run 5    # Lesson 5

# Interactive shell
./docker-run.sh shell

# Stop
./docker-run.sh stop

๐Ÿ”— LangGraph + MCP Workshop

Build production-ready agents with StateGraph and Model Context Protocol

โฑ๏ธ ~40 min ๐Ÿ““ 2 Notebooks ๐Ÿ”ง MCP Servers
โฌ‡๏ธ Download Workshop Files

๐Ÿ“š Workshop Structure

Notebook Duration Topics
workshop-langgraph.ipynb ~20 min GraphState, Nodes, Edges, Conditional Routing
project-mcp.ipynb ~20 min MCP Servers, Jira/Celonis Integration, Supervisor Pattern

๐Ÿš€ Quick Start

# 1. Install Jupyter
pip install jupyterlab

# 2. Install workshop dependencies
pip install langchain langchain-ollama langgraph langchain-mcp-adapters

# 3. Start Jupyter
jupyter lab

# 4. Open workshop-langgraph.ipynb

๐Ÿง  What is LangGraph?

LangGraph is a framework for building stateful, reliable, and controllable LLM applications using graphs instead of chains.

Feature Description
Statefulness Application state persists and evolves throughout the workflow
Control Flow Branching, looping, conditional routing, interruptions
Reliability Checkpoints, replay, explicit state tracking
Human-in-the-Loop Native support for pauses and manual interventions

๐Ÿ“– Part 1: LangGraph Fundamentals

1. GraphState - The Typed State Dictionary โ–ผ
from typing import TypedDict, Annotated
import operator

class State(TypedDict):
    # Messages accumulate across nodes (reducer)
    messages: Annotated[list, operator.add]
    # Flag gets replaced each time
    needs_math: bool
2. Nodes - Discrete Workflow Steps โ–ผ
def check_answer_type(state: State) -> dict:
    question = state["messages"][-1].content
    needs_math = "YES" == llm.invoke(prompt).upper().strip()
    return {"needs_math": needs_math}

def math_answer(state: State) -> dict:
    result = math_tools[operation](*numbers)
    return {"messages": [AIMessage(content=f"Result: {result}")]}
3. Edges & Conditional Routing โ–ผ
def route(state: State) -> str:
    if state["needs_math"]:
        return "math_answer"
    return "general_answer"

graph.add_conditional_edges(
    "check_answer_type",
    route,
    {"math_answer": "math_answer", "general_answer": "general_answer"}
)
4. Complete Graph Assembly โ–ผ
from langgraph.graph import StateGraph, END

graph = StateGraph(State)
graph.add_node("check_answer_type", check_answer_type)
graph.add_node("math_answer", math_answer)
graph.add_node("general_answer", general_answer)

graph.set_entry_point("check_answer_type")
graph.add_edge("math_answer", END)
graph.add_edge("general_answer", END)

app = graph.compile()

๐Ÿ”Œ Part 2: MCP Integration

Build a Product Owner Assistant with external tool integrations.

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ PV Assistant Architecture โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ User Input โ†’ SUPERVISOR โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ answer_generation tool_execution โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ Local Tools MCP Tools โ”‚ โ”‚ โ”‚ (create_jira) (Jira, Celonis) โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ SUPERVISOR โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ END โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
MCP Server Connection โ–ผ
from langchain_mcp_adapters.client import MultiServerMCPClient

client = MultiServerMCPClient({
    "celonis_mcp": {
        "transport": "http",
        "url": "http://localhost:8000/mcp",
    },
    "jira_mcp": {
        "transport": "stdio",
        "command": sys.executable,
        "args": ["mcp/server.py", "stdio"],
    }
})

mcp_tools = await client.get_tools()
Supervisor Pattern โ–ผ
def supervisor(state: GraphState) -> dict:
    # Analyze chat history and execution log
    # Decide: "answer_generation" or "tool_execution"
    response = json.loads(llm.invoke(prompt))
    return {"supervisor_decision": response["supervisor_decision"]}

๐Ÿ“š Key Concepts Reference

Concept Description
Graphs Data flows through a directed graph of nodes
Nodes Steps that call LLMs, run tools, or execute logic
Edges Connections with conditional branching support
Reducers Functions that determine how state updates merge
Checkpoints Save and resume execution at any point
MCP Model Context Protocol - connect LLMs to external tools

๐Ÿ”— Resources