Loopback is a premium, state-of-the-art full-stack web application designed to simulate, visualize, and analyze complex interpersonal communication dynamics between couples.
Powered by advanced clinical psychology frameworks (Attachment Theory, Big Five, conflict styles) and local Large Language Models via Ollama (preferring qwen2.5:7b), Loopback models romantic relationships through a multi-agentic system, allowing users to predict conversational outcomes, trace live emotional tension curves, and build a self-refining knowledge base.
Loopback uses a multi-layered agentic pattern to capture, model, and simulate relationships locally and privately:
graph TD
A[User Inputs: Questionnaire & Socials] -->|POST /api/profile/build| B(Personality Builder)
B -->|Ollama: qwen2.5:7b| C[Structured Personality Profile]
C -->|POST /api/profile/analyze-pairing| D(Attachment Pairing Analyzer)
C -->|POST /api/simulation/start| E(Simulation Engine)
E -->|Server-Sent Events SSE| F[Live React UI & Tension Curve]
E -->|Conversation Transcript| G(Conclusion Engine)
G -->|Therapist Notes & Predicted Trajectory| H[Conclusion Dashboard]
H -->|POST /api/feedback/submit| I(Knowledge Base Writer)
I -->|Markdown + Semantic Indexing| J[ChromaDB Vector Store]
J -->|Context Retrieval| E
Loopback/
βββ backend/
β βββ agents/ # Psychological Agent Engines
β β βββ agent_runner.py # SimulationRunner & SimTurn model
β β βββ conclusion_engine.py # Post-simulation transcript analysis
β β βββ emotional_state.py # Arousal, valence, openness, defensiveness trackers
β β βββ personality_builder.py# Dynamic LLM system prompt constructor
β βββ classifier/ # Context classification & retrieval
β β βββ intent_classifier.py # Decides relevant KB categories
β β βββ kb_retriever.py # Fetches relevant MD entries for LLM context
β βββ knowledge_base/ # Localized psychological pattern database
β β βββ attachment-outcomes/ # Anxious-avoidant trapped dynamics
β β βββ communication-mismatches/# Literal vs. indirect speech research
β β βββ conflict-styles/ # Fight, flee, freeze, fawn pairings
β β βββ personality-patterns/ # MBTI / Big Five archetypes
β β βββ skill-refinements/ # Date-prefixed simulation lessons
β βββ models/ # Pydantic schemas for request/response validation
β βββ routers/ # FastAPI Endpoints
β β βββ feedback.py # Handles session reviews & KB writing
β β βββ knowledge.py # Exposes KB statistics
β β βββ profile.py # Profile build & pairing compatibility analysis
β β βββ simulation.py # Start & SSE streaming routers
β βββ utils/ # Core utilities
β β βββ kb_writer.py # Commits dynamic feedback to Markdown files
β β βββ ollama_client.py # Ollama API adapter with auto text-model selection
β β βββ pattern_refiner.py # Refines and deduplicates KB patterns
β βββ main.py # FastAPI entrypoint
β βββ requirements.txt # Python dependencies
β
βββ frontend/
β βββ src/
β β βββ api/ # Axios-based backend communication
β β βββ components/ # Reusable UI Blocks (SimulationChat, Questionnaire)
β β βββ pages/ # Main screens (Home, BuildProfile, Simulate, Dashboard)
β β βββ store/ # Zustand client state management (with partialize filters)
β β βββ App.jsx # Routes and layout
β β βββ index.css # Beautiful styles, gradients, glassmorphism config
β βββ package.json # Frontend Node dependencies
β βββ vite.config.js # Vite bundler configuration
β
βββ run_loopback.sh # Single-click orchestration script
βββ PROJECT_PLAN.md # Original implementation specifications
Before running the application, make sure you have the following installed on your machine:
- Ollama: Running locally with a dialogue model downloaded (e.g.,
ollama pull qwen2.5:7b) - Node.js:
v18.0.0or higher (tested onv20.20.2) - npm:
v9.0.0or higher - Python:
v3.11.0or higher (or compatiblev3.9+)
Loopback automatically queries Ollama, filters out vision/embedding models, and auto-selects the best available text-focused model:
ollama pull qwen2.5:7bCreate a Python virtual environment, install the dependencies, and set up your environment variables:
# Navigate to backend
cd backend
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate
# Install requirements
pip install -r requirements.txtCreate a .env file in the backend/ directory:
OLLAMA_URL=http://127.0.0.1:11434
CHROMA_DB_PATH=./backend/chroma_db
KB_PATH=./backend/knowledge_baseInstall the Node dependencies:
cd ../frontend
npm installCreate a .env file in the frontend/ directory:
VITE_API_URL=http://localhost:8000You can boot both the FastAPI backend and the Vite frontend simultaneously using the included runner script in the workspace root:
chmod +x run_loopback.sh
./run_loopback.shStart the FastAPI Backend:
source backend/venv/bin/activate
uvicorn backend.main:app --reload --port 8000Start the Vite Frontend:
cd frontend
npm run devOpen http://localhost:5173 in your browser.
- Questionnaire & Social Data Parsing: Collects Big Five ratings and communication habits alongside simulated chat logs or social profiles to construct highly customized, attachment-labeled profiles.
- Dynamic Turn-Phase Prompting: Divides dialogue into 4 phases (Opening, Escalation, Crisis, Turning Point) to emulate authentic escalation arcs instead of repetitive loops.
- Double-Ended Emotional Tracker: Updates metric values (arousal, openness, valence, defensiveness) live with every speech turn, generating over 15+ rich psychological states (e.g., "vulnerable but uncertain", "cornered & lashing out").
- Anti-Repetition Engine: Scans historical turns to track themes already discussed and strictly forbids agents from repeating previous arguments.
- Real-time SSE Streaming: Emits live typing indicators, messages, inner monologues (subtexts), and current tension metrics directly to the React interface.
- Self-Correcting Knowledge Base: Incorporates real user feedback into Markdown folders (
/backend/knowledge_base/) dynamically. A background vector store index (ChromaDB) ensures lessons learned from previous simulations automatically shape subsequent agent behavior.