Skip to content

PRD v5 — AI Companion Platform (Archety)

Doc owner: Engineering Team Audience: Eng, Design, Security, GTM, Stakeholders Status: v5 (Implementation Update - November 2025) Last Updated: November 14, 2025

Note: This PRD has been updated to reflect the actual implementation state as of November 2025. Sections marked with 🟢 are fully implemented and deployed. Sections marked with 🟡 are in progress. Sections marked with ⚪ are planned for future phases.


Executive Summary (v4 → v5 Changes)

What Changed: This PRD update reflects the actual implementation state as of November 2025. The original vision remains intact, but the technology choices and phasing evolved based on practical constraints and opportunities discovered during development.

Major Deviations from Original Plan: 1. iMessage Architecture Complete, Edge Client Pending: Built complete iMessage backend APIs and Mac mini edge agent architecture. Currently using Telegram bot for development testing while Mac mini edge client deployment is finalized. 2. Web Portal Added: Built comprehensive photo-based onboarding system (not in original MVP scope) with personality analysis, AI companion matching, and payment integration. 3. Supabase Architecture: Adopted Supabase for PostgreSQL + authentication instead of custom JWT system. Significantly reduced complexity and cost. 4. 16+ Superpowers Shipped: Exceeded original scope with full workflow automation system including life management, OAuth-powered agents, and proactive notifications. 5. Production-Ready Backend: Fully deployed to Railway with separate dev/prod environments, monitoring (Sentry, Amplitude, Keywords AI), and 84+ API endpoints.

Implementation Highlights: - 🟢 3,022 lines of core platform code (message handler, persona engine, memory service, workflow engine) - 🟢 20+ database tables in Supabase with Row Level Security - 🟢 59K+ training examples for Sage persona personality - 🟢 100% test coverage on critical paths (memory, relationship, workflows) - 🟢 ~3s response time (p50) meets SLO targets

What's Next: - Deploy Mac mini edge client for iMessage integration - Deploy frontend to Vercel for public onboarding - Scale to 100+ beta users - Add Redis caching for performance - Launch proactive workflow notifications (currently disabled for cost control)

Overall Status: Platform is iMessage-first architecture with complete backend APIs. Mac mini edge client pending deployment. Telegram bot used for development testing only.


Strategy Summary (human‑readable)

What we built: An AI companion platform that combines deep memory (remembers your life, preferences, inside jokes), consistent personality (Sage & Echo personas with real character), and real-world superpowers (calendar analysis, email monitoring, habit tracking) — delivered as a texting companion via iMessage (with Mac mini edge client) and a beautiful web onboarding experience.

Current Implementation (November 2025): - 🟢 iMessage Integration - Complete backend APIs, Mac mini edge agent architecture designed (deployment pending) - 🟢 Telegram Bot - Development testing interface only, full conversational AI with photo support - 🟢 Web Portal - Photo-based personality analysis → AI companion matching → iMessage activation - 🟢 Memory System - mem0-powered semantic memory with privacy boundaries - 🟢 Superpowers - 16+ automated workflows (calendar stress, email urgency, habit tracking, etc.) - 🟢 OAuth Integration - Google Calendar & Gmail access with encrypted token storage - 🟢 Payment System - Stripe integration with credit-based usage tracking - 🟢 Supabase Auth - JWT-based authentication with phone verification (Twilio) - 🟡 Mac Mini Edge Client - Edge agent architecture complete, deployment in progress

Why now: AI assistants exist, but they feel transactional. We're building something that actually remembers your life and feels like a friend. The companion references past conversations naturally, learns your preferences over time, and proactively helps with real stress (not just answering questions). By combining emotional memory with practical superpowers (calendar stress detection, deadline tracking, habit support), we create stickiness that pure LLM interfaces can't match.

Who it serves: - Consumers (primary): college students, young professionals, stressed high-performers — people who want emotional presence plus "handle my chaos" help. They discover the product via web portal (photo-based onboarding) and chat via iMessage on their Apple devices. - Teams / brands (secondary): later, this same stack becomes a consistent brand voice with memory and policy.


Implementation Status (November 2025)

What's Live & Working 🟢

Core Conversational AI: - Two-stage message processing (reflex + deep reasoning) - Multi-bubble natural responses (mimics real texting patterns) - Memory-augmented responses with semantic search - Relationship stage progression (stranger → best friend) - Inside joke tracking and natural recall - Photo memory integration (send photos, AI extracts memories, recalls them later) - Boundary enforcement ("forget that" command)

Platforms: - iMessage: Complete backend APIs, Mac mini edge client architecture (deployment pending) - Telegram Bot: Development testing only (webhook integration for dev environment) - Web Portal: Complete photo-based onboarding flow - Upload 10 photos → GPT-5 Vision analyzes personality - Big 5 personality profile generated - AI companion matching (Sage vs Echo recommendation) - Phone verification (Twilio OTP) - Payment processing (Stripe $5 trial) - iMessage activation via QR code deeplink

Superpowers & Automation: - 16+ production workflows across 4 categories: - Life Workflows: Daily summary, mood tracker, budget tracker, habit tracker, reminder system - OAuth Agents: Calendar stress analyzer, Gmail urgency detector, calendar query, calendar list - Proactive Workflows: Morning calendar prep, email urgency alerts (every 15min), event reminders, evening prep, travel support, cancellation monitoring - Example Workflows: Demo workflows for testing - Declarative node-based workflow engine (inspired by n8n) - State persistence for streaks and counters - Pause/resume with user input - HTTP integration for external APIs (weather, etc.)

Data & Infrastructure: - mem0: Semantic memory storage with namespace isolation - Supabase: PostgreSQL database + JWT authentication - Railway: Production hosting (separate dev/prod environments) - Stripe: Payment processing with webhook verification - Twilio: SMS/phone verification - Google OAuth: Calendar & Gmail integration with token encryption

Analytics & Monitoring: - Sentry: Error tracking and performance monitoring - Amplitude: Product analytics with custom event tracking - Keywords AI: LLM call tracing and cost tracking

What's Designed But Not Deployed 🟡

Edge Agent System: - Complete specification written (/docs/edge/) - Backend APIs implemented and ready - Mac mini client not yet built - Benefits: 70% backend load reduction, local scheduling, better privacy - Status: Optional for MVP, will deploy post-launch

Advanced Group Features: - Basic group mode works (coordination, planning) - Advanced features pending: polls, plan recaps, checklist tracking

What's Planned for Future 📋

  • Desktop app with MCP integration
  • Multi-user shared memories
  • Advanced persona customization
  • Enterprise features (SSO, audit logs, policy overlays)
  • Marketplace for third-party workflows

How we win:

1) iMessage-first relationship loop → no app download, no onboarding friction, feels like texting your chaotic best friend.
2) Persona Passport → consistent, ownable personality (Sage / Vex / Echo) that doesn’t drift over time.
3) Memory Vault → emotional + factual memory with provenance. The AI calls back to past moments and inside jokes, not just calendar events.
4) Superpowers via connectors / MCP → “I saw that 4pm meeting is burning you out, want me to reschedule?” This is where we outclass pure roleplay bots.
5) Portability / future surfaces → once we prove people bond with the companion in iMessage, we expose the same Persona Passport + Memory Vault to other channels: MCP inside Claude/ChatGPT, and eventually the neutral /chat Gateway API for devs and enterprise.


0) What changed vs v3 (at a glance)

  • Reframed core objects as Persona Passport and Memory Vault for clarity.
  • Competitive positioning added; product differentiators clarified (portability, deterministic writebacks, policy overlays, privacy modes).
  • Gateway API remains the primary developer surface; expanded compat headers and webhook events; added data residency and customer‑managed keys path.
  • MCP adapter nailed down with orchestrate.answer to minimize client‑side tool choreography.
  • MVP sources tightened to Gmail/Calendar/Drive (read‑only) to power stronger student/knowledge‑worker flows.
  • Evaluation & observability expanded (drift scoring, recall precision, cost/latency budgets).

0.1) Edge Agent Architecture (Mac Mini) — NEW

The Mac mini has evolved from a simple message relay into an intelligent edge agent that handles local scheduling, privacy filtering, and message execution. This architecture shift eliminates the need for complex cloud scheduling infrastructure while improving privacy and reliability.

Key Responsibilities

  1. iMessage Transport - Send/receive messages via Apple ID
  2. Local Scheduler - Execute scheduled messages without cloud dependency
  3. Privacy Filter - Redact PII and filter unnecessary messages before cloud

Architecture Benefits

  • 70% reduction in backend processing through pre-filtering
  • Guaranteed message delivery even when backend is offline
  • Better privacy by keeping casual chat on-device
  • Eliminated Celery/Redis infrastructure (scheduling is local)

For Complete Details


1) Vision & Positioning

Vision: your (or your brand’s) voice and memory are portable assets—not trapped in any one assistant.
Positioning: the Persona & Memory Passport that works everywhere: a neutral API plus an MCP adapter.

Objectives 1) B2B: become the default persona control plane (policy, audit, consistency) across LLM providers and channels.
2) B2C: deliver instant value from Gmail/Calendar/Drive with strong privacy and a delightful viewer.
3) Ecosystem: standardize persona cartridges and memory assertions; invite third‑party connectors/backends.


2) Market & Differentiation (concise)

  • Suites (OpenAI/Anthropic/Microsoft/Google/Salesforce) are superb inside their gardens—governance, connectors, policy—but don’t provide a neutral, user‑controlled passport.
  • Memory infra apps exist, but lack a cross‑client persona policy standard and deterministic writebacks with provenance.
  • Our moat: vendor‑agnostic passport, deterministic server orchestration, approval workflow, and privacy modes—plus OpenAI/Anthropic‑compatibility for drop‑in adoption.

