Building Zorgax in Production: Hybrid AI Routing, Grounding, Fallbacks, and UX
Building an AI chatbot is easy.
Building an AI feature that survives production is a very different problem.
Over the last development cycle, we evolved Zorgax, the AI copilot inside MyZubster, from a simple conversational interface into a hybrid AI layer with model routing, cost controls, fallback logic, product grounding, runtime observability, and tighter integration with the rest of the platform.
The most interesting lesson was that the LLM API call ended up being one of the smallest parts of the system.
The goal
Zorgax is designed to act as the conversational entry point to MyZubster.
A user should be able to ask a normal question, explore the Marketplace, understand a LIFE Pilot, start a Seller journey, navigate the Metaverse, or receive guidance about the wider ecosystem.
But we did not want every request to go through the same AI model.
A simple message such as:
Ciao Zorgax
does not need the same infrastructure as:
Analyze the current LIFE workflow, evaluate KPI/MRV evidence,
and explain the deployment and repository architecture.
So we introduced a routing layer.
Hybrid model routing
The current architecture separates requests into broad standard and complex categories.
Research mode, long prompts, and signals related to coding, deployment, research, LIFE, KPI/MRV, automation, GitHub, or Vercel can move a request into the complex route.
Conceptually:
const tier =
useResearch ||
complexSignalCount >= 2 ||
text.length >= 2500
? "complex"
: "standard";
The architecture then becomes:
User
↓
Zorgax API
↓
Task classification
↓
AI Router
├── Standard → Ollama / general AI gateway
│
└── Complex / Research → OpenAI
↓
fallback
This gives us a hybrid system instead of making the whole product dependent on one remote provider.
Making the model visible
One of the first improvements was exposing the actual route used by the backend.
The API returns metadata like:
{
"ai_provider": "openai",
"ai_model": "gpt-5.6-sol",
"ai_fallback_reason": null
}
The interface displays it directly below the response:
AI: OpenAI · gpt-5.6-sol
If something goes wrong:
AI: Ollama · qwen2.5:3b · fallback: openai_rate_limit
This looks like a small UI feature, but operationally it changes a lot.
We no longer have to ask:
Did OpenAI actually generate this answer?
The application tells us.
The first production surprise
Once OpenAI routing was enabled, the first production request did not succeed.
Zorgax returned a valid answer, but the logs showed:
aiProvider: ollama
aiModel: qwen2.5:3b
aiFallbackReason: openai_error
The OpenAI call had returned HTTP 429.
At first, that was not enough information.
A 429 can represent very different conditions: a temporary rate limit, exhausted API credits, a project spending limit, or another usage restriction.
So we improved the error handling rather than simply retrying blindly.
Precise OpenAI diagnostics
Zorgax now extracts safe diagnostic information from failed requests:
HTTP status
error code
error type
request id
without exposing credentials.
Fallback states can now be much more precise:
openai_credit_balance_exhausted
openai_rate_limit
openai_rate_limit_exceeded
openai_project_spend_limit_exceeded
That immediately paid off.
Our next production test returned:
openai_credit_balance_exhausted
The application was working correctly. The account simply had no API credit.
After adding credit, the next request succeeded with:
AI: OpenAI · gpt-5.6-sol
and production logs confirmed:
aiProvider: openai
aiModel: gpt-5.6-sol
aiFallbackReason: null
That was the first full end-to-end verification.
Retry without retrying everything forever
Transient failures still need resilience.
For rate-limit-style failures, Zorgax now has controlled retry behavior.
The primary route can retry once, respecting Retry-After when the wait is short enough. A secondary OpenAI model can then be attempted before the system falls back to the local/general route.
The flow is roughly:
gpt-5.6-sol
↓
controlled retry
↓
secondary OpenAI model
↓
Ollama fallback
Quota errors are different.
If the API explicitly says credits are exhausted, retrying repeatedly would only waste time, so the fallback happens immediately.
That distinction is important: resilience does not mean retrying every failure.
Cost controls belong in the architecture
Remote AI usage also needs application-level cost controls.
Before sending a complex request, Zorgax checks its monthly OpenAI budget and reserves enough capacity for the request.
The flow looks like this:
Classify request
↓
Check monthly spend
↓
Estimate request cost
↓
Reserve budget
↓
Call OpenAI
↓
Record actual usage
↓
Settle reservation
If the reservation cannot be made, the conversation can continue through the fallback path.
We also record the model that actually completed the request, so usage accounting still makes sense if a secondary OpenAI model is used.
Grounding became the harder problem
Once OpenAI was running correctly, another issue appeared.
The model became too conservative.
We asked Zorgax which MyZubster features were live, experimental, planned, or unverified.
The answer classified nearly everything as unverified.
That was technically cautious, but it was also wrong.
The reason was architectural: the OpenAI route and the Ollama route were not receiving exactly the same runtime product context.
The local route had product facts.
The OpenAI route mostly had the system persona and the user message.
So instead of weakening our anti-hallucination rules, we fixed the input architecture.
One canonical runtime context
Both model paths now receive the same canonical product context.
It includes facts such as:
myzubster.com is live
/marketplace is an implemented route
Seller starts from Marketplace
/social-login is the authentication path
/metaverse is an implemented route
/life-pilot is an implemented pilot path
MYZ is internal reward/accounting
It also contains an important rule:
A live route does not prove every possible feature associated with that route.
That distinction prevents two opposite failures.
The assistant should not invent features that do not exist, but it should also not deny the existence of routes that are actually implemented.
Product state as part of the prompt
Zorgax now reasons with four capability states:
LIVE / IMPLEMENTED
PILOT / EXPERIMENTAL
PROPOSED / PLANNED
UNKNOWN / UNVERIFIED
For example, /metaverse being live means the route exists.
It does not automatically mean Sellers can create virtual stores.
Likewise, /life-pilot being live does not prove that GPS field reporting, scientific validation, public map publication, or environmental measurements are all implemented.
After introducing the shared runtime context, the same test produced a much better result.
Marketplace, Seller flow, authentication, Metaverse, LIFE Pilot, open-source contribution, and MYZ were described according to their verified status, while advanced dashboards, IoT integrations, IPFS/IPNS workflows, and external settlement remained unverified.
And this time the answer was generated by:
AI: OpenAI · gpt-5.6-sol
The chat itself needed work too
Backend architecture was only half the problem.
The original Zorgax interface had a very small conversation area.
Long AI answers appeared with the scroll position close to the end of the response, forcing the user to scroll upward to begin reading.
We changed the page so that the conversation became the main content area.
New assistant replies are now positioned at the beginning of the new response rather than the end.
The scroll logic is roughly:
function scrollMessageToTop(element) {
const delta =
element.getBoundingClientRect().top -
messages.getBoundingClientRect().top;
messages.scrollTo({
top: messages.scrollTop + delta - 12,
behavior: "smooth"
});
}
We also prevent textarea focus from modifying the viewport:
input.focus({ preventScroll: true });
This made long-form AI responses dramatically easier to read.
Zorgax also needed an exit
There was one more product problem.
Once a user entered Zorgax, the assistant page felt too isolated from the rest of MyZubster.
A product copilot should help users move through the product, not trap them inside the AI interface.
So we added permanent navigation in the Zorgax header:
🏠 Home MyZubster
🛒 Marketplace
The page also contains guided actions for Seller, Marketplace, Metaverse, LIFE Pilot, University/research, Community, and other supported journeys.
This turned Zorgax from a standalone AI page into a real navigation layer for the wider product.
Observability closed the loop
Vercel runtime logging now gives us a compact record of every AI routing decision.
A successful production event can look like:
event: zorgax_message_sent
plan: pro
webResearch: true
sourceCount: 0
aiProvider: openai
aiModel: gpt-5.6-sol
aiFallbackReason: null
During debugging, this was one of the most valuable pieces of the system.
Without it, an answer that looked fine could still have silently come from the fallback model.
With it, we can trace the actual production path.
What the architecture looks like now
The current system can be summarized like this:
User
↓
Zorgax UI
↓
Access policy
↓
Optional research
↓
Task classification
↓
Canonical product context
↓
AI Router
├── OpenAI
│ ├── primary model
│ ├── controlled retry
│ └── secondary model
│
└── Ollama / general AI fallback
↓
Grounded answer
↓
Provider + model metadata
↓
Runtime logs
↓
User
That is much closer to an AI product architecture than a simple chatbot.
What we learned
The LLM call was the easy part.
The actual production system is:
model
- routing
- budget controls
- retry policy
- fallbacks
- grounding
- authorization
- observability
- UI
- navigation
The more capable an AI model becomes, the more important it is for the application around it to define what is real.
The application has to know:
what exists
what is experimental
what is verified
what the AI may do
what actually happened
That is the direction we are taking with Zorgax and MyZubster.
AI can reason.
The product still owns truth, permissions, evidence, and execution.
We did not come to conquer. We came to build together.
Per CoderLegion userei come titolo:
Building Zorgax in Production: Hybrid AI Routing, Grounding, Fallbacks, and UX
Come sottotitolo:
How we evolved the MyZubster assistant from a chat interface into an observable, budget-aware, multi-model product copilot.