Kaizen — AI-Native Personal Operating System
Overview
Kaizen is an AI-native personal operating system for habits, goals, journaling, and reviews, built around a Coach that acts on the user's data rather than merely discussing it. Ask it to "add a habit to read every morning and create a goal to run a 5K next month" and it creates both — reload the page and the rows are genuinely there. It does this through a streaming tool-use loop exposing 12 tools, each bound to the same service-layer functions the REST API calls, so the agent writes through identical validated code paths as the UI. Built on FastAPI and SQLAlchemy 2.0 with Postgres/pgvector and a Next.js App Router frontend.
Challenges & Solutions
The core design problem was making an LLM a trustworthy actor on real user data rather than a chat surface bolted onto a CRUD app. The governing decision was to give the model no privileged write path: its tools dispatch to the very same service functions the UI calls, so the agent cannot bypass validation or drift from application invariants. Beyond that the model had to stay grounded — it is instructed to read current dashboard state before offering progress advice, and the system prompt injects the user's real timezone and current datetime so relative expressions like "tomorrow at 7am" resolve to correct ISO datetimes instead of plausible-looking guesses. Multi-round tool use streams to the client over SSE, so the user watches tool activity unfold rather than waiting through a silent pause. A secondary goal was avoiding vendor lock-in: a single provider interface that both Anthropic Claude and OpenAI implement against the same streaming contract, with every AI path degrading gracefully when no key is configured at all.
Technical Achievements
- Agentic tool-use loop exposing 12 tools — create_goal, log_habit, add_journal_entry, generate_review, query_knowledge, schedule_event, send_email and others — each dispatched against the same service layer the REST API uses, so the agent has no separate, less-validated route into the database
- Provider-neutral LLM abstraction: a single stream_agent contract implemented by both an Anthropic provider (streaming with adaptive thinking, preserving thinking and redacted_thinking blocks across tool rounds) and an OpenAI provider (function calling), selected at runtime by a factory based on whichever key is available
- Server-Sent Events streaming of both tokens and tool invocations, so a multi-round agent turn renders as visible, legible activity rather than a long silent wait
- Prompt grounding for correctness: the system prompt injects the user's real timezone and current datetime so relative scheduling resolves to exact ISO datetimes, and requires the model to read dashboard state before giving progress advice — keeping it anchored to actual data instead of plausible invention
- Semantic knowledge search over pgvector with a pluggable embedding backend (Voyage AI or OpenAI, both normalized to 1024 dimensions so the vector column stays provider-agnostic) and automatic keyword fallback when embeddings are unavailable
- Natural-language capture: a structured-output call converts a single free-form sentence into a typed goal, habit, or journal draft returned as strict JSON, surfaced as an editable confirmation card rather than written blindly
- Bounded, resilient execution: the tool loop is iteration-capped, and every AI path degrades to a clear message when no API key is present while the rest of the application remains fully usable
- Google Calendar OAuth (read and write) with tokens encrypted at rest via Fernet, making the Coach schedule-aware and able to create real calendar events
- Full-stack delivery: a 14-table relational model, roughly 7,500 lines across a FastAPI backend and Next.js App Router frontend, with Dockerized Postgres and pgvector