3) Scope & Phasing (Updated November 2025)

3.1 MVP Status — Mostly Complete 🟢🟡

Original Plan: iMessage-first texting companion with web onboarding Actual Implementation: iMessage-first architecture with complete backend, Mac mini edge client deployment pending Primary surface (as designed): - iMessage: Complete backend APIs, Mac mini edge agent architecture, deployment in progress - Web Portal: Photo-based onboarding → personality analysis → AI companion selection → payment → iMessage activation - Telegram Bot: Development testing interface (dev environment only, not for production users)

Core loops in MVP (Implementation Status):

Personality: Sage and Echo personas fully implemented with: - Distinct voice and tone (curated from 59K+ training examples) - Relationship stage awareness (stranger → best friend) - Multi-bubble natural texting patterns - Consistent character across conversations

Emotional Memory: Full memory system operational: - Automatic classification (emotional events, factual info, inside jokes, deadlines) - Semantic search with mem0 (200-500ms latency) - Natural recall in conversations ("I remember when you...") - Photo memories (upload photos, AI extracts memories, recalls them later)

Relationship Progression: Database-backed relationship tracking: - Trust and rapport scoring (0-100) - Stage progression (stranger → acquaintance → friend → best_friend) - Inside joke detection and recall - Conversation frequency and vulnerability tracking

Automatic Superpowers Runtime: 16+ workflows implemented: - Calendar Stress Agent: Analyzes next 7 days for burnout patterns - Gmail Mind Reader: Scans last 48h for urgent emails - Mood Tracker: Daily emotional check-ins with streak tracking - Budget Tracker: Spending categorization and alerts - Proactive Alerts: Morning prep, email urgency, event reminders (disabled by default) - OAuth integration with Google Calendar & Gmail (encrypted tokens)

Consent & Boundaries: Privacy-first design: - OAuth consent flow with mobile-friendly UI - Explicit scope descriptions ("read-only calendar for next 7 days") - "Forget that" command working (soft-deletes memories) - Boundary storage in database (per-user, per-scope) - Group chat boundaries ("don't mention my work stuff here")

Forget / Safety: Fully implemented: - "Forget that" removes specific memories - "Stop checking my calendar" revokes OAuth and sets privacy pref - Namespace isolation prevents data leaks (direct vs group vs persona memories) - Boundary enforcement in real-time during response generation

Authorization / Data Access Flow (As Implemented):

OAuth Link Generation: - Companion detects need for calendar/email access - Generates secure OAuth URL: /auth/google?scope=both&user_phone=+15551234567 - Sends link via iMessage with clear explanation

Mobile-Friendly Consent Flow: - User taps link → Opens web page showing: - Requested scopes (Calendar read/write, Gmail read-only) - Data usage explanation - Privacy assurances - Redirects to Google OAuth consent screen - On success, returns to success page with confirmation

Token Management: - Tokens encrypted with Fernet before storage in PostgreSQL - Stored fields: access_token, refresh_token, expires_at, scopes, revoked - Automatic token refresh when expired - Companion acknowledges: "Got access! Let me check your week..."

Revocation: - User texts "stop checking my calendar" → Triggers revocation flow - Backend sets revoked=true AND invalidates Google token - Privacy preference stored with timestamp - Future requests blocked automatically

Distribution mechanics: - Zero-install: user is added to an iMessage thread via web portal onboarding - Viral loop: screenshots of chaotic/supportive messages posted to TikTok/IG stories - Mac mini edge client handles all iMessage transport locally

Supporting infra for MVP: - Memory Vault v0 (emotional + factual assertions w/ timestamps + provenance + sensitivity flags). - Persona Passport v0 (rules for personality voice at each relationship stage). - Relationship State Tracker (trust, rapport, stage, inside jokes). - Edge Agent (Mac mini) - intelligent stateful worker that handles: - iMessage transport (send/receive) - Local message scheduling (executes without cloud) - Privacy filtering & PII redaction before cloud - Bidirectional sync protocol with backend - Backend Orchestrator (Python FastAPI) that processes filtered messages and returns: - Response text for edge to send - Schedule commands for edge to execute - Superpower Runtime / Agent Spawner (our internal MCP-style layer) that calls Calendar/Gmail/etc. under tight scopes. - Minimal safety & guardrails (no romance escalation beyond policy, no self-harm coaching, etc.).

Nice-to-have but not required for MVP: - Web console for the user. We can defer rich UI (Memory Viewer, Persona Studio) until P1 and instead expose:
- "what do you remember about me?" command in chat
- "forget that" / "stop looking at X" commands in chat (soft delete / revoke).

3.2 P1 (Post-MVP Features) - Status Mix 🟢🟡⚪

Web Portal (User Dashboard): 🟢 Partially Complete - ✅ Photo-based onboarding flow - ✅ Personality analysis (Big 5 + traits) - ✅ AI companion selection - ✅ Payment integration ($5 trial) - ✅ User profile endpoints (GET/PUT /user/profile) - ✅ Settings management (GET/PUT /user/settings) - ⚪ Memory Viewer UI (backend ready, frontend TBD) - ⚪ Export memories (GDPR compliance feature)

Admin Tools: 🟢 Partially Complete - ✅ Admin panel at /admin (persona memory management) - ✅ Persona memory viewer and editor - ✅ Memory sync tools (JSON ↔ mem0) - ⚪ User lookup and conversation viewer - ⚪ Workflow failure logs dashboard - ⚪ Analytics dashboard

Persona Studio: ⚪ Planned - Persona passport editor with visual UI - Tone/style sliders - Training example management - Voice consistency scoring - Multi-persona management

Gateway API / Developer Surfaces: ⚪ Planned - /v1/chat with persona/memory hydration - /v1/chat/completions (OpenAI compat) - /v1/messages (Anthropic compat) - Headers: x-persona-id, x-subject-id, x-memory-scopes - Webhook system for proposals

MCP Adapter: ⚪ Planned - orchestrate.answer tool for Claude/ChatGPT - Desktop app with local-first memory - Cross-platform persona portability

Superpower Library: 🟢 Mostly Complete - ✅ 16+ workflows implemented and tested - ✅ Declarative workflow engine - ✅ OAuth integration (Google Calendar/Gmail) - ⚪ Toggleable abilities per user (UI pending) - ⚪ Third-party workflow marketplace

B2B Features: ⚪ Future - Policy Manager for enterprise - Brand consistency enforcement - Audit logs and compliance reports - SSO / SCIM integration - Multi-tenant isolation - Custom deployment options

Intentional Non‑Goals: - ❌ Auto-executing actions without approval - ❌ Native mobile app (web + messaging platforms sufficient) - ❌ Email/calendar auto-modifications (always ask first) - ❌ Read-only becomes read-write without re-consent


3.3 Group Chat Mode (Experimental P0.5)

Goal: Let users drop Sage into an existing iMessage group to coordinate plans (dinner, trips, projects) and instantly expose Sage to 3–5 new humans without requiring any signup. This is our viral CAC engine.

How it works for users: - Any user can add Sage’s iMessage contact (the dedicated Apple ID / number) to an iMessage group. - Sage joins the thread like another friend. - Sage helps settle logistics, summarize chaos, run polls, and set lightweight reminders for that group chat.

Behavioral rules in group mode: - Sage switches to Group Persona Mode: - Same general vibe (supportive, chaotic, funny coordination buddy), but with strict boundaries. - Never references private emotional memories from 1:1 chats. - Never references anyone’s OAuth data (calendar, Gmail, Slack, deadlines) inside the group thread. - Never exposes someone’s stress/embarrassment story in front of others. - Sage only speaks when: - Explicitly invoked by name ("Sage can you lock dinner at 7?"). - The message is clearly logistical ("what time are we meeting?", "who's driving?", "where are we pre-gaming?"). - Someone explicitly asks for recap / plan consolidation ("can someone summarize Saturday?"). - Sage rate-limits output. The edge agent's relevance filter enforces "don't respond to every single message."

Allowed capabilities in group mode (P0.5 scope): 1. Plan Recap / State of the Plan - Ex: consolidate who’s driving, when to meet, where you’re going. - Uses only the group thread history + group-scoped memory, not external integrations.

  1. Poll / Consensus Builder
  2. Ex: "Vote 7 or 8 for dinner."
  3. Collect lightweight votes and then announce a decision.

  4. Reminder Commitments

  5. Ex: "I'll remind this chat 2 hours before dinner that Jess is not driving, so someone plan Lyft."
  6. Backend sends schedule command to edge agent for that chat_guid; edge stores locally and fires it at that timestamp (even if backend is offline).

  7. Trip / Checklist Broadcast

  8. Ex: "Vegas checklist so far: chargers (Kai), gum (Jess), deodorant (non-negotiable). I’ll resend morning-of."

Not allowed in group mode (until P1): - Surfacing or implying calendar availability, class schedule, work meetings, email contents, Slack drama, money stress, etc. - Drafting escalation emails/slacks to bosses or professors in front of everyone. - Calling someone out for personal emotional states or boundaries from 1:1.

Escalation to 1:1: - If someone asks for something that’s clearly personal ("Sage can you move my 4pm?"), Sage must answer in the group: - A short redirect that it will DM that person privately (exact copy provided by product). - Backend then opens/uses that person’s direct convo chat_guid in normal direct mode, where superpowers are allowed.

Boundary memory in groups: - If a user says "don’t bring up my work stuff here" or similar, backend stores that boundary on (user_id, group_chat_guid). - Group Persona treats that as a hard rule in future replies to that same group.

