# 1. Install Python dependencies
pip install -r requirements.txt
# 2. Configure your API key# Set the GEMINI_API_KEY environment variable (or edit backend/config.py)export GEMINI_API_KEY="your-api-key-here"# 3. Start the backend servercd backend
python app.py
# Server starts at http://localhost:5000# 4. Open browser# Navigate to: http://localhost:5000
βοΈ Configuration (backend/config.py)
Setting
Default
Notes
SECRET_KEY
personaflow-secret-key-...
Change in production
SQLALCHEMY_DATABASE_URI
sqlite:///personaflow.db
DB stored in backend/instance/
GEMINI_API_KEY
AIzaSyBiL-wOiS8Rj5h3YuC...
Your Gemini API Key
GEMINI_MODEL
gemini-2.5-flash
LLM model name
KOKORO_DEFAULT_VOICE
af_heart
Default Kokoro TTS voice
PERMANENT_SESSION_LIFETIME
86400 (24 hours)
Session expiry
π Key Architecture Decisions
SPA with hash routing: router.js intercepts all hashchange events and renders the correct page module. No page reloads.
Auth: Session-based (Flask sessions). Protected routes use @login_required decorator. Frontend checks /api/auth/me on load.
AI calls: All AI interactions go through ai_service.py β Gemini REST API. System prompt building is handled by agent_behavior.py.
Agent Behavior Engine (agent_behavior.py): Centralizes all prompt-building logic. Auto-detects role type (INTERVIEWER / TEACHER / COACH / EVALUATOR / DEFAULT) and injects role-specific behavioral instructions. Enforces strict scope via output_config.strict_mode. Applies response-length rules based on conversation mode β video calls get 1β2 sentence responses; text chat gets 3β4 sentences. Supports output_config behavior fields: strict_mode, allow_out_of_scope, max_answer_length, behavior.
Agent types: Two types β conversation (standard chat bot) and anchoring (teleprompter script reader). Anchoring agents have script_content and in-memory state tracking (anchoring_states dict in app.py).
Reports: Auto-generated on conversation end if output_config.evaluation is enabled. Can also be manually generated via the API. Stored in Report model.
Report Chat: /api/agents/<id>/report-chat feeds all the agent's conversations + reports as context to the LLM so users can ask analytical questions.
Video Call: Uses Three.js for 3D avatar rendering. Text-to-speech via Kokoro TTS (local neural). Speech-to-text via Whisper + Google Web Speech API. Custom phoneme-based lip-sync engine (lipsync-engine.js). Kokoro pipeline is initialized as a singleton at first TTS call to avoid reload overhead.
Dark mode: Stored in localStorage as personaflow-theme. Applied via [data-theme=dark] attribute on <html>. Applied immediately in a blocking <script> before body renders to prevent flash.
Share links: Tokenized URLs (/api/share/<token>). Support password protection, expiry, max uses, and required name/email fields.
Notifications panel: Rendered as a fixed overlay, positioned to appear above the sidebar (z-index managed carefully).
π Known Issues / Recent Work History
Report Chat was moved from Reports page β Agent Detail page (agent-specific context). The agent-detail.js "Report Chat" tab contains the chat UI.
Reports page (reports.js) shows only the report history list (no embedded chat).
Agent Creation Flow: The agent-wizard.js now features a "choice screen" before the wizard starts, offering "Build from Scratch" (with inspiration idea cards) or "Use a Template" (rendering the template gallery inline).
Templates: The dedicated #/templates page was removed from the sidebar. Templates are exclusively accessed via the new Create Agent choice screen.
TTS (Avatar Voice): Migrated from edge-tts (Microsoft) to Kokoro TTS (local neural TTS). The /api/avatar/talk endpoint now uses KPipeline from the kokoro Python package. Outputs .wav audio. On first run, Kokoro auto-downloads its model weights (~327MB). No API key required.
Note on Windows Installation: Kokoro has a strict dependency on numpy==1.26.4 which fails on Python 3.13. It can be installed by bypassing dependencies (pip install kokoro --no-deps) and installing numpy, torch, misaki, etc., manually.
Note on Misaki Compatibility: The G2P library misaki (version 0.7.4) crashes with a TypeError when encountering unknown tokens (t.phonemes is None). This was manually patched in misaki/en.py to fallback to an unknown token instead of crashing.
Agent Behavior Engine: New backend/agent_behavior.py centralizes all system-prompt building. Extracted from ai_service.py. Role-specific prompt sections (Interviewer, Teacher, Coach, Evaluator, Default). output_config JSON now supports strict_mode, allow_out_of_scope, max_answer_length, and behavior fields.
Response Length (video vs text): ai_service.generate_response() now accepts a mode parameter. Video calls pass mode='video' (from conversation.mode) β agent replies in 1β2 sentences for natural interrupt-handling. Text chat uses mode='text' β 3β4 sentences max.
3D Avatar lip-sync: Complex phoneme mapping via lipsync-engine.js. Debugging history in conversation logs.
Microphone Mute/Unmute: Fixed a bug where toggling the microphone off and on would leave the SpeechRecognition engine in a halted state. The startListening() method now properly handles re-initializing the Web Speech API SpeechRecognition object if it fails to start.
Notifications panel: Was clipping behind sidebar β fixed with proper z-index and positioning.
Anchoring: In-memory state per agent_id (anchoring_states dict in app.py). Script read line-by-line via /api/anchoring/<agent_id>/status polling.
Share Link UI: Redesigned the "Create Share Link" modal to improve UX, grouping password, expiry, and max uses into a cleaner layout, and converting to a toggle switch for the password field.
Code QA: Reviewed backend API routes and fixed minor transcript generation logic consistency in manual report generation.