Development Notes - AI Agent Server
- **Initial project structure and boilerplate**: Used AI to scaffold the basic Express.js server setup
Development Notes - AI Agent Server
๐ค AI-Generated vs. Manual Implementation
AI-Generated Content:
- Initial project structure and boilerplate: Used AI to scaffold the basic Express.js server setup
- TypeScript configurations: AI helped with tsconfig.json and package.json setup
- Basic prompt engineering: Initial system prompt structure was AI-assisted
- Documentation: README.md structure and API examples were AI-generated
- Error handling patterns: Standard try-catch patterns were AI-suggested
Manual Implementation:
- Custom embedding system: Built from scratch using word frequency and semantic features
- Cosine similarity algorithm: Implemented custom vector similarity calculation
- Plugin detection logic: Designed custom intent detection patterns
- Memory management: Built session-based conversation memory system
- RAG retrieval logic: Custom implementation for document chunking and retrieval
- Weather API integration: Manual OpenWeather API integration with city extraction
- Math plugin security: Implemented mathjs for safe mathematical evaluation
๐ Bugs Faced and Solutions
1. ES Module Import Issues
Problem: TypeScript ES module imports with .js extensions
Solution: Added "type": "module" to package.json and used .js extensions in imports
2. Vector Similarity Performance
Problem: Initial embedding system was too simplistic Solution: Enhanced with semantic features (markdown detection, code blocks, links) and word hashing
3. Plugin Intent Detection
Problem: Basic keyword matching missed complex queries Solution: Implemented regex patterns for math detection and comprehensive weather keywords
4. Memory Persistence
Problem: In-memory storage lost data on server restart Solution: Designed for session-based memory (can be extended to database storage)
5. Document Chunking
Problem: Large documents created poor retrieval results Solution: Implemented paragraph-based chunking with size limits (500 chars)
๐ Agent Routing Logic
Message Flow:
- Input Validation: Check for required
session_idandmessage - Memory Retrieval: Get last 2 conversation turns for context
- RAG Processing:
- Embed user message using custom embedding function
- Calculate cosine similarity with all document chunks
- Select top 3 most relevant chunks with diversity
- Plugin Detection:
- Weather: Check for weather-related keywords
- Math: Use regex to detect mathematical expressions
- Plugin Execution: Run detected plugins and capture output
- Prompt Assembly: Combine memory, context, and plugin outputs
- LLM Call: Send to Groq API with structured prompt
- Response Processing: Save to memory and return to user
Key Design Decisions:
- Custom Embeddings: Built lightweight embedding system for better control
- Session Memory: Simple in-memory storage for conversation continuity
- Plugin Architecture: Extensible system for adding new capabilities
- Error Resilience: Graceful fallbacks when plugins or LLM calls fail
๐ฏ Technical Highlights
Vector Search Implementation:
- Custom 100-dimensional embeddings using word frequency and semantic features
- Cosine similarity for document retrieval
- Diversity-based selection to avoid similar chunks
Plugin System:
- Intent detection using keyword matching and regex patterns
- Extensible architecture for adding new plugins
- Secure math evaluation using mathjs library
Memory Management:
- Session-based conversation history
- Automatic cleanup of old sessions (can be extended)
- Context injection for conversation continuity
๐ Deployment Considerations
The project is ready for deployment on:
- Render: Add
startscript and environment variables - Railway: Direct deployment from GitHub
- Vercel: Serverless function deployment
- Replit: Direct deployment with environment setup
Environment variables needed:
GROQ_API_KEY: For LLM API accessOPENWEATHER_API_KEY: For weather pluginPORT: Server port (optional, defaults to 3000)
Related Documents
SUMMARY
permalink: ai-implementation
Retrieval & Prompts
Retrieval quality depends on two things: **what the extraction prompt produces**, and **how Vector Storage is configured**. Most people start with Vector Storage settings โ but the bigger lever is the prompt. A well-structured memory block retrieves accurately even with default settings. A poorly structured one won't retrieve well no matter how much you tune.
App Review Support Guide โ Switch2Go
Switch2Go is an **AAC (Augmentative and Alternative Communication)** app designed specifically for users with **Cerebral Visual Impairment (CVI)**. It allows non-verbal or communication-impaired users to compose and speak phrases entirely hands-free using:
RFC-BLite: High-Performance Embedded Document Database for .NET
**Status:** Draft (living document)