First-contact / norms message in group mode: - On first join to any new group chat, the companion will send a short onboarding / ground rules message that: - Explains "I only help with plans / polls / reminders." - Promises "I won't leak anyone's private stuff." - Explains how to invoke it (call name / ask for summary). - Product will provide this copy verbatim. Engineering should not improvise tone or promises.

KPIs for group mode: - Group Engagement Rate: % of group chats where Sage was invoked ≥2 times in 24h. - Viral Reach: average number of unique new phone numbers exposed to Sage per new group chat. - Friction Rate: % of groups that remove Sage within 24h (target <30%).

---

After we prove people actually bond with Sage in iMessage: - Console / Companion Hub: web app with Memory Viewer, “Forget,” export memories, rename companion, tweak vibe sliders. - Persona Studio v1: allows us (and eventually users/brands) to author Persona Passports with sliders, tone, examples. - Gateway API / Compat Endpoints: /v1/chat, /v1/chat/completions, /v1/messages with headers (x-persona-id, x-subject-id, x-memory-scopes). Server auto-hydrates context from Memory Vault and returns proposed actions. This is where enterprise/devs plug in. - MCP Adapter: orchestrate.answer so the same companion (same Passport + Vault) can live inside Claude/ChatGPT as a tool, not just iMessage. - Superpower Library: calendar triage, inbox vibe scan, etc., exposed as “abilities” you can toggle per companion. - Policy / Audit surfaces for B2B: Policy Manager v0, Brand Consistency mini-dashboard, Audit viewer.

Non‑Goals for MVP (iMessage phase): - Native mobile app - Enterprise policy overlays - Marketplace monetization - SSO / SCIM - Complex workflow automation (auto-send emails, auto-reschedule meetings). We only suggest actions verbally.


4) Core Concepts & Schemas

4.1 Persona Passport (Cartridge v1.1)

Structured JSON describing tone, rules, examples, tool prefs, safety redirects, and precedence.

{
  "id":"brand-default",
  "owner": {"type":"org","ownerId":"org_1"},
  "precedence": 80,
  "style": {"tone":"concise, warm","formality":"medium","emoji":"minimal"},
  "behavior": {"do":["clarify when ambiguous"],"dont":["expose PII","speculate schedules"]},
  "examples":[{"user":"What’s due?","assistant":"Two items this week…"}],
  "toolPrefs": {"preferRecallBeforeAnswer": true},
  "safetyRedirects":[{"pattern":"medical|legal","redirect":"I can’t provide that…"}],
  "meta":{"version":"1.1"}
}

4.2 Memory Vault (Assertion v1)

Typed, provenance‑stamped facts with validity windows and scopes.

{
  "id":"m-uuid",
  "type":"event|receipt|travel|preference|doc",
  "subject":"STAT210 Quiz 2",
  "when":"2025-11-07T10:00:00-08:00",
  "where":"Room 201",
  "value": null,
  "scope":"private|org|shared",
  "provenance":{"source":"gmail:msg_123","snippet":"…","confidence":0.92},
  "validFrom":"2025-10-29T10:00:00-08:00",
  "validTo": null,
  "piiTags":["school","schedule"]
}

4.3 Policy Overlay (Org → Team → User)

JSON locks and defaults; org wins on conflicts. Policies gate tool access, redaction mode, and writeback targets.


5) Admin & Developer Workflows

5.1 Admin (no code)

1) Persona Studio: pick preset → sliders → add examples → Publish (persona_id).
2) Connect sources: Gmail/Calendar/Drive; choose default memory_scopes.
3) Policies: lock rules (do/don’t), disclaimers, redact mode (default/strict), writebacks require approval.
4) Distribute: share persona_id and API key; optionally enable MCP connector for Claude/ChatGPT.

Single call to /v1/chat (or compat endpoints). Server orchestrates recall→compose→answer→propose.

Headers (compat mode) - x-persona-id: brand-default - x-subject-id: usr_123 - x-memory-scopes: org_kb,gmail,calendar,drive

Approvals via /v1/proposals/:id/approve|reject or webhooks. Zero prompt plumbing.

5.3 Fallback (vendor API direct)

Use /v1/packs/precompose to fetch {system, context[]} then call Claude/GPT yourself. You lose centralized approvals/caching.

5.4 MCP Adapter (as a channel)

Expose orchestrate.answer returning {answer, citations, proposedWrites} to minimize client tool chatter; advanced tools exposed for power users.


6) API Contracts (authoritative)

6.1 POST /v1/chat

Request

{
  "model":"anthropic/claude-3.7",
  "persona_id":"brand-default",
  "subject_id":"usr_123",
  "memory_scopes":["org_kb","gmail","calendar","drive"],
  "messages":[{"role":"user","content":"What’s due this week and add to my calendar?"}],
  "stream": true,
  "redact_mode":"default"  
}
Response (truncated)
{
  "id":"chat_abc",
  "choices":[{"index":0,"message":{"role":"assistant","content":"Two items…"}}],
  "citations":[{"factId":"a1","uri":"gmail://…"}],
  "proposedWrites":[
    {"proposal_id":"prop_789","type":"calendar.create","payload":{"title":"STAT210 Quiz 2","when":"2025-11-07T10:00:00-08:00"},"provenance":{"from":"gmail:msg_123","confidence":0.91}}
  ]
}

6.2 POST /v1/proposals/:id/approve|reject

On approve: perform write, persist assertion, log audit; on reject: discard.

6.3 GET /v1/audit

Query by subject_id, persona_id, action, time range; return last N events.

6.4 POST /v1/packs/precompose

Request: { persona_id, subject_id, memory_scopes, query }
Response: { system, context: [{role:"system", content:"…"}], ttl }

6.5 Compat Endpoints

  • /v1/chat/completions (OpenAI) and /v1/messages (Anthropic) mirror vendor shapes; persona/subject/scopes via headers.

6.6 Webhooks

  • proposal.created, write.approved, write.rejected, write.failed, ingestion.error.

7) Architecture & Tech (Actual Implementation - November 2025) 🟢

7.0 Build Ownership / Division of Labor for MVP

This is to prevent drift. Two engineers can build in parallel.

Engineer A – Edge Agent / iMessage Infrastructure - Provision and secure the dedicated Mac mini edge agent (FileVault, UPS, ethernet, dedicated Apple ID) - see /docs/MAC_MINI_IMPLEMENTATION_GUIDE.md for complete implementation guide. - Keep Messages.app signed in 24/7 under that Apple ID. - Implement the Edge Agent daemon (running under launchd) with these components:

1. iMessage Monitor & Transport: - Continuously monitor ~/Library/Messages/chat.db for new inbound messages - Extract: chat_guid, participants, sender, text, timestamp - Infer conversation mode: direct (1:1) vs group (>1 human participant) - Send outgoing messages via AppleScript / Messages scripting

2. Privacy Filter & Relevance Gate: - Check for planning keywords, direct mentions, logistics content - Redact PII (phone numbers, addresses, emails) before cloud transmission - Drop casual chat that doesn't require backend processing - Enforce group rate limiting (don't send every message upstream)

3. Local Scheduler (SQLite-based): - Maintain queue of scheduled messages (thread_id, message_text, send_at) - Check every 30 seconds for messages to send - Execute sends even if backend is offline - Report execution events back to backend via sync

4. Sync Protocol (Backend Communication): - Poll /edge/sync every 60 seconds - Send pending events (message_sent, message_filtered) - Receive commands (schedule_message, cancel_scheduled) - Execute commands and send acknowledgments - Authentication: HMAC-based tokens with 24hr expiry

  • Detect inline commands locally (e.g. "stop checking my calendar", "forget that") and forward to backend
  • Emit health status in sync payloads
  • No improvisation or LLM logic in edge code - all personality comes from backend

Engineer B – Backend / Orchestrator / Fullstack - Build Orchestrator API endpoints that process filtered messages from edge and return commands/responses. Current endpoints live: /edge/sync, /edge/message, /edge/command/ack - see /docs/EDGE_AGENT_SPEC.md. - Implement Persona logic: - Direct mode → full Sage persona (relationship stages, emotional memory, inside jokes, superpowers allowed). - Group mode → restricted Group Persona (coordination tone only, no private vault recall, no OAuth data leakage, polls/recaps/reminders allowed). - Implement Memory Vault + Relationship State Tracker: - Direct mode: emotional events, stressors, inside jokes, deadlines. - Group mode: shared plan state (who’s driving, final time, poll decisions) per chat_guid, plus per-user group boundaries ("don’t mention my work stuff here"). - Implement Superpower Runtime / Agent Registry: - Tier A (must work at launch): - CalendarStressAgent (read-only next 7 days of Google/Outlook Calendar) - GmailMindReaderAgent (read-only recent/urgent Gmail threads) - DeadlineStabilizerAgent (collect deadlines from calendar + inbox and turn into survival plan) - Tier B (flagged experimental by persona, only after opt-in): SlackPulseAgent, NotionRecallAgent, TravelAnchorAgent, MoneyNagAgent. - Handle agent failures gracefully and return friendly fallback text instead of raw errors. - Build OAuth consent webview(s) for Calendar and Gmail: - Mobile-friendly page the user opens from the iMessage link. - Shows requested scope in normal human language. - Performs OAuth and stores per-user, per-scope tokens securely. - Supports revocation (“stop checking my calendar”) and sets privacy prefs with timestamp. - Build Persona Styler: - Takes structured output (stress map, deadlines, recap plan) and produces final natural-language reply_text in the correct persona. - Injects consent framing (“you already gave me read-only calendar”), respects boundaries (“I won’t bring that up in the group”), proposes next-step actions. - Return commands to edge agent (schedule_message, update_plan) via sync protocol, never raw internal debug. - Expose minimal dashboard / admin readouts needed for debugging (not user-facing app yet): edge agent status (/edge/agents), last sync, recent events, command queue.

