1
Client / UI
Why: the user sees latency and trust here, and it's where the system learns.
- Stream tokens; show sources next to the answer.
- Confirm before any action; thumbs up/down and "report" buttons.
answer streams in with a link to the expense policy, and a "Create ticket?" button
leaving out the UI. Without feedback capture here, the improvement loop never gets data.
2
API layer
auth · identity · quotas
Why: the model can't know who is asking, so this layer must, and it passes that identity down.
- SSO auth, per-user and per-team quotas, request validation, session state.
- Attach the user's identity and entitlements to the request context.
user = priya@corp, groups = [eng, india-office]
"Identity is set once at the edge and carried through the whole request, into retrieval and every tool call."
3
Input guardrails
Why: the input is untrusted.
- Redact PII, detect prompt injection and abuse, check the topic is in scope.
- Use cheap classifiers and rules here. A big model adds cost and latency.
treating guardrails as one input filter. Output and tool calls need checks too (steps 6 and 8).
4
Orchestrator
the app's own logic
Why: the model is stateless, so something has to decide what to fetch, build the prompt and parse the result.
- Classify intent, then run a fixed workflow where you can and an agent loop only where you must.
- Assemble the prompt from a versioned template; parse structured output.
intent = policy question + action → retrieve policy → answer → propose ticket
"I default to a deterministic workflow. An agent loop costs several times more and is harder to test, so it has to earn its place."
5
Context sources
retrieval · data · tools · memory
Why: the model doesn't know your data. This is where most of the answer's quality comes from.
- RAG index (hybrid search + rerank), SQL and APIs, tools that act, user memory.
- Filter by the user's permissions at query time.
search only docs Priya's groups can read; ticket tool runs with her token, not a service account
a shared index with no ACL filter. That's how one employee reads another team's documents.
6
LLM gateway
one door to every model
Why: calls are metered and can fail, so one place handles that for every feature.
- Routing (small vs large model), retries, fallback provider, timeouts.
- Prompt and response caching, API keys, rate limits, token budgets, cost per team and feature, logging.
putting business logic in the gateway. It knows models, not HR policy.
7
Models
API or self-hosted
Why: this is the only box that generates text, and it's swappable behind the gateway.
- Buy (API) for quality and speed to ship; self-host for data residency, very high volume or fine-tuned small models.
"Because everything goes through the gateway, changing models is a config change plus an eval run, not a rewrite."
8
Output guardrails
Why: the output is untrusted too.
- Validate the schema, check claims against the sources, run policy and PII-leak checks.
- Gate actions: the model proposes and code checks before anything runs.
ticket payload validated; user clicks "Create ticket" before it's filed
∞
Cross-cutting
around every hop
Why: the model is probabilistic, so you only know it works by measuring.
- Observability: a trace per request with spans for every hop, plus tokens, cost, latency and errors.
- Evals: an offline golden set gates every prompt or model change; online metrics in production.
- Feedback store: thumbs-down and escalations become new eval cases.
- Config registry: versioned prompts, model choices and feature flags, so changes can be rolled back.
logging full prompts with PII in them. Redact before storing traces, and set a retention limit.