How avijeett007/knotie-ai works
Project type and purpose
• Knotie-AI is a full-stack, open-source inbound/outbound AI Sales Agent.
• It consists of a Python/Flask web application with a minimal frontend (Jinja templates), a modular AI orchestration layer, a conversation caching subsystem, and integrations with external services (OpenAI API, Twilio, third-party tools).
File structure
• Top-level entrypoints:
• app.py (Flask server)
• Dockerfile & docker-compose*.yml (containerization & multi-service orchestration)
• Frontend:
• templates/index.html (public UI)
• templates/admin.html (admin UI)
• Backend modules:
• ai_helpers.py, audio_helpers.py, appUtils.py (core utilities & wrappers)
• prompts.py, stages.py, tools.py, tools_helper.py (AI prompt orchestration & tool/plugin layer)
• ConversationCache/ (state management package, uses Redis via CacheManager.py)
• Model training:
• Ai_Model_Training/… (scripts to prepare JSONL & train OpenAI models)
• Config & deployment:
• config.py, .env_sample (configuration)
• .github/workflows/*.yml (CI/CD pipelines)
• openapi_specs/ (future OpenAPI/Swagger support)
• Docs:
• docs/ (installation, deployment, how-to guides)
README for additional insights
• Confirms Python/Flask, Redis cache, OpenAI integration, Twilio support, Dockerized deployment, and an admin UI.
• Future features hint at plugin-style tool integration and OpenAPI spec support.
Main components & their relationships
a. Client Layer
• Web Browser → HTTP/WS → Flask server
• Uses index.html (public) or admin.html (admin UI)
b. Web/API Layer (Flask)
• Routes in app.py invoke appUtils, ai_helpers, audio_helpers
• Exposes REST/Webhook endpoints for external systems
c. Conversation Cache
• ConversationCache.CacheManager (Redis backend)
• Decorators enforce singleton, config loaded from Configuration.py
d. AI Orchestration Layer
• prompts.py & stages.py: define prompt templates & multi-step flows
• tools.py & tools_helper.py: plugin architecture for calling external APIs (Twilio, third-party tools)
• ai_helpers.py: wrapper around OpenAI API calls
e. Persistence & Messaging
• Redis (state/cache) via docker-compose
• File-based logs or .jsonl training data in Ai_Model_Training
f. External Services
• OpenAI API (chat completion, embeddings)
• Twilio (SMS/Voice)
• Future: other SaaS via plugin modules
g. DevOps / CI-CD
• Dockerfile & docker-compose (local dev, prod deploy, Redis only)
• GitHub Actions (build, test, docker image publish)
• retype.yml & retype.json (documentation site generation)
Architectural patterns & design principles
• Layered MVC-style separation: Presentation (templates) → Controller (Flask routes) → Model/Service (AI orchestration & cache)
• Plugin/Strategy pattern for external tools
• Singleton pattern for cache manager
• Containerized micro-services style (Flask app + Redis)
Essential elements
• Clear component names:
• Client UI, Flask Server, ConversationCache, AI Orchestrator, External Services
• Data flows & dependencies: annotate with “prompt data,” “cache lookup,” “AI response,” etc.
• Technology callouts: Python/Flask, Jinja2, Redis, OpenAI API, Docker, GitHub Actions