Back to Labs
Advanced

Full Agent + Streamlit

Download Lab Files

Production-ready Streamlit application with LangChain agents, RAG, moderation layers, guardrails, and multiple tools.

Why Full Agent?

Complete Web Application

Streamlit UI with tabs: Chat, Setup, and Help

Moderation Layer

Security: Toxicity, injection, PII masking

Guardrails

Quality: Citations, tone, professional responses

RAG Integration

FAISS + PDF processing + Knowledge search

Architecture

Streamlit UI Moderation Layer Safe Blocked LangChain Agent Blocked Response Tools RAG Search Calculate Summarize FAISS Index Guardrails Final Response Legend: UI Security Agent Tools Quality

Step 1: Environment Setup

Recommended: Docker ensures consistent environment and includes all dependencies.
# 1. Make sure Ollama is running
ollama serve
ollama pull llama3.1

# 2. Navigate to the directory
cd "Full Agent + streamlit + langchain"

# 3. Run with helper script (recommended)
chmod +x scripts/docker-run.sh
./scripts/docker-run.sh run

# OR use docker-compose directly
docker-compose up --build

# 4. Access the app
# Open: http://localhost:8505
Native Windows: Automated scripts handle system dependencies.

1. Setup & Environment

# 1. System dependencies (Run PowerShell as Administrator)
.\setup\windows\install.ps1

# 2. Python environment & dependencies
cd "Full Agent + streamlit + langchain"
python -m venv .venv
.\.venv\Scripts\activate
pip install -r requirements.txt

2. RAG System (FAISS + Embeddings)

Important: You must initialize the vector database to enable RAG features.
# Generate the FAISS index from PDFs
python src/rag/generate_vector_db.py

3. (Optional) GPU Acceleration

# If you have an NVIDIA GPU
.\setup\windows\fix_pytorch_cuda.bat

4. Run

# Start Ollama and run the app
ollama serve
ollama pull llama3.1
streamlit run ui.py
Native macOS: Uses Homebrew for system dependencies.

1. Setup & Environment

# 1. System dependencies
chmod +x setup/mac/install.sh && ./setup/mac/install.sh

# 2. Python environment & dependencies
cd "Full Agent + streamlit + langchain"
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

2. RAG System (FAISS + Embeddings)

Important: You must initialize the vector database to enable RAG features.
# Generate the FAISS index from PDFs
python src/rag/generate_vector_db.py

3. Run

# Start Ollama and run the app
ollama serve
ollama pull llama3.1
streamlit run ui.py
# Navigate to the directory
cd "Full Agent + streamlit + langchain"

# Configure Poetry
poetry config virtualenvs.in-project true

# Install dependencies
poetry install

# Make sure Ollama is running
ollama serve
ollama pull llama3.1

# Run the Streamlit app
poetry run streamlit run ui.py

# Access: http://localhost:8501
AI-Assisted: Use GitHub Copilot or any AI coding assistant to automate installation.

How to Use

The project includes a ready-to-use prompt file that you can copy and paste into Copilot, ChatGPT, Claude, or any AI assistant.

Open COPILOT_INSTALL_PROMPT.md in the project root
Copy the content inside the code block
Paste into your AI assistant (Copilot, ChatGPT, etc.)
Follow the AI-generated step-by-step instructions

What the Prompt Includes

  • System requirements (Python, Ollama, Graphviz)
  • Key Python packages from requirements.txt
  • Step-by-step installation for Windows and macOS
  • Complete project structure reference
  • Troubleshooting common issues
  • Quick commands summary table
# Location of the Copilot prompt file:
COPILOT_INSTALL_PROMPT.md

# The file contains a detailed prompt you can use with:
# - GitHub Copilot Chat
# - ChatGPT / GPT-4
# - Claude
# - Any AI coding assistant

# Simply copy the prompt and paste it into your AI tool!

Step 2: RAG System

FAISS + PDF processing + Embeddings

Vector Database Architecture
Important: You must initialize the vector database to enable RAG features.
# Generate the FAISS index from PDFs
python src/rag/generate_vector_db.py
Pro Tip: After running the app, you can also go to the "RAG" tab in the interface and click "Rebuild Vector Database" to refresh your knowledge base without using the command line.
Toxicity: Filters offensive language
Injection: Blocks prompt attacks
PII Masking: Redacts emails/phones
DLP: Prevents data leakage
# src/moderation/manager.py
class ModerationManager:
    def check_input(self, text: str) -> ModerationResult:
        if self._is_toxic(text):
            return ModerationResult(blocked=True, reason="Toxic content")
        if self._is_injection(text):
            return ModerationResult(blocked=True, reason="Injection attempt")
        return ModerationResult(blocked=False, cleaned=self._mask_pii(text))
Citations: Warns if missing sources
Tone: Flags unprofessional responses
# src/guardrails/validators.py
class ResponseValidator:
    def validate(self, response: str) -> ValidationResult:
        warnings = []
        if self._lacks_citations(response):
            warnings.append("Response lacks source citations")
        if self._is_overly_apologetic(response):
            warnings.append("Tone is unprofessional")
        return ValidationResult(warnings=warnings)

Chat Tab

Conversational interface with tools

Setup Tab

LLM, RAG, and persistence config

Help Tab

Documentation and examples

Project Structure

Full Agent + streamlit + langchain/
├── ui.py                    # Main Streamlit interface
├── config/                  # YAML configurations
│   ├── model_config.yaml    # LLM settings
│   └── prompt_templates.yaml
├── src/
│   ├── moderation/          # Security Layer
│   │   └── manager.py       # Toxicity, injection, PII
│   ├── guardrails/          # Quality Layer
│   │   └── validators.py    # Citations, tone
│   ├── rag/                 # RAG Implementation
│   │   ├── retriever.py
│   │   └── generate_vector_db.py
│   ├── tools/               # Agent tools
│   └── llm/                 # LLM clients
└── data/
    ├── docs/books/          # PDF documents
    └── embeddings/          # FAISS index

Learning Checklist

Additional Resources