Guruzin
Designed and built an AI mindfulness agent end to end: prompt engineering, RAG pipeline, and production deployment, running an 8-week MBSR program on WhatsApp and Telegram.
My Role
AX designer and developer. Concept, architecture, prompt engineering, integrations, and production deployment.
By the numbers
Production system rebuilt in January 2026. The n8n workflow is 118 KB of orchestration logic, running 4 active workflows and 13 Supabase edge functions across 2 channels. Pilot consumed 608,000 tokens across 256 LLM calls at a total cost of ~$0.13.
WhatsApp conversation
A participant interacting with Guruzin during the MBSR program via WhatsApp.
n8n workflow walkthrough
Walking through the full conversation workflow canvas in n8n.

Project overview
No issues flagged by the advisor on the production branch.

RAG embeddings table
69 prompt assets indexed by week phase, each with a pgvector embedding for semantic retrieval.

Edge Functions
15 deployed functions: locks, embeddings, report generation, user context, and reminder delivery.

System prompt
GPT-4o-mini configured with a hierarchical mission: remember, clarify, record, export report.

Model parameters
Max tokens 500, temperature 0.3. Context assembled from upstream nodes at runtime.

Semantic search node
Calls the Supabase Edge Function with the user message, threshold 0.7, and top-3 match count.

Reminder scheduler
Daily cron at 07:00 routing reminders to WhatsApp or Telegram. 10+ consecutive successful runs.

Main conversation flow
Intent routing, RAG pre-fetch, OpenAI call, tool-call check, rate limiting, and error handling.
Stack
| Layer | Technology | Role |
|---|---|---|
| Orchestration | n8n (Railway) | Workflow engine, all logic runs here |
| Channels | Telegram · WhatsApp (Twilio) | Message in/out |
| Database | Supabase (PostgreSQL + pgvector) | State, history, embeddings |
| Edge Functions | Supabase (Deno/TypeScript) | Serverless business logic |
| LLM | OpenAI GPT-4o-mini | Conversation + tool calls |
| Embeddings | OpenAI text-embedding-ada-002 | RAG vector search |
| Auth | Hotmart webhook | Purchase to access provisioning |
| Deploy | Railway (PaaS container) | n8n self-hosted, zero ops |
Prompt engineering
The system prompt is structured in XML blocks. XML gives the model unambiguous section boundaries and makes the prompt auditable: each block has a clear owner and a testable output.
Mindfulness practice names are hardcoded in <canonical_practices>. The model is forbidden from inventing practice names. If it can't match a canonical name, it must ask the user to clarify.
The 4-question registration flow runs in enforced sequence. Few-shot examples in the prompt show correct and incorrect paths. The LLM is not trusted to improvise the flow.
California SB 243 (Jan 2026) requires chatbots in mental health contexts to disclose AI identity, refer to crisis lines, and prompt breaks in long sessions. All three are enforced in the system prompt. A Filter Response node in n8n runs a regex blocklist against every output before it reaches the user, catching diagnostic or prescriptive language regardless of what the LLM generated.
RAG pipeline
The knowledge base is structured as prompt_assets rows in Supabase, each tagged with a program_phase (week_1 through week_8). A user in week 1 asking "what should I practice?" gets body scan instructions, not week 6 content. The phase filter is what delivers the right answer without the LLM guessing.
Retrieval runs as a separate n8n workflow called as an OpenAI tool: it receives the user's message and current program phase, generates an embedding, runs cosine similarity search via pgvector, and returns the top 3 matched chunks (similarity threshold 0.7) formatted for injection into the prompt.
n8n as the orchestrator
n8n replaced what would otherwise be a custom backend. All application logic (routing, state checks, LLM calls, database writes, sending messages) lives in visual workflows.
The main conversation workflow handles both Telegram and WhatsApp through the same logic path:
Telegram Trigger / Twilio Webhook
→ Parse Message + Intent Detection
→ get-or-create-user-context ← Supabase edge fn
→ Authorization check
→ OpenAI GPT-4o-mini
→ [tool call] Prompt Assets RAG workflow
→ Filter Response (blocklist regex)
→ save-message ← Supabase edge fn
→ Send reply (Telegram API / Twilio REST)
Telegram to WhatsApp: why and how
WhatsApp Business API has friction: templates require Meta approval, cold outreach outside 24 hours requires approved template IDs, and every session message costs money. Telegram has none of this. The entire conversation flow, registration logic, and RAG integration was built and validated on Telegram before a single WhatsApp message was sent.
Daily reminders are cold outreach by definition. The Reminder Scheduler checks the timestamp of the user's last inbound message: if under 24 hours it sends a free-form session message, if over 24 hours it sends the approved reminder template. No custom code required.