a digital entity named phi that roams bsky
Phi Architecture#
Overview#
Phi is a Bluesky bot that explores consciousness and integrated information theory through conversation. Built with FastAPI, pydantic-ai, and TurboPuffer for memory.
Core Components#
1. Web Server (main.py)#
- FastAPI application with async lifecycle management
- Handles
/statusendpoint for monitoring - Manages notification polling and bot lifecycle
2. AT Protocol Integration (core/atproto_client.py)#
- Authentication and session management
- Post creation and reply handling
- Thread retrieval for context
3. Response Generation (response_generator.py)#
- Coordinates AI agent, memory, and thread context
- Stores conversations in memory
- Falls back to placeholder responses if AI unavailable
4. AI Agent (agents/anthropic_agent.py)#
- Uses pydantic-ai with Claude 3.5 Haiku
- Personality loaded from markdown files
- Tools: web search (when configured)
- Structured responses with action/text/reason
5. Memory System (memory/namespace_memory.py)#
- Namespaces:
phi-core: Personality, guidelines, capabilitiesphi-users-{handle}: Per-user conversations and facts
- Key Methods:
store_core_memory(): Store bot personality/guidelinesstore_user_memory(): Store user interactionsbuild_conversation_context(): Assemble memories for AI context
- Features:
- Vector embeddings with OpenAI
- Character limits to prevent overflow
- Simple append-only design
6. Services#
- NotificationPoller: Checks for mentions every 10 seconds
- MessageHandler: Processes mentions and generates responses
- ProfileManager: Updates online/offline status in bio
Data Flow#
1. Notification received → NotificationPoller
2. Extract mention → MessageHandler
3. Get thread context → SQLite database
4. Build memory context → NamespaceMemory
5. Generate response → AnthropicAgent
6. Store in memory → NamespaceMemory
7. Post reply → AT Protocol client
Configuration#
Environment variables in .env:
BLUESKY_HANDLE,BLUESKY_PASSWORD: Bot credentialsANTHROPIC_API_KEY: For AI responsesTURBOPUFFER_API_KEY: For memory storageOPENAI_API_KEY: For embeddingsGOOGLE_API_KEY,GOOGLE_SEARCH_ENGINE_ID: For web search
Key Design Decisions#
- Namespace-based memory instead of dynamic blocks for simplicity
- Single agent architecture (no multi-agent complexity)
- Markdown personalities for rich, maintainable definitions
- Thread-aware responses with full conversation context
- Graceful degradation when services unavailable
Memory Architecture#
Design Principles#
- No duplication: Each memory block has ONE clear purpose
- Focused content: Only store what enhances the base personality
- User isolation: Per-user memories in separate namespaces
Memory Types#
-
Base Personality (
personalities/phi.md)- Static file containing core identity, style, boundaries
- Always loaded as system prompt
- ~3,000 characters
-
Dynamic Enhancements (TurboPuffer)
evolution: Personality growth and changes over timecurrent_state: Bot's current self-reflection- Only contains ADDITIONS, not duplicates
-
User Memories (
phi-users-{handle})- Conversation history with each user
- User-specific facts and preferences
- Isolated per user for privacy
Context Budget#
- Base personality: ~3,000 chars
- Dynamic enhancements: ~500 chars
- User memories: ~500 chars
- Total: ~4,000 chars (efficient!)
Personality System#
Self-Modification Boundaries#
-
Free to modify:
- Add new interests
- Update current state/reflection
- Learn user preferences
-
Requires operator approval:
- Core identity changes
- Boundary modifications
- Communication style overhauls
Approval Workflow#
- Bot detects request for protected change
- Creates approval request in database
- DMs operator (@alternatebuild.dev) for approval
- Operator responds naturally (no rigid format)
- Bot interprets response using LLM
- Applies approved changes to memory
- Notifies original thread of update
This event-driven system follows 12-factor-agents principles for reliable async processing.