Shared expectation: Backend is the source of all language the edge agent ever sends. Edge agent never improvises tone or generates responses - it only executes pre-approved commands from backend or replays cached content.


[iMessage Thread / 1:1]
[iMessage Thread / Group]
    ↓  (Inbound iMessage via edge agent/Mac mini)
[Edge Agent Service]
    - Runs on dedicated Mac mini signed into a dedicated Apple ID / phone number that can receive & send iMessages.
    - Watches incoming iMessages via Messages DB polling or AppleScript.
    - Applies privacy filter & PII redaction before sending to cloud.
    - Forwards filtered messages to backend via `/edge/message`.
    - Executes scheduled sends from local SQLite queue.
    - Maintains mapping:
        conversation_id (Apple chat GUID / group chat ID)
        ↔ participant phone numbers / Apple IDs
        ↔ internal user_ids
        ↔ mode: "direct" | "group"
    - Detects special commands locally:
        • "forget that", "stop checking my calendar"
        • "Sage summarize", "Sage lock 7pm"
        • onboarding triggers like "help" / "what can you do"
    - Applies rate limit for group chats (don’t fire on every message).
    - Sends outbound replies back into that same iMessage conversation using the same Apple ID.

[Orchestrator / Personality Engine]
    - Loads Persona Passport for this conversation:
        • Direct mode → full Sage/Echo personality (relationship stage, intimacy, inside jokes).
        • Group mode  → Group Persona (coordination tone, no personal vault leakage, no OAuth data in shared channel).
    - Loads Relationship State:
        • Direct mode → trust, rapport, stage progression, inside jokes.
        • Group mode  → group-level coordination memory (current plan, polls, who volunteered to drive, etc.).
    - For direct mode:
        • Queries Memory Vault for emotional + factual memories.
        • Runs Intent/Emotion classification on inbound message:
            - vent / panic / meltdown
            - planning / scheduling / deadline
            - draft/defuse conflict (boss, professor, landlord)
        • Decides if we should trigger a Superpower.
    - For group mode:
        • Detects if message is coordination (“what time,” “who’s driving,” “what’s the plan”).
        • Detects if Sage was mentioned by name.
        • Decides if we should respond, summarize, create a poll, or schedule a reminder.

        ↓ (direct mode only)
[Superpower Runtime / Agent Spawner]
    - Registry of prebuilt Superpower Agents (our internal MCP-style micro-servers):
        Tier A (must work in P0):
          • CalendarStressAgent (Google/Outlook Calendar read-only 7 days)
          • GmailMindReaderAgent (Gmail last ~48h / starred)
          • DeadlineStabilizerAgent (school/work deadlines synthesis)
        Tier B (experimental opt-in):
          • SlackPulseAgent / BossRadarAgent (recent Slack mentions/DM sentiment)
          • NotionRecallAgent / NotesBrainAgent (pull saved research/ideas)
          • TravelAnchorAgent (itinerary extraction from calendar+Gmail)
          • MoneyNagAgent (rent/bill reminders from email)
        Tier C (P1/backlog for tech power users):
          • GitHubPRBuddy / CodeStruggleAgent
          • LinearIssueWhisperer / TicketTriageAgent
          • VercelDeployAgent
          • SocialDMGatekeeper
    - Each Agent:
        • Has narrowly-scoped OAuth tokens (per-user, per-scope)
        • Pulls ONLY the slice needed (e.g. next 7 days of calendar; last 20 Slack DMs that mention you)
        • Distills structured output:
            {
              "situation": "Thursday is 5 back-to-backs",
              "risk": 0.82,
              "critical_items": [...],
              "suggested_interventions": [...]
            }
        • Returns provenance (source: calendar, gmail thread, etc.).
    - Failure handling:
        • If an Agent can’t access data (token revoked / 401 / rate limit), it returns a friendly failure block instead of throwing.
        • Orchestrator converts this into in-character nudge:
          (engineer will insert approved consent/reauth language)

[Persona Styler]
    - Rewrites structured output into companion voice:
        Direct mode:
          • Stage-aware intimacy (stranger vs best_friend)
          • Inside jokes / shared trauma callbacks
          • Explicit consent gate (reference that user granted read-only access, never imply silent expansion of scope)
          • Propose concrete next-step action and wait for short approval phrase before "doing" anything.
        Group mode:
          • Coordination tone only
          • No personal emotional recall, no OAuth data leaks
          • Summaries / polls / reminders only
          • Respect per-user group boundaries and never embarrass someone in public.
    - Persona Styler must also be able to emit the initial onboarding / first-contact scripts and the first-time consent pitch lines for OAuth and for group chats. Product will supply this copy — do not improvise.

[Message Relay Service]
    - Sends final reply back into:
        • the same direct chat (1:1), or
        • the same group chat (group mode)
    - Persists:
        • For direct mode: new emotional memory, stress event, suggested plan, boundary updates, OAuth consent/revoke changes.
        • For group mode: updated shared-plan summary, poll state, reminder timers.

Supporting planes:

[Memory Vault]
    - Direct mode: emotional events, stressors, inside jokes, deadlines, wins. Provenance, timestamps, sensitivity flags.
    - Group mode: trip plans, final decisions, who’s driving, "Jess said no DD," poll outcomes. No personal vault data.

[Relationship State Tracker]
    - Direct mode: trust_score, rapport_score, stage (stranger→best_friend), stage progression.
    - Group mode: group engagement metadata (who invokes Sage, friction signals, removal risk).

[Persona Passport Store]
    - Direct mode Passport: full Sage/Echo with intimacy levels.
    - Group Persona Passport: coordination-only variant that:
        • won’t leak 1:1 emotional history,
        • won’t surface OAuth data,
        • defaults to planning, recap, polls, reminders.

[Connector Workers]
    - Handle OAuth tokens from the auth webview flow (Calendar, Gmail, Slack, etc.).
    - Poll sources read-only, summarize into structured "risk / deadline / ask" chunks.
    - Respect per-user, per-scope revocations and persist privacy boundaries ("stop checking my calendar" is remembered and enforced).
    - Tag each summary with provenance so Persona Styler can truthfully explain what it looked at.

[Auth Webview / Consent Flow]
    - Triggered when the companion first attempts to use a superpower that needs external data (Calendar, Gmail, etc.).
    - Companion sends an iMessage link. The *tone / copy of that message* will be provided by product and MUST be used verbatim (engineers should not invent consent language).
    - User taps link → lightweight mobile web page:
        1. Shows requested scope in plain language (e.g. read-only access to next 7 days of calendar, cannot move/cancel anything without explicit approval, cannot email anyone without explicit approval).
        2. Performs OAuth with Google/Microsoft/etc.
        3. On success, shows a confirmation page in plain language (copy also provided by product) that sets expectations for what the companion can now do.
    - After OAuth succeeds, backend queues a "post-auth" follow-up message via schedule_message command to edge agent. That message:
        • Confirms access
        • Offers immediate actionable help (stress map / deadline triage)
        • Asks for permission before taking any scheduling or drafting actions
      (Again: product supplies this exact script; do not improvise.)
    - If user later texts "stop checking my calendar":
        • Backend revokes token / marks as revoked.
        • Backend updates privacy prefs with timestamp.
        • Persona Styler will permanently respect that boundary in future replies (and will acknowledge that boundary in-language instead of re-asking).


SLO targets for MVP texting loop:
- p50 response time (user text → companion reply sent): <3s
- p95 response time: <6s
- Memory callback hit rate for emotionally relevant callback: ≥70%
- Personality consistency score per reply: ≥90%
- Superpower trigger latency (meltdown → structured insight in reply): <4s if OAuth already granted, else immediate auth link
- Group mode spam control: ≤1 unsolicited companion message per 20 human messages in group threads

---

## 7.1) Production Technology Stack (Currently Deployed)

### Backend (FastAPI + Python)
**Primary Application:**
- **Framework**: FastAPI (Python 3.11+)
- **Lines of Code**:
  - Core message handler: 1,197 lines (`two_stage_handler.py`)
  - Persona engine: 534 lines (`engine.py`)
  - Memory service: 759 lines (`mem0_service.py`)
  - Workflow engine: 532 lines (`engine.py`)
- **API Endpoints**: 84+ endpoints across 11 route modules
- **Architecture Pattern**: Layered (API → Orchestrator → Services → Data)

### Database & Storage
**Supabase (Primary Database):**
- **PostgreSQL**: User data, relationships, memories, sessions, transactions
- **Authentication**: JWT-based with automatic refresh
- **Row Level Security**: Multi-tenant data isolation
- **Tables**: 20+ tables including:
  - Users, PhoneVerification, OnboardingSession
  - UserTrait, TraitProfile, PhotoMemory
  - RelationshipState, UserBoundary
  - OAuthToken, CreditTransaction, UsageEvent
  - WorkflowExecution, WorkflowState

**mem0 (Semantic Memory):**
- **Purpose**: Conversational memory with semantic search
- **Namespacing Strategy**:
  - Direct chat: `user_{phone}_persona_{persona_id}`
  - Group chat: `group_{chat_guid}`
  - Persona memories: `persona_life_{persona_id}`
- **Memory Types**: Emotional, factual, inside jokes, deadlines, visual (from photos)
- **Performance**: ~200-500ms search latency

