XgirlfriendGPT is a state-of-the-art, multi-modal, multi-persona AI companion platform. Built on top of LangGraph multi-agent orchestration, Pydantic v2 state management, headless ComfyUI visual generation, Edge-TTS voice streaming, and Qdrant + FastEmbed long-term vector memory, XgirlfriendGPT delivers contextually congruent roleplay, visual selfie generation, and multi-character group interactions.
100% of user chat turns execute through a state graph featuring dedicated, specialized agents:
| Agent | Responsibility |
|---|---|
| RouterAgent | Handles turn-taking and speaker selection in 1-on-1 and multi-companion room chats using name recognition, semantic topic matching, and conversation flow awareness |
| PersonaAgent | Blends long-term memory, conversation history, and persona directives to produce character-aligned responses and detect visual tool calls |
| SceneAgent | Extracts physical descriptors and triggers context-congruent visual generation payloads for ComfyUI |
| MemoryAgent | Asynchronously extracts long-term facts and updates vector embeddings in Qdrant |
- Generates photorealistic selfies and scene photos aligned with the current conversation
- Supports FLUX.2, FLUX.1, SDXL checkpoints, InstantID face consistency, and custom LoRA overlays
- Inline
πΈ View Photobutton embedded directly in chat response bubbles - Async non-blocking generation with circuit breaker protection
- Edge-TTS real-time synthesis for rich, natural vocal responses
- Manual inline
π Listenbutton with toggleable play/pause controls (no invasive autoplay) - On-demand synthesis via
/api/v1/voice/synthesizeendpoint - WebSocket streaming support for real-time calls
- Ingest chat logs, text exports, or natural language descriptions to auto-extract traits, formality, slang, and system prompts
- Long-term memory stored in Qdrant vector space with FastEmbed embeddings
- Dynamic memory recall during chat turns with semantic similarity search
- Post-creation personality updates via
PATCH /api/v1/clone/profile/{id}
- Create multi-companion rooms where characters engage in dynamic group conversations
- Intelligent turn-taking with semantic routing and round-robin fallback
- Shared conversation history with per-speaker attribution
- Integrated APScheduler for automated, context-aware SMS check-ins
- Contextual message generation using recalled long-term user memories
- Twilio integration for SMS delivery
- Health Checks:
/health/liveness,/health/readiness(Qdrant, LLM, ComfyUI),/health/metrics(Prometheus) - Observability: Request tracing middleware with
x-request-id, latency metrics - Rate Limiting: Token bucket (chat: 60/min, media: 10/min) with thread-safe implementation
- Circuit Breakers: Three-state (CLOSED/OPEN/HALF_OPEN) for external service resilience
- JWT Authentication: HS256 tokens with configurable secret, 24hr expiry
- Input Validation: Path traversal prevention, strict companion_id sanitization
βββββββββββββββββββββββββββββββββ
β FastAPI Gateway β
β (http://0.0.0.0:8005) β
βββββββββββββββββ¬ββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββ
β LangGraph State Orchestratorβ
β State: CompanionState β
βββββββββββββββββ¬ββββββββββββββββ
β
ββββββββββββββββββββ¬ββββββββββββ΄ββββββββββββ¬βββββββββββββββββββ
β β β β
βΌ βΌ βΌ βΌ
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β Router Agent β βPersona Agent β β Scene Agent β β Memory Agent β
ββββββββββββββββ βββββββββ¬βββββββ βββββββββ¬βββββββ βββββββββ¬βββββββ
β β β
βΌ βΌ βΌ
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β Ollama β β ComfyUI β β Qdrant β
β (Port 11434) β β (Port 8188) β β (Vector DB) β
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
- Python 3.12+
- Ollama running locally on port
11434with your preferred roleplay model (e.g.,R4C3R/qwen3-8b-heretic:q8_0) - ComfyUI running locally on port
8188(for image generation)
git clone https://github.com/JasonDoug/XgirlfriendGPT.git
cd XgirlfriendGPT
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtcp .env.example .env
# Edit .env with your settings:
# - LLM_BASE_URL, LLM_API_KEY, DEFAULT_MODEL
# - QDRANT_HOST, QDRANT_COLLECTION
# - JWT_SECRET_KEY (generate with: openssl rand -hex 32)
# - TWILIO credentials (optional, for SMS/Voice)bash /path/to/ComfyUI/run_comfyui.sh --port 8188export PYTHONUNBUFFERED=1
source .venv/bin/activate
uvicorn app.main:app --host 0.0.0.0 --port 8005Open your browser at http://localhost:8005 to access the interactive web interface!
| Variable | Default | Description |
|---|---|---|
LLM_PROVIDER |
auto |
auto, ollama, vllm, together, openai, mock |
LLM_BASE_URL |
http://localhost:11434/v1 |
Ollama/OpenAI-compatible endpoint |
LLM_API_KEY |
`` | API key for remote providers |
DEFAULT_MODEL |
granite4:latest |
Model identifier for LLM inference |
QDRANT_HOST |
./data/qdrant_db |
Qdrant mode: local disk (./data/qdrant_db), in-memory (:memory:), or server (localhost / qdrant) |
QDRANT_COLLECTION |
companion_memories |
Vector collection name |
JWT_SECRET_KEY |
required | HS256 signing key (generate: openssl rand -hex 32) |
TWILIO_ACCOUNT_SID |
`` | Twilio account SID for SMS/Voice |
TWILIO_AUTH_TOKEN |
`` | Twilio auth token |
TWILIO_PHONE_NUMBER |
`` | Twilio verified phone number |
- LLM Model: Switch between Ollama/local models
- Image Model: FLUX/SDXL checkpoint selection with auto-tuned params
- Resolution: 512Γ512 to 1152Γ896
- Sampling Steps: 1β50
- CFG Scale: 1.0β15.0
- LoRA Overlays: Multi-select with auto trigger-word injection
source .venv/bin/activate
# Run all tests
pytest
# Run specific test modules
pytest tests/test_extractor.py -v
pytest tests/test_api.py -v
pytest tests/test_chat_memory.py -v
# With coverage
pytest --cov=app --cov-report=term-missingTest Suite Coverage: 14+ test cases covering:
- Personality extraction from logs/descriptions
- API routes (chat, rooms, voice, SMS, clone, settings, health, auth)
- Vector memory storage/retrieval
- Fast mode chat + on-demand media synthesis
- Companion profile updates (formality, response length)
- WebSocket voice streaming
XgirlfriendGPT/
βββ app/
β βββ api/ # FastAPI route handlers
β β βββ auth.py # JWT token issuance & validation
β β βββ chat.py # 1-on-1 companion chat
β β βββ clone.py # Personality ingestion & profile updates
β β βββ health.py # Liveness/readiness/metrics
β β βββ rooms.py # Multi-persona group chats
β β βββ settings.py # Runtime model/pipeline config
β β βββ sms.py # Twilio SMS webhooks
β β βββ voice.py # Voice webhooks & TTS
β βββ graph/ # LangGraph multi-agent orchestration
β β βββ agents/ # Router, Persona, Scene, Memory agents
β β βββ state.py # CompanionState (Pydantic)
β β βββ workflow.py # Graph compilation
β βββ middleware/ # Observability, rate limiting
β βββ models/ # Pydantic schemas
β βββ services/ # Business logic (LLM, Memory, Visual, Voice, SMS, etc.)
β βββ utils/ # Circuit breaker, helpers
β βββ static/ # Frontend (HTML, JS, generated assets)
β βββ config.py # Pydantic Settings
β βββ main.py # FastAPI app factory
βββ tests/ # Pytest test suite
βββ data/ # Persistent storage (companions, rooms, Qdrant)
βββ requirements.txt # Python dependencies
βββ .env.example # Environment template
βββ README.md
GET /health/liveness- Process healthGET /health/readiness- Dependency checks (Qdrant, Ollama, ComfyUI)GET /health/metrics- Prometheus metrics
POST /api/v1/auth/token- Issue JWT ({"user_id": "..."})GET /api/v1/auth/me- Validate token, get user info
POST /api/v1/clone/ingest- Create companion from logs/descriptionGET /api/v1/clone/list- List all companionsGET /api/v1/clone/profile/{id}- Get companion profilePATCH /api/v1/clone/profile/{id}- Update formality, response length, name, typeDELETE /api/v1/clone/{id}- Delete companion
POST /api/v1/chat/message- Send message (with rate limiting)GET /api/v1/chat/history/{id}- Get chat historyPOST /api/v1/chat/selfie/{id}- On-demand image generation
POST /api/v1/rooms/create- Create roomGET /api/v1/rooms- List roomsGET /api/v1/rooms/{id}- Get roomPOST /api/v1/rooms/message- Send room message
POST /api/v1/voice/webhook- Twilio voice webhookPOST /api/v1/voice/synthesize- On-demand TTSWS /api/v1/voice/stream- Real-time voice streamingPOST /api/v1/sms/webhook- Twilio SMS webhookPOST /api/v1/sms/send- Trigger outbound SMS
GET /api/v1/settings- Get current settingsPOST /api/v1/settings- Update settingsGET /api/v1/settings/models- Discover available models/LoRAs
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
git clone https://github.com/JasonDoug/XgirlfriendGPT.git
cd XgirlfriendGPT
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pre-commit install # optional, for linting- Python: Black + Ruff (line length 100)
- Type Hints: Required for all public functions
- Async: Prefer
async/awaitfor I/O-bound operations - Tests: Add tests for new features in
tests/
This project is licensed under the MIT License - see LICENSE for details.
- LangGraph - Multi-agent orchestration framework
- ComfyUI - Node-based visual generation pipeline
- Edge-TTS - High-quality text-to-speech
- Qdrant - Vector database for long-term memory
- FastEmbed - Fast ONNX embeddings (BAAI/bge-small-en-v1.5)
- FastAPI - Modern, fast web framework
- Pydantic v2 - Data validation and settings management
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Security: See SECURITY.md for vulnerability reporting
Built for advanced AI companion exploration and multi-modal multi-agent orchestration.