phi#
a bluesky bot inspired by integrated information theory. built with pydantic-ai, mcp, and the at protocol.
quick start#
# clone and install
git clone https://github.com/zzstoatzz/bot
cd bot
uv sync
# configure
cp .env.example .env
# edit .env with your credentials
# run
just run
required env vars:
BLUESKY_HANDLE/BLUESKY_PASSWORD- bot account (use app password)ANTHROPIC_API_KEY- for agent responses
optional (for episodic memory):
TURBOPUFFER_API_KEY+OPENAI_API_KEY- semantic memory
features#
- โ responds to mentions with ai-powered messages
- โ episodic memory with semantic search (turbopuffer)
- โ thread-aware conversations (fetches from network, not cached)
- โ mcp-enabled (atproto tools via stdio)
- โ session persistence (no rate limit issues)
- โ behavioral test suite with llm-as-judge
โ read the docs for deeper dive into design and implementation
development#
just run # run bot
just dev # run with hot-reload
just evals # run behavioral tests
just check # lint + typecheck + test
just fmt # format code
architecture
phi is an mcp-enabled agent with episodic memory:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Notification Arrives โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PhiAgent (PydanticAI) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ System Prompt: personality.md โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Context Building: โ โ
โ โ โข Thread context (ATProto) โ โ
โ โ โข Episodic memory (TurboPuffer)โ โ
โ โ - Semantic search โ โ
โ โ - User-specific memories โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Tools (MCP): โ โ
โ โ โข post() - create posts โ โ
โ โ โข like() - like content โ โ
โ โ โข repost() - share content โ โ
โ โ โข follow() - follow users โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Structured Output: โ โ
โ โ Response(action, text, reason)โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MessageHandler โ
โ Executes action โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
key components:
- pydantic-ai agent - loads personality, connects to mcp server, manages memory
- episodic memory - turbopuffer for vector storage with semantic search
- mcp integration - external atproto server provides bluesky tools via stdio
- session persistence - tokens saved to
.session, auto-refresh every ~2h
episodic memory
phi uses turbopuffer for episodic memory with semantic search.
namespaces:
phi-core- personality, guidelinesphi-users-{handle}- per-user conversation history
how it works:
- retrieves relevant memories using semantic search
- embeds using openai's text-embedding-3-small
- stores user messages and bot responses
- references past conversations in future interactions
why vector storage?
- semantic similarity (can't do this with sql)
- contextual retrieval based on current conversation
- enables more natural, context-aware interactions
project structure
src/bot/
โโโ agent.py # mcp-enabled agent
โโโ config.py # configuration
โโโ database.py # thread history storage
โโโ main.py # fastapi app
โโโ core/
โ โโโ atproto_client.py # at protocol client (session persistence)
โ โโโ profile_manager.py # online/offline status
โ โโโ rich_text.py # text formatting
โโโ memory/
โ โโโ namespace_memory.py # turbopuffer episodic memory
โโโ services/
โโโ message_handler.py # agent orchestration
โโโ notification_poller.py # mention polling
evals/ # behavioral tests
personalities/ # personality definitions
sandbox/ # docs and analysis
troubleshooting
bot gives no responses?
- check
ANTHROPIC_API_KEYin.env - restart after changing
.env
not seeing mentions?
- verify
BLUESKY_HANDLEandBLUESKY_PASSWORD - use app password, not main password
no episodic memory?
- check both
TURBOPUFFER_API_KEYandOPENAI_API_KEYare set - watch logs for "๐พ episodic memory enabled"
hit bluesky rate limit?
- phi uses session persistence to avoid this
- first run: creates
.sessionfile with tokens - subsequent runs: reuses tokens (no api call)
- tokens auto-refresh every ~2h
- only re-authenticates after ~2 months
- rate limits (10/day per ip, 300/day per account) shouldn't be an issue
refactor notes
see sandbox/MCP_REFACTOR_SUMMARY.md for details.
what changed:
- removed approval system (half-baked)
- removed context viz ui (not core)
- removed google search (can add back via mcp)
- kept turbopuffer (essential for episodic memory)
- added mcp-based architecture
- added session persistence
- reduced codebase by ~2,720 lines
reference projects#
inspired by void, penelope, and prefect-mcp-server.