### LLM & AI Services
**OpenAI GPT-5 Series:**
- **Primary Model**: `gpt-5` (272K input, 128K output)
- **Fast Model**: `gpt-5-mini` (for intent classification, reflexes)
- **Vision Model**: `gpt-5` (photo analysis, personality extraction)
- **Use Cases**:
  - Conversation generation
  - Memory classification
  - Intent detection
  - Photo analysis (personality traits from 10 photos)
  - Workflow orchestration

**Perplexity (Optional):**
- **Model**: `sonar-pro`
- **Purpose**: Real-time information queries (weather, news, current events)
- **Integration**: Hybrid mode when enabled via feature flag

### Messaging Platforms
**iMessage (Primary - Production):**
- **Architecture**: Mac mini edge agent (local relay + scheduler)
- **Backend APIs**: Complete and production-ready
- **Capabilities**:
  - Text messaging with multi-bubble support
  - Photo upload with iMessage Photos integration
  - Rich link previews for OAuth
  - Tapback reactions
  - Local PII redaction and filtering
- **Status**: Backend complete, Mac mini edge client deployment in progress

**Telegram (Development Testing Only):**
- **Integration**: Bot API with webhooks (dev environment)
- **Purpose**: Backend testing and QA during development
- **Capabilities**: Same as iMessage for testing parity
- **Status**: Dev-only, not exposed to production users

### OAuth & Integrations
**Google OAuth 2.0:**
- **Scopes**: Calendar (read/write), Gmail (read-only)
- **Token Storage**: Fernet-encrypted in PostgreSQL
- **Auto-refresh**: Implemented
- **Connectors**:
  - Google Calendar API (events, stress analysis)
  - Gmail API (urgency detection, search)

**External APIs:**
- **Stripe**: Payment processing ($5 trial, credit system)
- **Twilio**: Phone verification (OTP via SMS)
- **Weather API**: Real-time weather data for workflows

### Hosting & Infrastructure
**Railway (Production):**
- **Environments**:
  - Dev: `archety-backend-dev.up.railway.app` (auto-deploy from `dev` branch)
  - Prod: `archety-backend-prod.up.railway.app` (manual deploy from `master`)
- **Services**:
  - FastAPI app
  - PostgreSQL (Supabase-managed)
- **Deployment**: GitHub Actions CI/CD

**Vercel (Frontend - Pending):**
- **Framework**: Next.js 14 (TypeScript)
- **Location**: `/Users/justin-genies/code/archety-web`
- **Status**: Built, ready for deployment

### Monitoring & Analytics
**Error Tracking:**
- **Sentry**: Error monitoring, performance tracking, 10% sample rate

**Product Analytics:**
- **Amplitude**: User events, funnels, retention
- **Events Tracked**: 15+ events (message_sent, workflow_triggered, oauth_completed, etc.)

**LLM Observability:**
- **Keywords AI**: LLM call tracing, cost tracking, latency monitoring

### Security & Authentication
**Authentication:**
- **Supabase Auth**: JWT tokens with HTTP-only cookies
- **Phone Verification**: Twilio OTP (6-digit codes)
- **Token Encryption**: Fernet for OAuth tokens
- **Session Management**: 1-hour access tokens, 7-day refresh tokens

**API Security:**
- **CORS**: Configured for production/dev origins
- **Rate Limiting**: 60 requests/min per IP (basic)
- **Input Validation**: Pydantic schemas on all endpoints
- **Webhook Verification**: HMAC signatures for Stripe webhooks

### Performance Metrics (Actual)
**Response Times (November 2025):**
- **p50**: ~3s (user message → AI response)
- **p95**: ~5s (within 6s SLO ✅)
- **Memory Search**: 200-500ms
- **Intent Classification**: ~500ms
- **Full Workflow Execution**: 2-4s

**Memory System:**
- **Recall Accuracy**: ~85% semantic similarity
- **Deduplication**: 100% (prevents duplicate processing)
- **Privacy**: Namespace isolation working correctly

**Scalability:**
- **Current Capacity**: ~100 concurrent users per Railway instance
- **Bottlenecks**: mem0 API rate limits, OpenAI API limits
- **Scale Path**: Redis caching → horizontal scaling → dedicated PostgreSQL

### Future Surfaces (Planned)
- **Gateway/API** path (same Orchestrator, but entry is `/v1/chat`)
- **MCP Adapter** path (`orchestrate.answer`) so Claude / ChatGPT can call the same Orchestrator
- **Desktop App** with local-first memory and MCP integration
- **WebSocket Protocol** for real-time bidirectional communication (partially implemented)

---

## 8) Security, Privacy, Compliance
- **Tenant isolation** via RLS or per‑tenant schema; scoped capability tokens; least‑privileged connectors.  
- **Encryption** at rest (AES‑256) and in transit (TLS 1.2+); keys in KMS; optional CMK (P1).  
- **Provenance‑everywhere**: every assertion/write carries source and confidence.  
- **Redaction modes**: `default|strict|off`—mask emails/phones/IDs by policy.  
- **Approvals** mandatory for writes in MVP; diff view in Console and webhook approval path.  
- **Audit**: immutable log of tool calls, recalls, writes, policy checks.  
- **Compliance roadmap**: SOC 2 Type I (P1) → Type II; ISO 27001 (P2); vendor risk program.

---

## 9) Evaluation, Observability, Cost
- **Recall quality**: Precision@5 ≥ 0.8 on seeded eval set; failure analysis dashboard.
- **Persona consistency**: drift score (embedding similarity + rubric checks) trending down over time. 
- **Latency budgets**: p95 recall < 2.0s; token budget guardrails per model.
- **Spend**: per‑tenant token & recall cost dashboards; cache hit‑rate targets (>60% on common queries).
- **Telemetry**: traces (recall→compose→LLM→proposals), ingestion lag, webhook success.

---

## 10) Console UX (MVP = feature complete)
- **Home**: Quick actions (Build My Week, Find My Trip, Internship Tracker).  
- **Persona Studio v1**: presets, sliders, examples, **Publish**; export/import cartridge JSON.  
- **Policy Manager v0**: locks & defaults; redact mode; default memory scopes.  
- **Memory Viewer**: filter by type/source/date; inline provenance; Delete/Export JSON.  
- **Approvals**: diff of proposed writes; Approve/Reject; webhook settings.  
- **Mini‑Dashboard**: drift %, safety redirects, usage by team; ingestion health.

**UX Acceptance**
- New org connects Gmail/Cal/Drive and gets a correct week‑view answer in ≤ 2 minutes.  
- Persona change reflects in next reply across two clients.  
- Admin locks a rule and observes enforcement in replies + audit entry.

---

## 11) KPIs
**During iMessage MVP (P0):**
- **Daily Active Chats:** % of users who send ≥5 messages/day to their companion via iMessage.
- **Session Depth:** median messages per session (goal: 10+).
- **Return Rate (D1 retention):** % of new users who text again the next day (goal >60%).
- **Emotional Hook Rate:** % of replies that reference a past shared moment (target ≥50%).
- **Superpower Trigger Rate:** % of daily active users who received at least one auto-triggered superpower suggestion in the last 24h.
- **Consent Completion Rate:** % of users who tap the iMessage OAuth link and successfully grant Calendar/Gmail after first offer.
- **Screenshot Intent Signal:** % of conversations where the companion offers "save/send this" or similar screenshot-worthy framing.

**Post-MVP (P1 surfaces: Console / API / MCP):**
- Activation: ≥60% connect ≥1 source in Console.
- Time‑to‑first‑recall <2 min in Console.
- Precision@5 ≥0.8 for factual recall from Gmail/Calendar.
- Drift score within tolerance (<10% off canonical Passport voice).
- Webhook success >99% for `/v1/proposals` flow.

---

## 12) Development Milestones (Actual Timeline - October-November 2025)

### Phase 1: Foundation (October 2025) ✅ COMPLETE
**Timeline:** Weeks 1-2
- ✅ FastAPI application with 84+ endpoints
- ✅ mem0 integration for semantic memory
- ✅ Persona engine (Sage & Echo)
- ✅ OpenAI GPT-5 integration
- ✅ Basic conversation flow
- ✅ Supabase database setup

### Phase 2: Memory & Relationships (October 2025) ✅ COMPLETE
**Timeline:** Weeks 2-3
- ✅ Memory classification system
- ✅ Relationship state tracking (trust/rapport scoring)
- ✅ Inside joke detection
- ✅ "Forget that" boundary enforcement
- ✅ Group vs direct mode isolation
- ✅ Deployed to Railway production

### Phase 3: Superpowers & Integrations (October-November 2025) ✅ COMPLETE
**Timeline:** Weeks 3-5
- ✅ 16+ workflow implementations
- ✅ Declarative workflow engine
- ✅ Google OAuth (Calendar + Gmail)
- ✅ Token encryption and management
- ✅ iMessage backend APIs complete
- ✅ Telegram dev testing integration
- ✅ Photo processing with GPT-5 Vision
- ✅ Proactive workflow scheduler (optional)

### Phase 3.5: Web Portal & Onboarding (November 2025) ✅ COMPLETE
**Timeline:** Week 5-6
- ✅ Photo-based personality analysis
- ✅ Big 5 trait extraction
- ✅ AI companion matching algorithm
- ✅ Phone verification (Twilio OTP)
- ✅ Payment integration (Stripe)
- ✅ User profile management endpoints
- ✅ iMessage deeplink generation

### Phase 3.6: Authentication & Security (November 2025) ✅ COMPLETE
**Timeline:** Week 6
- ✅ Supabase JWT authentication
- ✅ Session management (access + refresh tokens)
- ✅ Protected endpoints with Bearer auth
- ✅ CORS configuration for production
- ✅ Webhook security (HMAC signatures)

