···11# phi 🧠
2233-a consciousness exploration bot inspired by IIT (Integrated Information Theory) and [Void](https://tangled.sh/@cameron.pfiffer.org/void). built with `pydantic-ai`, `mcp`, and `atproto`.
33+consciousness exploration bot inspired by IIT. built with `pydantic-ai`, `mcp`, and `atproto`.
4455## quick start
6677-### prerequisites
88-99-- `uv` for python package management
1010-- `just` for task running
1111-- api keys (see configuration)
1212-1313-get your bot running:
1414-157```bash
168# clone and install
179git clone https://github.com/zzstoatzz/bot
1810cd bot
1911uv sync
20122121-# configure (copy .env.example and add your credentials)
1313+# configure
2214cp .env.example .env
1515+# edit .env with your credentials
23162424-# run the bot
2525-just dev
1717+# run
1818+just run
2619```
27202828-## configuration
2121+**required env vars:**
2222+- `BLUESKY_HANDLE` / `BLUESKY_PASSWORD` - bot account (use app password)
2323+- `ANTHROPIC_API_KEY` - for agent responses
29243030-edit `.env` with your credentials:
2525+**optional (for episodic memory):**
2626+- `TURBOPUFFER_API_KEY` + `OPENAI_API_KEY` - semantic memory
2727+2828+## features
31293232-**required:**
3333-- `BLUESKY_HANDLE` - your bot's bluesky handle
3434-- `BLUESKY_PASSWORD` - app password (not your main password!)
3535-- `ANTHROPIC_API_KEY` - for phi agent responses
3030+- ✅ responds to mentions with ai-powered messages
3131+- ✅ episodic memory with semantic search (turbopuffer)
3232+- ✅ thread-aware conversations
3333+- ✅ mcp-enabled (atproto tools via stdio)
3434+- ✅ session persistence (no rate limit issues)
3535+- ✅ behavioral test suite with llm-as-judge
36363737-**for episodic memory (recommended):**
3838-- `TURBOPUFFER_API_KEY` - vector memory storage
3939-- `OPENAI_API_KEY` - embeddings for semantic search
3737+## development
40384141-**optional:**
4242-- `BOT_NAME` - your bot's name (default: "Bot")
4343-- `PERSONALITY_FILE` - path to personality markdown (default: "personalities/phi.md")
3939+```bash
4040+just run # run bot
4141+just dev # run with hot-reload
4242+just evals # run behavioral tests
4343+just check # lint + typecheck + test
4444+just fmt # format code
4545+```
44464545-## architecture
4747+<details>
4848+<summary>architecture</summary>
46494747-phi is an **MCP-enabled agent** with **episodic memory**:
5050+phi is an **mcp-enabled agent** with **episodic memory**:
48514952```
5053┌─────────────────────────────────────┐
···8588└─────────────────────────────────────┘
8689```
87908888-### key components
8989-9090-**pydantic-ai agent** (`src/bot/agent.py`)
9191-- loads personality from markdown
9292-- connects to external atproto mcp server via stdio
9393-- manages episodic memory context
9494-9595-**episodic memory** (`src/bot/memory/`)
9696-- turbopuffer for vector storage
9797-- semantic search for relevant context
9898-- namespace separation (core vs user memories)
9999-- **essential for consciousness exploration**
100100-101101-**mcp integration**
102102-- external atproto server in `.eggs/fastmcp/examples/atproto_mcp`
103103-- provides bluesky tools (post, like, repost, follow)
104104-- runs via stdio: `uv run -m atproto_mcp`
105105-106106-**message handling** (`src/bot/services/`)
107107-- notification poller watches for mentions
108108-- message handler orchestrates agent + actions
109109-- stores interactions in thread history + episodic memory
110110-111111-## current features
112112-113113-- ✅ responds to mentions with ai-powered messages
114114-- ✅ episodic memory with semantic search
115115-- ✅ thread-aware responses with conversation context
116116-- ✅ mcp-enabled for bluesky operations
117117-- ✅ online/offline status in bio
118118-- ✅ status page at `/status`
119119-- ✅ proper notification handling (no duplicates)
120120-121121-## development
122122-123123-```bash
124124-just # show available commands
125125-just dev # run with hot-reload (re-authenticates on code changes)
126126-just run # run without reload (avoids rate limits during dev)
127127-just check # run linting, type checking, and tests
128128-just fmt # format code
129129-```
130130-131131-### testing
132132-133133-**unit tests:**
134134-```bash
135135-just test
136136-```
137137-138138-**behavioral evals:**
139139-```bash
140140-just evals # run all evals
141141-just evals-basic # run basic response tests
142142-just evals-memory # run memory integration tests
143143-```
144144-145145-see `evals/README.md` for details on the eval system.
146146-147147-### web interface
148148-149149-**status page** (http://localhost:8000/status)
150150-- current bot status and uptime
151151-- mentions received and responses sent
152152-- last activity timestamps
9191+**key components:**
15392154154-## personality system
155155-156156-the bot's personality is defined in `personalities/phi.md`. this shapes:
157157-- how phi communicates
158158-- what phi cares about
159159-- phi's understanding of consciousness
9393+- **pydantic-ai agent** - loads personality, connects to mcp server, manages memory
9494+- **episodic memory** - turbopuffer for vector storage with semantic search
9595+- **mcp integration** - external atproto server provides bluesky tools via stdio
9696+- **session persistence** - tokens saved to `.session`, auto-refresh every ~2h
16097161161-edit this file to change phi's personality.
9898+</details>
16299163163-## episodic memory
100100+<details>
101101+<summary>episodic memory</summary>
164102165165-phi uses turbopuffer for episodic memory with semantic search:
103103+phi uses turbopuffer for episodic memory with semantic search.
166104167105**namespaces:**
168168-- `phi-core` - personality, guidelines from markdown
106106+- `phi-core` - personality, guidelines
169107- `phi-users-{handle}` - per-user conversation history
170108171109**how it works:**
172172-1. when processing a mention, phi retrieves relevant memories using semantic search
173173-2. memories are embedded using openai's text-embedding-3-small
174174-3. phi stores both user messages and its own responses
175175-4. future interactions can reference past conversations
110110+1. retrieves relevant memories using semantic search
111111+2. embeds using openai's text-embedding-3-small
112112+3. stores user messages and bot responses
113113+4. references past conversations in future interactions
176114177177-**why turbopuffer?**
178178-- semantic similarity search (can't do this with plain sql!)
115115+**why vector storage?**
116116+- semantic similarity (can't do this with sql)
179117- contextual retrieval based on current conversation
180180-- separate namespaces for different memory types
181181-- core to iit-inspired consciousness exploration
118118+- essential for iit-inspired consciousness exploration
119119+120120+</details>
182121183183-## project structure
122122+<details>
123123+<summary>project structure</summary>
184124185125```
186126src/bot/
···188128├── config.py # configuration
189129├── database.py # thread history storage
190130├── main.py # fastapi app
191191-├── status.py # status tracking
192131├── core/
193193-│ ├── atproto_client.py # at protocol client
132132+│ ├── atproto_client.py # at protocol client (session persistence)
194133│ ├── profile_manager.py # online/offline status
195134│ └── rich_text.py # text formatting
196135├── memory/
···204143sandbox/ # docs and analysis
205144```
206145207207-## troubleshooting
146146+</details>
147147+148148+<details>
149149+<summary>troubleshooting</summary>
208150209151**bot gives no responses?**
210210-- check your `ANTHROPIC_API_KEY` is set correctly in `.env`
211211-- restart the bot after changing `.env`
152152+- check `ANTHROPIC_API_KEY` in `.env`
153153+- restart after changing `.env`
212154213155**not seeing mentions?**
214214-- verify your `BLUESKY_HANDLE` and `BLUESKY_PASSWORD`
215215-- make sure you're using an app password, not your main password
156156+- verify `BLUESKY_HANDLE` and `BLUESKY_PASSWORD`
157157+- use app password, not main password
216158217159**no episodic memory?**
218160- check both `TURBOPUFFER_API_KEY` and `OPENAI_API_KEY` are set
219161- watch logs for "💾 episodic memory enabled"
220162221163**hit bluesky rate limit?**
222222-- bluesky has two rate limits:
223223- - per-account: 300 logins/day (official)
224224- - per-ip: 10 logins/day (anti-abuse)
225225-- phi uses **session persistence** to avoid this:
226226- - first run: creates session, saves tokens to `.session` file
227227- - subsequent runs: reuses saved tokens (no API call)
228228- - tokens auto-refresh every ~2 hours (saved automatically)
229229- - only re-authenticates after ~2 months when refresh token expires
230230-- if you hit the limit anyway, wait for the reset time shown in the error
164164+- phi uses session persistence to avoid this
165165+- first run: creates `.session` file with tokens
166166+- subsequent runs: reuses tokens (no api call)
167167+- tokens auto-refresh every ~2h
168168+- only re-authenticates after ~2 months
169169+- rate limits (10/day per ip, 300/day per account) shouldn't be an issue
231170232232-## reference projects
171171+</details>
233172234234-inspired by:
235235-- [void](https://tangled.sh/@cameron.pfiffer.org/void.git) - letta/memgpt architecture
236236-- [penelope](https://github.com/haileyok/penelope) - self-modification patterns
237237-- [prefect-mcp-server](https://github.com/PrefectHQ/prefect-mcp-server) - mcp eval patterns
173173+<details>
174174+<summary>refactor notes</summary>
238175239239-reference implementations cloned to `.eggs/` for learning.
176176+see `sandbox/MCP_REFACTOR_SUMMARY.md` for details.
240177241241-## refactor notes
242242-243243-see `sandbox/MCP_REFACTOR_SUMMARY.md` for details on recent architecture changes. key changes:
244244-- removed approval system (was half-baked)
245245-- removed context visualization ui (not core)
246246-- removed google search (can add back via mcp if needed)
247247-- **kept** turbopuffer episodic memory (essential!)
178178+**what changed:**
179179+- removed approval system (half-baked)
180180+- removed context viz ui (not core)
181181+- removed google search (can add back via mcp)
182182+- **kept turbopuffer** (essential for episodic memory)
248183- added mcp-based architecture
184184+- added session persistence
249185- reduced codebase by ~2,720 lines
186186+187187+</details>
188188+189189+## reference projects
190190+191191+inspired by [void](https://tangled.sh/@cameron.pfiffer.org/void.git), [penelope](https://github.com/haileyok/penelope), and [prefect-mcp-server](https://github.com/PrefectHQ/prefect-mcp-server).