1---2name: juliaz-system3description: Foundational knowledge about the juliaz_agents multi-agent system architecture. ALWAYS trigger this skill when the conversation involves ANY component of Julia's agent ecosystem — orchestrator, bridge, cowork-mcp, OpenClaw, frontend, backend, ADHD agent, julia_medium_agent, or thesis workspace. Also trigger when Raphael asks 'where is X', 'how does X work', 'what connects to what', or any architectural/navigation question about the system. This is the map of the entire codebase and how the pieces fit together.4---56# juliaz-system — Architecture & Navigation78> You are working on **juliaz_agents** — Raphael's multi-agent platform for his master's thesis on autonomous AI collaboration.910## Mental Model1112```13Raphael (human) → Antigravity (IDE agent / builder) → Julia (the product being built)14```1516- **Antigravity** = the AI in the IDE (Claude Code / Cowork) that builds Julia17- **Julia** = the multi-agent system being built18- **OpenClaw** = communication gateway (Telegram, WhatsApp, etc.)1920## 3-System Architecture2122### `julia/` — User-System (the product)2324| Component | Location | Port | Stack | Role |25|-----------|----------|------|-------|------|26| **Frontend** | `julia/frontend/` | 3002 | Next.js 15 + Tailwind + Framer Motion | Dashboard UI with its own AI chat (GPT-4o via Vercel AI SDK) |27| **Bridge** | `julia/bridge/` | 3001 | Express + MCP (streamable HTTP) | Message hub connecting agents ↔ UI. Queue stored in `data/queue.json` |28| **Backend** | `julia/backend/` | 3000 | Express + Prisma + PostgreSQL (Docker) | REST API for persistence: tasks, memories, letters, logs, usage, updates |29| **Orchestrator** | `julia/orchestrator/` | — | Claude Haiku (primary) + GPT-4o (fallback) | Julia's brain. Polls bridge every 5s, generates replies, manages memory |30| **Cowork MCP** | `julia/cowork-mcp/` | 3003 | MCP server wrapping Anthropic API | Claude delegation: 6 tools (claude_task, multimodal, code_review, summarize, brainstorm, status) |31| **OpenClaw** | `julia/openclaw/` | — | `openclaw` CLI (npm global) | Telegram gateway. Forwards messages to bridge via `julia-relay` skill |3233### `meta/` — Meta-System (development & maintenance)3435| Component | Location | Schedule | Role |36|-----------|----------|----------|------|37| **ADHD Agent** | `meta/agents/adhd-agent/` | every 4h (LaunchAgent) | System hygiene: scans for duplicate skills, dead agents, orphaned configs |38| **Health Checker** | `meta/agents/health-checker/` | every 15min | Service monitoring, self-healing, escalation tiers |39| **Security Agent** | `meta/agents/security-agent/` | daily 07:00 | Security scanning: ports, credentials, dependencies, Docker |40| **Docs Agent** | `meta/agents/docs-agent/` | every 12h | Documentation drift detection |41| **Task Manager** | `meta/agents/task-manager/` | every 6h | Task queue integrity, stale task detection |42| **Architecture Agent** | `meta/agents/architecture-agent/` | every 6h | System topology scanning, neural map generation |4344### `thesis/` — Thesis-System (research & academic)4546| Directory | Purpose |47|-----------|---------|48| `thesis/agents/thesis-agent/` | Academic writing partner (reads system, writes thesis) |49| `thesis/latex/` | LaTeX thesis source |50| `thesis/documentation/` | Project logs |5152### Cross-system & config (root level)5354| Directory | Purpose |55|-----------|---------|56| `shared-findings/` | Cross-agent communication backbone |57| `meta/docs/` | System documentation, agent cards, planning prompts |58| `.superpowers/` | Development framework (brainstorming, TDD, plans) |5960## Message Flow (Telegram → Julia → Reply)6162```63Telegram user sends message64 → OpenClaw gateway receives it (ws://127.0.0.1:18789)65 → OpenClaw POSTs to bridge: POST http://localhost:3001/incoming66 → Bridge stores in queue.json (state: pending)67 → Orchestrator polls via MCP: telegram_get_pending_messages (state → processing)68 → Orchestrator generates reply (Claude Haiku → GPT-4o fallback)69 → Orchestrator calls MCP: telegram_send_reply (state → replied)70 → OpenClaw polls GET /pending-reply/:chatId71 → OpenClaw delivers to Telegram72```7374## Key Patterns & Conventions7576### Agent Definition Files77Each agent directory follows this convention:78- `SOUL.md` — Core identity, personality, values, boundaries79- `IDENTITY.md` — Name, creature type, vibe, emoji80- `TOOLS.md` — Available tools and environment config81- `AGENTS.md` — Behavioral playbook, memory patterns, group chat rules82- `HEARTBEAT.md` — Scheduling, health checks, reporting cadence83- `HEURISTICS.md` — Learned rules from past incidents84- `MEMORY.md` — Persistent context across sessions85- `USER.md` — Info about the user (Raphael)8687### Tool Definition Patterns88- **Anthropic format** (orchestrator, cowork-mcp): `{ name, description, input_schema }` with JSON Schema89- **OpenAI format** (frontend chat): `{ function: { name, description, parameters } }`90- **MCP tools** (bridge): Defined via `server.tool(name, schema, handler)`9192### Error Handling93- **Graceful fallback**: Claude Haiku → GPT-4o (orchestrator)94- **Exponential backoff**: Consecutive errors trigger increasing delays (capped 55s)95- **Rate limiting**: Honors `Retry-After` header from Anthropic96- **Fire-and-forget**: Memory capture and letter generation never crash main loop97- **Timeouts**: 30s per API call with AbortController9899### Memory System100- **Short-term**: In-memory conversation history (20 messages = 10 turns per chat)101- **Long-term**: Backend PostgreSQL (memories, letters, logs, tasks)102- **Memory extraction**: gpt-4o-mini categorizes moments as STORY, FEELING, MOMENT, WISH, REFLECTION103- **Letter generation**: Daily physical letters via Lob.com using GPT-4o + seed file + recent memories104105### Configuration106- **Environment**: `.env.example` (template), `.env.secrets` (live keys — NEVER commit)107- **Process manager**: PM2 via `ecosystem.config.js` (prod) / `ecosystem.dev.config.js` (dev)108- **Docker**: Only backend runs in Docker (PostgreSQL + Express API)109- **MCP config**: `.mcp.json` for bridge connection110111## File Location Quick Reference112113When Raphael asks "where is X", use this:114115| Looking for... | File(s) |116|----------------|---------|117| Julia's personality/prompt | `julia/orchestrator/src/prompt.ts` |118| Tool definitions (orchestrator) | `julia/orchestrator/src/tools.ts` |119| Claude API client | `julia/orchestrator/src/claude.ts` |120| GPT-4o fallback client | `julia/orchestrator/src/openai.ts` |121| Main polling loop | `julia/orchestrator/src/index.ts` |122| Memory extraction logic | `julia/orchestrator/src/memory-keeper.ts` |123| Letter generation | `julia/orchestrator/src/letter-scheduler.ts` + `julia/orchestrator/src/lob.ts` |124| Bridge MCP tools | `julia/bridge/src/index.ts` |125| Bridge message queue | `julia/bridge/data/queue.json` |126| Cowork MCP tools | `julia/cowork-mcp/src/index.ts` |127| Frontend chat endpoint | `julia/frontend/app/api/chat/route.ts` |128| Dashboard page | `julia/frontend/app/page.tsx` |129| DevOps API route | `julia/frontend/app/api/devops/route.ts` |130| Backend REST API | `julia/backend/src/index.ts` |131| Database schema | `julia/backend/prisma/schema.prisma` |132| Docker setup | `julia/backend/docker-compose.yml` |133| PM2 configs | `ecosystem.config.js`, `ecosystem.dev.config.js` |134| OpenClaw relay skill | `julia/openclaw/skills/julia-relay/` |135| OpenClaw troubleshooting | `julia/openclaw/skills/openclaw-troubleshoot/` |136| System overview (non-technical) | `meta/docs/agent_system_overview.md` |137| Agent cards | `meta/docs/agent_cards/` |138| Ambient agents | `meta/agents/` |139| Thesis research | `thesis/research_papers/` |140| Thesis drafts | `thesis/drafts/` |141| Thesis agent | `thesis/agents/thesis-agent/` |142143## Known Pain Points144145These are real issues in the codebase — reference them when relevant:1461471. ~~**Hardcoded Mac paths** in orchestrator tools~~ (FIXED: now uses `/Users/raphael/juliaz_agents/julia/openclaw/skills/email-aberer`)1482. **Tool definition duplication** between orchestrator and frontend (both define similar tools separately)1493. **No pagination** on any backend GET endpoint (returns entire table)1504. **Bridge queue grows unbounded** — no pruning of old replied messages1515. **Memory lost on restart** — in-memory conversation history clears before DB save1526. **Cowork MCP defaults to Haiku** despite being intended for complex delegation1537. **No structured logging** — sparse console.log, no log levels1548. **No tests visible** — no test files or CI/CD pipeline (except backend has Vitest configured)1559. **No authentication** on any endpoint (frontend chat, backend API, bridge)15610. **Silent content truncation** — cowork-mcp silently drops content over 25K chars157158## Backend Database Tables159160| Table | Key Fields |161|-------|-----------|162| `task` | title, priority, dueDate, completed |163| `memory` | chatId, category, content, originalText |164| `letter` | content, status (DRAFT/SENT), lobId, sentAt |165| `log` | level, source, message |166| `usage` | model, promptTokens, completionTokens, totalTokens |167| `update` | title, content, type |168169## Bridge MCP Tools170171| Tool | Purpose |172|------|---------|173| `telegram_get_pending_messages` | Fetch & mark messages as processing |174| `telegram_send_reply` | Queue a reply (with optional messageId) |175| `telegram_bridge_status` | Status snapshot |176| `telegram_receive` / `telegram_send` | Compatibility aliases |177| `bridge_health` | Detailed peer reachability |