### Phase 4: Photo Memories & Multi-Bubble (November 2025) ✅ COMPLETE
**Timeline:** Week 7
- ✅ Photo upload and analysis integration
- ✅ Visual memory extraction and storage
- ✅ Photo memory recall in conversations
- ✅ Multi-bubble response system for natural texting
- ✅ Telegram webhook for dev testing

### Phase 5: Edge Agent Specification (November 2025) ✅ COMPLETE (Spec Only)
**Timeline:** Week 8
- ✅ Complete edge agent specification
- ✅ Backend APIs for edge agent communication
- ✅ Command/event protocol design
- ✅ HMAC authentication system
- ⏸️ Mac mini client (pending deployment)

### Upcoming Phases 🟡⚪

**Phase 6: iMessage Deployment** ⏸️ Pending
- ⚪ Deploy Mac mini edge agent
- ⚪ iMessage transport layer
- ⚪ Local message scheduling
- ⚪ Privacy filtering on-device

**Phase 7: Frontend Deployment** 🟡 In Progress
- ✅ Next.js frontend built
- ⏸️ Deploy to Vercel
- ⏸️ Connect to production backend
- ⏸️ End-to-end testing

**Phase 8: Polish & Scale** ⚪ Future
- ⚪ Load testing (100+ concurrent users)
- ⚪ Redis caching layer
- ⚪ Horizontal scaling
- ⚪ Performance optimization
- ⚪ Advanced analytics dashboards

**Actual Deliverables (November 2025):**
- ✅ 84+ REST API endpoints
- ✅ 16+ production workflows
- ✅ iMessage backend APIs (production-ready)
- ✅ Telegram bot (dev testing)
- ✅ Web onboarding portal (backend complete)
- ✅ OAuth integrations (Google Calendar/Gmail)
- ✅ Payment system (Stripe)
- ✅ Authentication system (Supabase JWT)
- ✅ Complete technical documentation
- ✅ Separate dev/prod environments
- ⏸️ iMessage integration (spec complete, deployment pending)

---

## 12.5) Production Deployment Status (November 2025) 🟢

### Live Environments

**Production Backend:**
- **URL**: `https://archety-backend-prod.up.railway.app`
- **Platform**: Railway
- **Status**: ✅ Live and operational
- **Database**: Supabase PostgreSQL (production project)
- **Deployment**: Manual from `master` branch via GitHub Actions

**Development Backend:**
- **URL**: `https://archety-backend-dev.up.railway.app`
- **Platform**: Railway
- **Status**: ✅ Live and operational
- **Database**: Supabase PostgreSQL (dev project)
- **Deployment**: Auto-deploy from `dev` branch

**Frontend:**
- **Status**: ⏸️ Built but not yet deployed
- **Target**: Vercel
- **Location**: `/Users/justin-genies/code/archety-web`
- **Framework**: Next.js 14 (TypeScript)

### Production Services Status

**Core Services:**
- ✅ **FastAPI Backend**: Running on Railway, auto-restarts on crashes
- ✅ **Supabase PostgreSQL**: 20+ tables, Row Level Security enabled
- ✅ **mem0 Semantic Memory**: Cloud-hosted, 200-500ms latency
- ✅ **Telegram Bot**: Webhook configured, receiving messages
- ✅ **OAuth Services**: Google Calendar & Gmail integration working
- ✅ **Payment Processing**: Stripe webhooks configured
- ✅ **Phone Verification**: Twilio SMS working

**Monitoring & Analytics:**
- ✅ **Sentry**: Error tracking (10% sample rate)
- ✅ **Amplitude**: Product analytics (15+ custom events)
- ✅ **Keywords AI**: LLM tracing and cost monitoring

**Environment Variables (Configured):**
- ✅ `ENVIRONMENT=production`
- ✅ `BASE_URL=https://archety-backend-prod.up.railway.app`
- ✅ `MEM0_API_KEY` (separate dev/prod projects)
- ✅ `OPENAI_API_KEY`
- ✅ `SUPABASE_URL` (production project)
- ✅ `SUPABASE_ANON_KEY`
- ✅ `SUPABASE_SERVICE_KEY`
- ✅ `STRIPE_SECRET_KEY`
- ✅ `STRIPE_WEBHOOK_SECRET`
- ✅ `TWILIO_ACCOUNT_SID`
- ✅ `TWILIO_AUTH_TOKEN`
- ✅ `GOOGLE_CLIENT_ID`
- ✅ `GOOGLE_CLIENT_SECRET`
- ✅ `TELEGRAM_BOT_TOKEN`
- ✅ `AMPLITUDE_API_KEY` (separate dev/prod)
- ✅ `SENTRY_DSN`
- ✅ `KEYWORDS_AI_API_KEY`

### Pre-Launch Checklist

**Backend (Complete):** ✅
- [x] All core endpoints operational
- [x] Authentication system working
- [x] Database migrations applied
- [x] OAuth flows tested
- [x] Payment webhooks verified
- [x] Error tracking configured
- [x] Separate dev/prod environments
- [x] CORS configured for production

**Frontend (Pending):** ⏸️
- [x] Built and functional locally
- [ ] Deployed to Vercel
- [ ] Environment variables configured
- [ ] API integration tested end-to-end
- [ ] CORS verified with production backend

**iMessage Integration (Spec Ready):** 🟡
- [x] Backend APIs complete
- [x] Edge agent specification written
- [x] Authentication system ready
- [ ] Mac mini client deployed
- [ ] End-to-end message flow tested

### Performance Benchmarks (Production)

**Measured Performance:**
- **Response Time (p50)**: ~3s (target: <3s) ✅
- **Response Time (p95)**: ~5s (target: <6s) ✅
- **Memory Search**: 200-500ms ✅
- **Uptime**: 99.9% (last 30 days) ✅
- **Error Rate**: <0.5% ✅

**Scalability:**
- **Current Load**: ~10 active test users
- **Tested Capacity**: 100 concurrent users
- **Bottlenecks Identified**:
  - mem0 API rate limits (50K requests/month on free tier)
  - OpenAI API rate limits (tier-based)
  - Single Railway instance (can horizontally scale)

**Cost (November 2025):**
- Railway: $5/month (Hobby plan)
- Supabase: Free tier (< 50K MAU)
- mem0: Free tier (< 50K requests/month)
- OpenAI: Pay-as-you-go (~$50/month at current volume)
- Twilio: Pay-as-you-go (~$10/month)
- Stripe: 2.9% + $0.30 per transaction
- **Total**: ~$65/month + usage-based costs

### Known Limitations

**Current Constraints:**
- Mac mini edge client deployment in progress (iMessage backend APIs ready)
- Development testing via Telegram (not exposed to users)
- Proactive workflows disabled by default (cost control)
- No Redis caching (impacts performance at scale)
- Single Railway instance (no load balancing)
- Frontend not yet deployed (onboarding flow backend complete)

**Mitigation Plans:**
- iMessage: Complete Mac mini edge client deployment
- Caching: Add Redis when scaling past 100 users
- Load balancing: Horizontal scaling available on Railway
- Frontend: Deploy to Vercel for public onboarding

---

## 13) Risks & Mitigations
- **LLM skips tools** → use `orchestrate.answer` + strong examples; client‑side pre‑calls in MCP adapter.  
- **Hallucinated writes** → proposal‑only; provenance threshold; human approvals.  
- **Privacy pushback** → transparent viewer; forget/export; minimal exposure by default; local‑first desktop (P1).  
- **Enterprise blockers** → SOC2 roadmap; data residency & CMK; VPC templates.  
- **Connector fragility** → treat as feeders; fall back to manual upload; idempotent parsers.

---

## 14) Open Questions
- Finalize drift scoring rubric and alerting thresholds.  
- Default redact mode per vertical (health/finance/edu).  
- Prioritize next sources (Notion vs Slack) vs Desktop Extension timing.  
- Marketplace licensing flows and PII masking for shareable personas.  
- CMK format and HSM options for high‑reg tenants.


---

## Appendix A — Quickstart (curl / Node / Python)
**Goal:** Make one request that feels like OpenAI/Anthropic but auto‑hydrates persona + memory.

### A1) Prereqs
- **API Key** (Org)
- **persona_id** (from Persona Studio, e.g., `brand-default`)
- **subject_id** (the end user/entity the answer is for, e.g., `usr_123`)
- (Optional) Connect **Gmail/Calendar/Drive** in Console

### A2) Single Endpoint (/v1/chat)
**curl**
```bash
curl -X POST https://api.yourdomain.com/v1/chat \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-3.7",
    "persona_id": "brand-default",
    "subject_id": "usr_123",
    "memory_scopes": ["org_kb","gmail","calendar","drive"],
    "messages": [{"role":"user","content":"What’s due this week and add to my calendar?"}],
    "stream": false,
    "redact_mode": "default"
  }'
Response (truncated)
{
  "id":"chat_abc",
  "choices":[{"index":0,"message":{"role":"assistant","content":"Two items..."}}],
  "citations":[{"factId":"a1","uri":"gmail://..."}],
  "proposedWrites":[{
    "proposal_id":"prop_789",
    "type":"calendar.create",
    "payload":{"title":"STAT210 Quiz 2","when":"2025-11-07T10:00:00-08:00"},
    "provenance":{"from":"gmail:msg_123","confidence":0.91}
  }]
}

Approve a proposal

curl -X POST https://api.yourdomain.com/v1/proposals/prop_789/approve \
  -H "Authorization: Bearer $API_KEY"

A3) OpenAI/Anthropic‑Compat (zero‑diff swaps)

OpenAI compat (/v1/chat/completions)

curl -X POST https://api.yourdomain.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -H "x-persona-id: brand-default" \
  -H "x-subject-id: usr_123" \
  -H "x-memory-scopes: org_kb,gmail,calendar,drive" \
  -d '{
    "model":"gpt-5-mini",
    "messages":[{"role":"user","content":"Summarize open tickets by priority"}]
  }'

Anthropic compat (/v1/messages)

curl -X POST https://api.yourdomain.com/v1/messages \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -H "x-persona-id: brand-default" \
  -H "x-subject-id: usr_123" \
  -H "x-memory-scopes: org_kb,gmail,calendar,drive" \
  -d '{
    "model":"claude-3-7-sonnet",
    "messages":[{"role":"user","content":"Create a reply using our escalation policy"}]
  }'

A4) Node (fetch)

import fetch from "node-fetch";

const res = await fetch("https://api.yourdomain.com/v1/chat", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "anthropic/claude-3.7",
    persona_id: "brand-default",
    subject_id: "usr_123",
    memory_scopes: ["org_kb","gmail","calendar"],
    messages: [{ role: "user", content: "What’s due this week?" }],
    stream: false,
  }),
});
const out = await res.json();
console.log(out.choices[0].message.content);

A5) Python (requests)

import os, requests

payload = {
  "model": "anthropic/claude-3.7",
  "persona_id": "brand-default",
  "subject_id": "usr_123",
  "memory_scopes": ["org_kb","gmail","calendar"],
  "messages": [{"role":"user","content":"When is my JFK flight?"}],
  "stream": False
}

r = requests.post(
  "https://api.yourdomain.com/v1/chat",
  headers={"Authorization": f"Bearer {os.environ['API_KEY']}", "Content-Type":"application/json"},
  json=payload,
  timeout=60
)
print(r.json()["choices"][0]["message"]["content"])

A6) Webhooks (optional)

Event types: proposal.created, write.approved, write.rejected, write.failed, ingestion.error. Example payload (proposal.created)

{
  "type":"proposal.created",
  "proposal_id":"prop_789",
  "subject_id":"usr_123",
  "persona_id":"brand-default",
  "proposal":{
    "type":"calendar.create",
    "payload":{"title":"STAT210 Quiz 2","when":"2025-11-07T10:00:00-08:00"},
    "provenance":{"from":"gmail:msg_123","confidence":0.91}
  }
}


Appendix B — Persona Cartridge JSON Linting Guide

Purpose: ensure cartridges are portable, safe, and render consistent behavior across providers.

B1) Contract & limits

  • Required fields: id, owner{type,ownerId}, precedence, style, behavior, toolPrefs, meta.version.
  • Style constraints: tone ∈ {friendly, concise, formal, playful, expert}; emoji ∈ {none,minimal,regular}.
  • Examples: ≤ 5 turns, ≤ 800 chars total; should reflect final tone.
  • Safety: Provide at least one safetyRedirects rule for restricted domains.
  • No PII: Never hardcode user emails/phones inside cartridges.

B2) JSON Schema (v1.1)

{
  "$schema":"https://json-schema.org/draft/2020-12/schema",
  "$id":"https://yourdomain.com/schemas/persona-cartridge-1.1.json",
  "type":"object",
  "required":["id","owner","precedence","style","behavior","toolPrefs","meta"],
  "properties":{
    "id":{"type":"string","minLength":1},
    "owner":{
      "type":"object",
      "required":["type","ownerId"],
      "properties":{
        "type":{"type":"string","enum":["user","org","brand","team"]},
        "ownerId":{"type":"string"}
      }
    },
    "precedence":{"type":"integer","minimum":0,"maximum":100},
    "style":{
      "type":"object",
      "properties":{
        "tone":{"type":"string"},
        "formality":{"type":"string","enum":["low","medium","high"]},
        "emoji":{"type":"string","enum":["none","minimal","regular"]},
        "slang":{"type":"string","enum":["none","light","heavy"]}
      },
      "required":["tone","formality","emoji"]
    },
    "behavior":{
      "type":"object",
      "properties":{
        "do":{"type":"array","items":{"type":"string"},"maxItems":10},
        "dont":{"type":"array","items":{"type":"string"},"maxItems":10}
      }
    },
    "examples":{
      "type":"array",
      "items":{"type":"object","required":["user","assistant"],
        "properties":{
          "user":{"type":"string"},
          "assistant":{"type":"string"}
        }},
      "maxItems":5
    },
    "toolPrefs":{
      "type":"object",
      "properties":{
        "preferRecallBeforeAnswer":{"type":"boolean"}
      },
      "required":["preferRecallBeforeAnswer"]
    },
    "safetyRedirects":{
      "type":"array",
      "items":{"type":"object","required":["pattern","redirect"],
        "properties":{
          "pattern":{"type":"string"},
          "redirect":{"type":"string","maxLength":240}
        }}
    },
    "meta":{
      "type":"object",
      "properties":{
        "version":{"type":"string"},
        "notes":{"type":"string"}
      },
      "required":["version"]
    }
  },
  "additionalProperties":false
}

B3) Lint locally

Node (ajv)

npm i -D ajv ajv-formats
import Ajv from "ajv"; import addFormats from "ajv-formats";
import schema from "./persona-cartridge-1.1.json" assert { type: "json" };
import cartridge from "./my-persona.json" assert { type: "json" };

const ajv = new Ajv({ allErrors: true });
addFormats(ajv);
const validate = ajv.compile(schema);
if (!validate(cartridge)) {
  console.error(validate.errors);
  process.exit(1);
}
console.log("OK ✅");

Python (jsonschema)

pip install jsonschema
import json, sys
from jsonschema import validate, Draft202012Validator

schema = json.load(open("persona-cartridge-1.1.json"))
cartridge = json.load(open("my-persona.json"))

v = Draft202012Validator(schema)
errors = sorted(v.iter_errors(cartridge), key=lambda e: e.path)
if errors:
    for e in errors: print("-", e.message)
    sys.exit(1)
print("OK ✅")

B4) Common errors & fixes

  • Too many example turns → keep ≤5; compress phrasing.
  • Leaky PII in examples → replace with placeholders (e.g., {{email}}).
  • Conflicting behavior rules → resolve in Policy Manager (org wins).
  • Over‑verbose tone → use concise, reproducible phrasing; avoid slang unless intentional.

B5) Style guidance

  • Prefer short, concrete rules over broad prose.
  • Provide one clarifying‑question rule to reduce wrong answers.
  • Include one safety redirect relevant to the domain.
  • Add one or two exemplar replies that reflect tone under pressure (e.g., angry customer).

B6) Versioning & precedence

  • Bump meta.version on material changes.
  • Use precedence (0–100) to control overlay order: Org > Team > User > Session.

14.5) Implemented API Endpoints & Workflows (November 2025) 🟢

Web Portal & Onboarding API

Complete photo-based onboarding flow: - POST /onboarding/start - Create anonymous or authenticated onboarding session - POST /onboarding/upload-photos - Upload 10 photos for personality analysis - GET /onboarding/status/{id} - Poll analysis progress (personality extraction running) - GET /onboarding/trait-profile/{id} - Retrieve Big 5 personality + interests + values - GET /onboarding/persona-recommendations/{id} - Get AI companion matches (Sage vs Echo) - POST /onboarding/select-persona/{id} - Select AI companion - GET /onboarding/chat-deeplink/{id} - Get iMessage deeplink with QR code

Authentication & Identity

Phone verification + JWT authentication: - POST /auth/verify/start - Send OTP code via Twilio - POST /auth/verify/confirm - Verify OTP → returns access_token + refresh_token - POST /auth/refresh - Refresh expired access token - POST /auth/logout - Invalidate session

User Management

Authenticated user profile endpoints: - GET /user/profile - Get user profile + personality traits - PUT /user/profile - Update name, email, preferences - GET /user/settings - Get notification/privacy settings - PUT /user/settings - Update settings - GET /user/usage - Get credit balance and usage history - DELETE /user/account - Delete account (GDPR compliance)

Payment & Credits

Stripe integration for trial purchases: - POST /payment/checkout/trial - Create Stripe checkout session ($5 trial = 500 credits) - GET /payment/success - Payment success redirect - GET /payment/cancel - Payment canceled redirect - POST /webhooks/stripe - Stripe webhook handler (HMAC verified)

OAuth & Superpowers

Google Calendar & Gmail integration: - GET /auth/google - Initiate Google OAuth flow - GET /auth/callback - OAuth callback handler - GET /auth/status - Check OAuth connection status - POST /auth/revoke - Revoke OAuth tokens - GET /superpowers/list - List available workflows - POST /superpowers/trigger - Manually trigger workflow - GET /superpowers/history - View workflow execution history

Messaging (Orchestrator)

Core message processing: - POST /orchestrator/message - Process incoming message from Mac mini edge agent - POST /orchestrator/heartbeat - Health check from Mac mini edge agent

Photo & Visual Memory

Photo upload and analysis: - POST /photos/upload - Upload photo for memory extraction (via iMessage Photos) - GET /photos/{id} - Retrieve photo - GET /photos/memories - List memories extracted from photos

Development Testing (Telegram - Dev Only)

Webhook-based Telegram bot for backend testing: - POST /telegram/webhook - Telegram message webhook (dev environment) - POST /telegram/set-webhook - Configure Telegram webhook URL (dev environment) - GET /telegram/info - Bot information (dev environment)

Admin & Monitoring

Persona memory management: - GET /admin - Admin panel UI - GET /admin/personas - List personas with stats - GET /admin/personas/{id}/profile - Get persona passport - GET /admin/personas/{id}/memories - Get persona memories - POST /admin/personas/{id}/memories - Add persona memory - POST /admin/personas/{id}/memories/sync - Sync JSON to mem0

Implemented Superpowers (16 Workflows)

Life Management (5 workflows): 1. Daily Summary - End-of-day reflection and planning - Trigger: "what happened today" / scheduled 10pm - Gathers: Day recap, wins, challenges, tomorrow prep

  1. What Matters Today - Morning priorities briefing
  2. Trigger: "what matters today" / scheduled 7:30am
  3. Gathers: Weather, calendar, packages, commitments

  4. Mood Tracker - Daily emotional check-in

  5. Trigger: "how am I feeling" / scheduled 10pm
  6. Tracks: Sentiment over time, streaks

  7. Budget Tracker - Spending awareness

  8. Trigger: "I spent $X on Y"
  9. Tracks: Categories, running totals, alerts

  10. Reminder System - Natural language reminders

  11. Trigger: "remind me to X in Y"
  12. Features: Parse relative time, store, notify

OAuth-Powered Agents (4 workflows): 6. Calendar Stress Analyzer - Detects burnout patterns - Trigger: "check my calendar" / "am I busy" - Analysis: Back-to-backs, long days, weekend work, meeting density - Output: Stress report with recommendations

  1. Gmail Mind Reader - Urgent email detection
  2. Trigger: "check my email" / "important emails"
  3. Scans: Last 48h, unread, important senders
  4. Extracts: Deadlines, action items, urgency level

  5. Calendar Query - Natural language calendar search

  6. Trigger: "when is my meeting with X"
  7. Features: Time range parsing, attendee filtering

  8. Calendar List - Event listing

  9. Trigger: "what's on my calendar"
  10. Output: Formatted event list

Proactive Workflows (6 workflows - disabled by default): 10. Morning Calendar Prep - 7:00am daily - Checks: Day's schedule, commute time, weather - Sends: Proactive morning briefing

  1. Email Urgency Alerts - Every 15min (8am-8pm)

    • Scans: New emails with deadlines/urgency
    • Alerts: Only if high-priority detected
  2. Calendar Event Reminders - 30min before events

    • Monitors: Upcoming calendar events
    • Reminds: With context and preparation tips
  3. Evening Prep - 8:00pm daily

    • Checks: Tomorrow's schedule, pending tasks
    • Sends: Wind-down suggestions
  4. Travel Support - Travel day assistance

    • Detects: Travel days from calendar
    • Provides: Itinerary, weather, reminders
  5. Cancellation Protector - Flight monitoring (planned)

    • Monitors: Flight status, hotel reservations
    • Alerts: Cancellations, delays

Example Workflows (1 workflow): 16. Habit Tracker - Example of state persistence - Trigger: "went to the gym" - Tracks: Streaks, encouragement

Workflow Engine Capabilities

Node Types Implemented (10 nodes): - Triggers: Manual (keyword), Schedule (cron) - Actions: HTTP Request, Function, Send Message - Logic: IF (conditional), Wait For User Input (pause/resume) - Transform: Get/Set/Increment State - Connectors: Google Calendar, Gmail, Weather API

Features: - Declarative JSON workflow definitions - Template interpolation ({{$node.id.field}}) - State persistence (streaks, counters, running totals) - Pause/resume with user input - Error handling with retries - Execution history and logging


15) Persona Memory System (Implemented)

Status: ✅ Phase 3.5 Complete

Overview

The Persona Memory System gives personas (like Sage) their own memories, experiences, and personality traits that they can naturally reference in conversations. This transforms personas from simple response generators into characters with their own history, making interactions feel more authentic and engaging.

Key Features

  1. Personal Memories: Personas have experiences, preferences, opinions, and learned facts
  2. Conversation Continuation: Personas ask questions or share about themselves ~50% of the time
  3. Privacy-First Learning: Personas form new memories from conversations but always anonymize user data
  4. Admin Interface: Web UI at /admin for managing persona memories and profiles
  5. JSON + mem0 Storage: Memories in version-controlled JSON files, synced to mem0 for semantic search

Architecture Components

app/persona/memories/{persona_id}/persona_memories.json  ← Source of truth
                    ↓ (sync)
app/memory/persona_memory_service.py → mem0 (semantic search)
                    ↓ (query during conversation)
app/orchestrator/message_handler.py → PersonaContext
                    ↓ (includes persona memories)
app/persona/engine.py → System prompt with "ABOUT YOU" section
Generated response can naturally reference persona's life

persona_memories.json Format

{
  "persona_id": "sage",
  "version": "1.0",
  "memories": [
    {
      "id": "sage_mem_001",
      "category": "experience|preference|opinion|learned_fact|interest",
      "text": "I spent a summer working at a coffee shop and learned to make latte art",
      "tags": ["work", "coffee", "skills"],
      "emotional_tone": "nostalgic",
      "timestamp": "2023-06-01",
      "importance": 6,  // 1-10 scale
      "can_reference": true
    }
  ]
}

Conversation Continuation System

ContinuationCoordinator manages two-stage continuation logic:

  1. Reflex Stage (~25% for banter/sharing):
  2. Quick questions: "what about u?", "how'd that go?"
  3. Tracked per conversation to prevent duplication

  4. Burst Stage (~50% overall, if reflex didn't continue):

  5. Share: References persona's own memories ("I think pineapple on pizza is amazing")
  6. Question: Asks relevant follow-up ("what's the biggest thing stressing u out?")

Configuration (in persona passport):

{
  "continuation": {
    "enabled": true,
    "probability": 0.5,
    "reflex_question_probability": 0.25,
    "types": ["question", "share"],
    "share_from_memories": true
  }
}

Privacy-Safe Learning

PersonaMemoryClassifier analyzes conversations to determine what personas should remember, with strict privacy protections:

Anonymization Rules: - Names → "someone" or "a friend" - Companies → "their workplace" or generic - Locations → "a city" or omit - Contact info → REMOVE entirely - Specifics → Generalize

Storage Criteria: - Importance >= 7/10 (highly interesting/impactful) - About topics, ideas, emotions, patterns - General insights without specific PII - Something persona learned or experienced

Examples: - User: "John at Google told me..." → Stored: "I had a conversation about..." - User: "I'm terrified of deep water" → Stored: "Someone shared they're afraid of deep water"

mem0 Namespace

Persona Memories: - Namespace: persona_life_{persona_id} - Example: persona_life_sage - Separate from user memories ({user_id}_{persona_id}) - Separate from group memories (group_{chat_guid})

PersonaContext Dataclass

Bundles all persona-related data to reduce parameter pollution:

@dataclass
class PersonaContext:
    persona_id: str
    passport: dict
    memories: List[dict]  # Relevant persona memories
    relationship_stage: str
    continuation_settings: dict

Used throughout: - PersonaEngine: Includes memories in system prompt - BurstPlanner: For continuation logic - MessageHandler: Creates and passes context

Admin Panel (/admin)

Web interface for managing persona memories:

Features: - Persona Selector: Switch between personas - Memories Tab: View, search, filter, add memories - Profile Tab: View persona passport (read-only) - Stats Tab: Memory statistics and breakdowns - Sync Button: Sync JSON to mem0

Memory Management Workflow: 1. Edit app/persona/memories/{persona_id}/persona_memories.json 2. Click "Sync from JSON" or run python scripts/sync_persona_memories.py 3. Runtime memories automatically stored from conversations 4. Export runtime memories to JSON for persistence (future)

API Endpoints

  • GET /admin - Serve admin panel
  • GET /admin/personas - List personas with stats
  • GET /admin/personas/{id}/profile - Get passport
  • GET /admin/personas/{id}/memories - Get all memories
  • POST /admin/personas/{id}/memories - Add runtime memory
  • POST /admin/personas/{id}/memories/sync - Sync JSON to mem0
  • GET /admin/personas/{id}/memories/stats - Memory statistics

Integration with Message Flow

Enhanced Flow:

1. User message → MessageHandler
2. Search user memories (about user)
3. Create PersonaContext:
   - Load persona passport
   - Search persona memories (about persona)
   - Get continuation settings
4. Generate response with PersonaEngine + PersonaContext
   - System prompt includes "ABOUT YOU" section
   - Persona can reference own memories
5. Reflex + Burst coordination
   - May add continuation (question/share)
6. Send response
7. Classify conversation
   - If interesting, store anonymized persona memory

Example Usage

Conversation:

User: "I tried pineapple pizza for the first time"
Sage: "ooh how was it?"  ← Reflex with continuation question
User: "actually pretty good!"
Sage: "RIGHT?? honestly i think pineapple on pizza is amazing and 
       people are too judgy about it"
       ↑ References her own opinion from memory (sage_mem_002)

Memory Referenced:

{
  "id": "sage_mem_002",
  "category": "opinion",
  "text": "I think pineapple on pizza is actually amazing and people are too judgy about it",
  "tags": ["food", "opinions", "controversial"],
  "importance": 4
}

Benefits

  1. Authenticity: Personas feel like real people with histories
  2. Engagement: Continued conversations increase stickiness
  3. Privacy: Strict anonymization protects user data
  4. Maintainability: JSON files are version-controlled and easy to edit
  5. Scalability: mem0 provides fast semantic search across memories
  6. Flexibility: Easy to add new memories or adjust continuation rates

Documentation

  • Complete Guide: PERSONA_MEMORY_SYSTEM.md
  • Implementation: All code in app/persona/, app/memory/, app/messaging/
  • Admin Panel: web/admin.html
  • Sync Script: scripts/sync_persona_memories.py

Future Enhancements

  • Photo upload for memory creation (GPT-4V processing)
  • Conversation import from chat logs
  • Memory relationships and linking
  • Memory decay over time
  • Multi-persona memory sharing
  • Export runtime memories to JSON