Local AI Microservice Mesh Context
This document provides full, deep context awareness for AI agents working on the
Local AI Microservice Mesh Context
This document provides full, deep context awareness for AI agents working on the docker-compose-ai-gateway project. It summarizes the architecture, developer workflow, configuration hierarchy, and key operational concepts.
System Architecture & Request Flow
The system is a locally runnable, multi-container microservice mesh where an AI
classifier (ai_router) predicts backend routing based on natural language
intent.
- Gateway: Serves the UI, applies routing policy (
T_ROUTE,T_MARGIN), proxies requests, and aggregates application-level traces. - AI Router: Lightweight intent classifier (TF-IDF + Logistic Regression).
Returns
route,confidence,probabilities, andexplanation(top contributing tokens). - Backends:
search_service,image_service,ops_service. - Trainer Profile: One-shot container that trains
model.joblibfromtrain.csvand outputsmetrics.jsonandmisclassified.csvto a shared volume (model_artifacts). - Refiner Profile / Training API: Improves the dataset via relabeling and
augmenting using Ollama (phi3:mini). Orchestrated via the
training-api. - Redis: Maintains job states and handles Pub/Sub for Server-Sent Events (SSE) to send completion events to the UI.
Configuration & Environment Variables
Configuration follows a rigid hierarchy to ensure reproducibility:
- Source of Truth:
config/PROJECT_CONFIG.yaml(containsdefault,dev, etc. environment sections). - Generation:
scripts/generate_env.pyreadsdefault.ENV(fallbackdev) unless an explicit<env>is passed, then createsenv/.env.<env>. - Consumption: Docker compose files reference the generated
.envfile via theenv_filedirective.
Critical Note: Never hardcode configuration in code or Compose. Edit
PROJECT_CONFIG.yaml and regenerate the env files.
Local LLM Integration (Ollama)
The Refiner relies on Ollama for dataset improvement. Two modes are supported,
defined in OLLAMA_MODE:
native: Connects to Ollama running on the host machine.container: Spins up anollamacontainer alongside the stack via therefine-containerprofile.
Key Developer Scripts
The scripts/demo.sh script is the primary control plane for local operations.
- Start Stack:
./scripts/demo.sh run [--dev](uses dev overlay for reload) - Stop/Teardown:
./scripts/demo.sh stop,restart,delete, orreset(full teardown and rebuild) - Testing:
./scripts/demo.sh test [all|gateway|ai_router]or rawpytest - Train Route:
./scripts/demo.sh train - Refiner Route:
./scripts/demo.sh refine(runs relabel & augment), followed by./scripts/demo.sh promote(promotes candidate if better). - Standalone refine:
scripts/refine_relabel.shandscripts/refine_augment.shfor running phases outsidedemo.sh. - Other utilities:
logs,scaling,failure,curl,load-test.
Technical Policies for Agents
- Routing Thresholds: AI Router returns raw probabilities. The Gateway
enforces the actual routing via
T_ROUTE(minimum confidence) andT_MARGIN(gap between top 2 routes). Do not implement policy in the model code. - One-Shot Training: Training is intentionally not a long-running API. The
trainercontainer spins up, readstrain.csv, writesmodel.joblib, and terminates. - Security rules: All operations are offline. Respect structural bounds
and do not run
catin bash to write files. Always utilizesnyk_code_scanfor new lines of code.
[!TIP] Always review
docs/auxiliary/architecture/TECHNICAL.mdbefore making structural changes to the AI router or gateway.
Related Documents
Design Document: BharatSeva AI
BharatSeva AI is a multi-agent orchestration system built on AWS using Amazon Bedrock Agents with Claude 3.5 Sonnet as the foundation model. The system deploys 10 AI agents (1 Master Orchestrator + 9 Specialist Agents) to assist India's informal sector workers in navigating government schemes across three domains: PM Vishwakarma (artisan credit), PMFBY (crop insurance), and BOCW (construction worker welfare).
OpenClaw Enterprise Transformation Plan
Transform OpenClaw from a single-user personal AI assistant into a **dual-mode platform** that is simultaneously:
Qwen Image and Edit: Open-sourcing and Local GGUF Generations with Lightning
Daniel Sandner, for article on https://sandner.art/
Qwen3-TTS — Model Reference
Models: `Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice` and `Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice`