OptiEngine
Your Agents should follow Org's standards
Created on 28th February 2026
•
OptiEngine
Your Agents should follow Org's standards
The problem OptiEngine solves
Problem Statement
The problem OptiEngine solves is not that AI writes bad code. It's that AI writes code without knowing your organization. Every engineering team has accumulated years of hard-won decisions — which libraries to use, how to handle auth, when to paginate, how to protect sensitive data. These decisions live in ADRs nobody reads, in senior engineers' heads, and in PR review comments that arrive after the damage is done. When a junior developer opens Cursor or Claude and types a prompt, the AI is extraordinarily capable — but completely blind to your organization's standards.
It doesn't know you mandated React Query over useEffect.
It doesn't know your sales data needs a 5-minute staleTime.
It doesn't know revenue figures need a PermissionGate.
It generates code that is technically correct and organizationally wrong.
The result is a review cycle where senior engineers spend 45 minutes per PR catching violations that should never have been written.
For a team of 8, that's 1,200+ minutes of senior review time per week — not reviewing logic, not improving architecture — just enforcing known standards that the AI didn't know existed.OptiEngine makes organizational coding standards machine-executable.
It sits between the developer's prompt and the code generator as an MCP server, intercepts every prompt, retrieves the 3-5 most semantically relevant rules from a domain-isolated vector database, rewrites the prompt with those rules as hard mandatory requirements, and hands the enhanced prompt to the AI.
The developer typed regular prompt. The AI receives a enhanced prompt mentioning engineering specifications followed across the organization. The code comes out compliant on the first generation.

What it does -- Feature List
Semantic RAG Pipeline
Rules are stored as embeddings in ChromaDB using all-MiniLM-L6-v2. When a developer writes a prompt, the system queries both the global collection and the domain-specific collection in parallel, ranks candidates by cosine distance, and retrieves only the rules semantically relevant to that specific prompt. A developer asking about inventory hooks gets PermissionGate and ErrorBoundary rules. They never see JWT signing rules or AI streaming rules — those live in different collections.
Domain Isolation
Each team operates in a hard-isolated ChromaDB collection — guidelines_web, guidelines_backend, guidelines_ai. There is no metadata filtering that can be bypassed. A Web developer's prompt physically cannot retrieve Backend rules. This mirrors how real organizations work — the React team doesn't need to know bcrypt cost factors.
MCP Integration
The enhancement pipeline runs as a FastMCP server connected to Cursor via stdio. Every prompt the developer writes in Agent mode is intercepted by enhance_development_prompt before any code is generated. The interception is invisible to the developer — they type naturally, the tool fires automatically, and the enhanced prompt is what the LLM sees.
ADR Auto-Ingestion
Tech Leads paste any Architecture Decision Record into the control plane. Groq reads the document and extracts 5-15 atomic, enforceable rules automatically. The Staff Engineer reviews, edits, approves or skips rules individually, then ingests with one click. Rules are live in ChromaDB immediately — the next developer prompt fires them with no restart required.
Prompt Injection Defense
All user inputs are sanitized through a regex-based pattern detector before reaching the RAG pipeline. Attempts to override instructions, inject roles, or bypass rules are redacted and logged as security warnings. The system returns HTTP 422 with PROMPT_INJECTION_DETECTED rather than silently passing the flagged prompt.
Graceful Degradation
If Groq fails, the system appends raw rule text as structured directives rather than blocking the request. If ChromaDB returns zero matches, the original prompt passes through with a loud warning: DEGRADED MODE — MUST be reviewed by senior engineer before merge. Failures are never silent.
Live Demo Dashboard
A Next.js dashboard hits the live backend in real time — showing which rules fired for any prompt, their exact semantic distances from ChromaDB, the before and after prompt transformation, and side-by-side code generated from the raw prompt versus the enhanced prompt using the same model.

Challenges we ran into
1. The Relevance Threshold Problem
The hardest calibration problem in the entire system. Set RELEVANCE_THRESHOLD too low and only highly specific rules fire — a developer asking about "sales data" might not trigger the "use cursor pagination" rule even though they should. Set it too high and every prompt retrieves 15 loosely-related rules, bloating the enhanced prompt with irrelevant directives that confuse the LLM.
The solution was switching from Euclidean distance to cosine similarity in ChromaDB by setting hnsw:space=cosine on collection creation, then logging all candidate distances on every retrieval call. This let us empirically observe that related rules cluster between 0.35–0.75, loosely related rules sit between 0.75–1.0, and truly irrelevant rules are above 1.0. Setting the threshold at 1.0 and taking the top 5 candidates gave the right balance — specific enough to be useful, broad enough to catch non-obvious relationships like "inventory stock" triggering "PermissionGate for sensitive data."
2. The Venv Path Corruption Bug
The project folder was renamed mid-development from OptiEngne to OptiEngine — one missing letter. The virtual environment had the old path hardcoded in every launcher script inside .venv/Scripts/. Every attempt to run Python, pip, or uvicorn failed with ENOENT — the executable existed but the path inside it pointed to a folder that no longer existed. Cursor's MCP spawn also failed with ENOENT for the same reason — it was trying to launch the old Python path.
The fix was deleting the entire .venv directory and rebuilding it from scratch. Three hours were lost to this before identifying the root cause by diffing the path strings character by character.
3. Groq Model Decommission Mid-Build
llama3-8b-8192 was deprecated by Groq during active development. The model returned HTTP 400 with model_decommissioned after working correctly for weeks. The retry logic in prompt_builder.py made this worse — it retried twice, both failed, then fell back to raw rule injection. The fallback worked but stripped the Groq synthesis quality from the enhancement, making enhanced prompts look like raw bullet lists instead of coherent engineering specifications.
Fix was a one-line model name change to llama-3.1-8b-instant. The lesson was that model names should be environment variables, not string literals — a change that's now in the codebase.
4. The Contaminated Blind Test
When testing "MCP off versus MCP on" to demonstrate the difference, the MCP-off results looked nearly identical to MCP-on results. The reason: the MCP-on generation had already created useSalesData.js with React Query, staleTime, and Zod in the project. When MCP was disabled for the comparison run, Cursor's codebase indexer read those existing files and mirrored the patterns — not because it followed the rules, but because it copied what was already there.
This required redesigning the test to use a feature the codebase had no existing example of — an inventory hook instead of a sales hook. Without a prior implementation to mirror, Cursor fell back to raw LLM knowledge and generated Python instead of TypeScript, with no React Query, no Zod, and no role checks. The contrast became undeniable.
5. Browser CORS Blocking Direct LLM API Calls
The demo dashboard was designed to call the Anthropic API directly from the browser to generate side-by-side code comparisons. This failed with a CORS error — Anthropic blocks browser-origin requests by design, and exposing the API key client-side is a security violation regardless.
The fix was a Next.js API route at /api/generate that proxies the generation call server-side. The browser calls its own origin, the Next.js server holds the API key in .env.local, and the key is never exposed to the client. Switching from the Anthropic SDK to Groq for generation also simplified the integration since the same GROQ_API_KEY already present in the environment could be reused.
6. The "Just Use a JSON File" Objection
Not a technical challenge but a product challenge that required rethinking the demo entirely. During testing, the MCP-off generation with guidelines.json present in the project produced code nearly as good as the MCP-on generation. This appeared to invalidate the core value proposition.
The resolution was understanding and articulating three distinct failure modes of the JSON file approach that only appear at scale: context window saturation with 200+ rules, inconsistent rule weighting by the LLM across different prompts, and the absence of any organizational control or audit trail. The demo was redesigned to remove guidelines.json entirely from the project, making OptiEngine the only source of standards knowledge and the contrast clean and honest.
Tracks Applied (1)
Gemini API
Major League Hacking
Technologies used
