Skip to main content

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.

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.

A participant interacting with Guruzin during the MBSR program via WhatsApp.

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

LayerTechnologyRole
Orchestrationn8n (Railway)Workflow engine, all logic runs here
ChannelsTelegram · WhatsApp (Twilio)Message in/out
DatabaseSupabase (PostgreSQL + pgvector)State, history, embeddings
Edge FunctionsSupabase (Deno/TypeScript)Serverless business logic
LLMOpenAI GPT-4o-miniConversation + tool calls
EmbeddingsOpenAI text-embedding-ada-002RAG vector search
AuthHotmart webhookPurchase to access provisioning
DeployRailway (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.

Supabase

Supabase

PostgreSQL + pgvector for state, conversation history, and RAG embeddings. Edge Functions run the serverless business logic.

n8n

n8n

Visual workflow engine that replaced a custom backend. All routing, LLM calls, scheduling, and channel delivery run here.

WhatsApp

WhatsApp

Primary channel for the production program. Participants receive daily practices and reminders without installing anything.

OpenAI

OpenAI

GPT-4o-mini handles conversation and tool calls. text-embedding-ada-002 powers the RAG vector search.

Hotmart

Hotmart

Purchase webhook is the only entry point for new users. HMAC-validated event triggers account provisioning automatically.

Railway

Railway

PaaS container for self-hosted n8n. Zero ops: Railway handles restarts, SSL, and environment variable injection.

Telegram

Telegram

Prototype and secondary channel. The entire conversational flow was built and validated here before touching WhatsApp.

OpenRouter

OpenRouter

Fallback routing layer for provider resilience. Switches to alternative models when the primary provider returns errors.