An advanced AI agent system that adapts its responses based on contextual rules stored in a database, inspired by Parlant.io's approach
MHR Agent | Overview β’ Features β’ Architecture β’ Quick Start β’
This MVP demonstrates a sophisticated approach to AI agent customization where behavioral guidelines are:
- Dynamically loaded from a PostgreSQL database (Supabase)
- Contextually matched using both semantic search (vector embeddings) and text matching
- Intelligently applied based on conversation context and priority
- Tracked and optimized to prevent repetitive responses
The system is demonstrated through a Spanish mid-term rental company (1-6 months stays) with guidelines for:
- Sales conversations (pricing, availability, benefits)
- Property management (maintenance, check-in/out)
- General customer service
The MVP features a unique comparison interface showing two guideline matching approaches side-by-side:
- Text Matching: Traditional keyword and pattern matching
- Vector/Semantic Matching: AI-powered understanding using OpenAI embeddings
This allows real-time comparison of both methods' effectiveness.
- Guidelines follow "When [condition], then [action]" format
- Priority-based selection (0-10 scale)
- Category organization (sales, management, general)
- Active/inactive status for easy management
- Hybrid Matching: Configurable blend of semantic and text matching (default 80/20)
- Context Awareness: Considers conversation flow and previous messages
- Category Continuity: Boosts guidelines in the same category as previous ones
- Prevents guideline overuse within sessions
- 5% score reduction per use
- Session-based tracking
- Detailed usage analytics
- Split-screen comparison of matching methods
- Real-time response generation
- Usage statistics visualization
- Response time tracking
- Tab and split view modes
- RESTful endpoints for all operations
- Session management
- Guideline CRUD operations
- Analytics and monitoring
- Embedding management
- Framework: Hono (lightweight, fast web framework)
- Language: TypeScript with Node.js
- Database: Supabase (PostgreSQL + pgvector for embeddings)
- AI Integration: OpenAI API
- Embeddings: OpenAI text-embedding-3-small model
- Framework: Preact with TypeScript
- Build Tool: Vite
- Styling: Tailwind CSS + DaisyUI
- Icons: Lucide React
- Node.js 22.x or higher
- Docker (for Supabase local development)
- OpenAI API key
-
Clone the repository:
git clone https://github.com/adrifdez/upmvp.git cd upmvp -
Install dependencies:
# Backend dependencies npm install # Frontend dependencies cd client && npm install && cd ..
-
Set up the database with pgvector:
npm run setup
This will:
- Start Supabase local development stack
- Create all tables with pgvector support
- Load sample guidelines
You need to copy anon key to .env SUPABASE_ANON_KEY and service_role key to .env SUPABASE_SERVICE_ROLE_KEY
-
Start the development servers:
# Terminal 1: Backend server (port 3001) npm run dev # Terminal 2: Frontend dev server (port 5173) npm run dev:client
- Access to http://localhost:3001 and click 'Generate All Embeddings'
- Access the app at http://localhost:5173
This MVP demonstrates a guideline-aware AI system with:
- Dynamic Guidelines: AI behavior rules stored in a database
- Semantic Search: Vector embeddings for better guideline matching
- Context Awareness: Guidelines applied based on user message content
- Hybrid Matching: Combines semantic search with keyword matching
- Usage Tracking: Prevention of repetitive responses
npm run dev # Start backend development server
npm run dev:client # Start frontend development server
npm run build # Build both backend and frontend
npm run start # Start production server
npm run setup # Complete database setup with pgvector
npm run db:reset # Reset database and apply migrations
npm run db:seed # Load sample guidelines
npm run typecheck # Run TypeScript type checkingupmvp/
βββ src/
β βββ server.ts # Main server file
β βββ services/ # Core business logic
β βββ routes/ # API endpoints
β βββ types/ # TypeScript types
βββ client/
β βββ src/ # React frontend
β βββ public/ # Static assets
βββ supabase/
β βββ migrations/ # Database schema
β βββ seed.sql # Sample data
βββ scripts/
β βββ setup-db.sh # Database setup script
βββ public/ # Frontend files (Phase 3)
GET /health- Health checkPOST /api/chat- Main chat endpoint{ "message": "Your message here", "sessionId": "optional-session-id" }GET /api/guidelines- List all guidelinesPOST /api/guidelines- Create new guideline
GET /api/embeddings/status- Check embeddings system statusPOST /api/embeddings/generate- Generate embeddings for guidelinesPOST /api/embeddings/test- Test vector search
- Stores behavioral rules with conditions and actions
- Includes priority and category
- Full-text search enabled on conditions
- Tracks chat sessions and message history
- Maintains list of used guidelines per session
- Analytics for guideline activation
- Tracks scoring and actual application
-
Basic chat test:
curl -X POST http://localhost:3001/api/chat \ -H "Content-Type: application/json" \ -d '{"message": "What are your prices?"}'
-
View guidelines:
curl http://localhost:3001/api/guidelines
-
Access Supabase Studio: Open http://localhost:54323 in your browser
# Check if Docker is running
docker ps
# Reset Supabase
npm run supabase:stop
npm run supabase:start# Check Supabase status
npm run supabase:status
# Reset database
npm run db:reset- API runs on port 3001 (configurable in .env)
- Supabase Studio: 54323
- PostgreSQL: 54322
- Guidelines use a "When X, then Y" format
- Priority ranges from 0-10 (higher = more important)
- Guidelines can have relationships (requires/excludes)
- Sessions prevent guideline repetition
ISC