How to Read These Architectures
Each reference architecture below includes a diagram (zoom with +/−), a component table naming every layer and its responsibility, a numbered step-by-step procedure for implementation and operations, plus technical and enterprise deployment context.
Use the sidebar to jump between architectures. Procedures are written for AI engineers, architects, and auditors who need repeatable, production-grade workflows.
Prompt Engineering Workflow
Architecture Overview
The enterprise prompt lifecycle treats prompts as versioned, testable software artifacts—not ad-hoc strings. Every change flows through design, evaluation, staging, and governed production release.
Core Components
| Component | Role | Typical Technology |
|---|---|---|
| Product / SME | Defines task, success criteria, and failure modes | Confluence, Jira, domain experts |
| Prompt Repository | Stores system/user templates with semantic versioning | Git, prompt registry DB |
| Eval Harness | Runs golden datasets, LLM-as-judge, human rubrics | Custom CI, LangSmith, Phoenix |
| Policy Gate | Blocks release if safety/quality thresholds fail | OPA, custom validators |
| Inference Runtime | Serves approved prompt versions to apps | API gateway + model endpoint |
Step-by-Step Procedure
End-to-end flow from initiation to production operation. Follow these steps when designing, implementing, or auditing this architecture.
- 1
Step 1 — Requirements & Task Specification
Document the business objective, input/output schema (JSON Schema), allowed tools, latency budget, and compliance constraints (PII, retention). Map to measurable KPIs: accuracy, refusal rate, citation fidelity.
- 2
Step 2 — Prompt Design
Author system message (role, constraints), user template (variables), few-shot exemplars if needed, and output format instructions. Separate trusted system channel from untrusted user content to mitigate injection.
- 3
Step 3 — Offline Evaluation
Execute eval suite against frozen model version: unit tests for format, semantic similarity to references, task-specific scorers (exact match, F1, LLM judge). Record baseline metrics in eval dashboard.
- 4
Step 4 — Red-Team & Security Review
Run adversarial prompts (jailbreaks, instruction override via documents). Validate guardrails: PII redaction, topic refusal, tool allowlists. Security signs off before promotion.
- 5
Step 5 — Staging Deployment
Deploy prompt hash vN+1 to staging environment with shadow traffic or internal dogfood. Compare side-by-side with production prompt on held-out queries.
- 6
Step 6 — Canary & Production Release
Route 5% → 25% → 100% traffic via feature flag. Monitor token cost, latency p99, error rate, human escalation rate. Rollback automatically if SLO breach.
- 7
Step 7 — Continuous Monitoring
Weekly regression on golden set; alert on metric drift. Quarterly review with SMEs when model provider upgrades base weights.
Technical Deep Dive
Prompts are keyed by {tenant_id, use_case, version}. Runtime resolves active version from config service. Each inference logs: prompt_template_id, variable hash, model_id, temperature, full trace_id. Diff tools compare token-level changes between versions.
Practical Use Case
A regulated bank versions 200+ prompts for KYC, fraud, and support. PRs require two approvers + passing eval CI. Production incidents trigger instant rollback to previous prompt hash without redeploying application code.
LLM Architecture (Production Stack)
Architecture Overview
A production LLM stack decouples user-facing applications from model inference through gateways, routers, and scalable GPU serving—enabling cost control, failover, and observability.
Core Components
| Component | Role | Typical Technology |
|---|---|---|
| Client Application | Web, mobile, or backend service initiating completion requests | React, Java Spring, Python FastAPI |
| API Gateway | AuthN/Z, rate limiting, request validation | Kong, Azure APIM, AWS API Gateway |
| Model Router | Selects model by capability, cost, latency, data residency | Custom router, Martian, OpenRouter pattern |
| Inference Server | Batched token generation with continuous batching | vLLM, TensorRT-LLM, TGI |
| Model Artifact Store | Weights, tokenizer, config | S3, HuggingFace Hub, internal registry |
Step-by-Step Procedure
End-to-end flow from initiation to production operation. Follow these steps when designing, implementing, or auditing this architecture.
- 1
Step 1 — Request Ingestion
Client sends HTTPS POST with API key/OAuth JWT. Gateway validates schema: messages[], max_tokens, response_format, tools[]. Assign correlation ID.
- 2
Step 2 — Authentication & Quota
Map API key to tenant quota (RPM, TPM). Reject or throttle if exceeded. Attach billing metadata.
- 3
Step 3 — Routing Decision
Router scores candidate models: task type (chat vs embed), sensitivity (on-prem vs cloud), budget. May cascade: try small model first, escalate if confidence low.
- 4
Step 4 — Prompt Assembly
Merge system prompt, conversation history (trimmed to context window), RAG context if applicable. Apply chat template (ChatML, Llama format).
- 5
Step 5 — Tokenization & Prefill
Tokenizer converts text to input_ids. GPU executes prefill pass—processes entire prompt in parallel—building KV cache.
- 6
Step 6 — Autoregressive Decode
Sample next token (greedy, top-p, or temperature). Append to sequence; update KV cache per layer. Repeat until EOS or max_tokens.
- 7
Step 7 — Post-Processing
Parse structured output if JSON mode. Run safety classifiers on completion. Stream tokens via SSE if streaming enabled.
- 8
Step 8 — Response & Telemetry
Return completion + usage {prompt_tokens, completion_tokens}. Emit metrics to Prometheus/Datadog; store trace for debugging.
Technical Deep Dive
Continuous batching groups requests dynamically on GPU. KV cache stores key/value tensors per layer to avoid recomputing prefix. Quantization (INT8/FP8) reduces memory; speculative decoding drafts tokens with smaller model then verifies with large model.
Practical Use Case
E-commerce platform routes product-description generation to 8B on-prem model (low cost) and legal review summaries to GPT-4-class API (high quality)—single unified API for internal teams.
Transformer Architecture
Architecture Overview
The Transformer is an encoder-decoder (or decoder-only) neural architecture where self-attention replaces recurrence, enabling parallel training and long-range dependency modeling at scale.
Core Components
| Component | Role | Typical Technology |
|---|---|---|
| Token Embedding | Maps token IDs to d_model-dimensional vectors | Learned embedding matrix E ∈ ℝ^{V×d} |
| Positional Encoding | Injects sequence order (sinusoidal or RoPE) | Added to embeddings or applied in attention |
| Multi-Head Self-Attention | Each token attends to all positions | Q,K,V projections; softmax(QKᵀ/√d_k)V |
| Feed-Forward Network | Per-token MLP, typically 4× expansion | GELU/ReLU; residual + LayerNorm |
| Output Head | Projects hidden state to vocabulary logits | Linear layer; softmax for next-token prob |
Step-by-Step Procedure
End-to-end flow from initiation to production operation. Follow these steps when designing, implementing, or auditing this architecture.
- 1
Step 1 — Tokenization
Input text → subword tokens via BPE/SentencePiece. Special tokens: BOS, EOS, PAD. Max length truncation or sliding window for long docs.
- 2
Step 2 — Embedding Lookup
token_id → vector x_i ∈ ℝ^d. Scale by √d_model per original paper.
- 3
Step 3 — Positional Information
Add positional encodings or apply RoPE to Q,K in each layer so model distinguishes order.
- 4
Step 4 — Encoder Layer (×N)
For each layer: (a) Multi-head self-attention with residual + LayerNorm, (b) FFN with residual + LayerNorm. Output: contextualized representations H.
- 5
Step 5 — Decoder Layer (×N) [seq2seq]
Masked self-attention (causal) + cross-attention to encoder output + FFN. Mask prevents attending to future tokens during training.
- 6
Step 6 — Decoder-Only [GPT-style]
Stack of causal self-attention layers only. Training: predict token t+1 given tokens 1..t (teacher forcing).
- 7
Step 7 — Output Projection
Final hidden state h_t linearly mapped to logits over vocabulary. Softmax → probability distribution.
- 8
Step 8 — Training Objective
Minimize cross-entropy loss over next-token predictions. Backprop through all layers; AdamW optimizer; learning rate warmup + cosine decay.
- 9
Step 9 — Inference
Autoregressive generation: sample/argmax next token, append, repeat. KV cache optimizes by caching past K,V tensors.
Technical Deep Dive
Complexity O(n²·d) per layer limits context length; FlashAttention reduces memory IO. Layer normalization stabilizes deep stacks. Pre-norm vs post-norm affects training stability at 100B+ scale.
Practical Use Case
Decoder-only Transformers power ChatGPT-class assistants; encoder-only (BERT) for embeddings/classification; encoder-decoder (T5) for translation and summarization pipelines.
RAG Pipeline Architecture
Architecture Overview
Retrieval-Augmented Generation (RAG) grounds LLM outputs in externally retrieved documents, reducing hallucination and enabling answers over private, fresh enterprise data.
Core Components
| Component | Role | Typical Technology |
|---|---|---|
| Ingestion Pipeline | Loads, chunks, embeds documents | Airflow, Unstructured.io, custom ETL |
| Embedding Model | Maps text chunks to dense vectors | text-embedding-3, e5, BGE |
| Vector Database | ANN index for similarity search | Qdrant, Pinecone, Milvus, FAISS |
| Retriever | Hybrid dense + sparse search, re-ranker | BM25 + cross-encoder rerank |
| Generator (LLM) | Conditions answer on retrieved context | GPT-4, Llama, Mistral |
Step-by-Step Procedure
End-to-end flow from initiation to production operation. Follow these steps when designing, implementing, or auditing this architecture.
- 1
Step 1 — Document Ingestion
Connectors pull PDFs, wikis, tickets from SharePoint, Confluence, S3. Extract text (OCR if needed). Attach metadata: source, ACL, timestamp, version.
- 2
Step 2 — Chunking
Split into overlapping segments (512–1024 tokens, 10–20% overlap). Preserve headings hierarchy; optional parent-child chunk linking.
- 3
Step 3 — Embedding & Indexing
Batch-embed chunks; upsert into vector DB with metadata filters. Build sparse index (Elasticsearch) in parallel for hybrid retrieval.
- 4
Step 4 — Query Processing
User question → optional query expansion/reformulation → embed query vector q.
- 5
Step 5 — Retrieval
ANN search top-k (e.g., k=20); apply metadata filters (tenant, classification). Hybrid: fuse dense scores with BM25 via RRF. Re-rank top-20 → top-5 with cross-encoder.
- 6
Step 6 — Context Assembly
Pack chunks into context window budget. Order by relevance; deduplicate near-duplicates; inject citation markers [1][2].
- 7
Step 7 — Grounded Generation
Prompt LLM: system (cite sources only), context blocks, user question. Constrain: 'If not in context, say unknown.'
- 8
Step 8 — Post-Validation
Check citations exist in retrieved set; NLI model verifies answer entailed by context; block if hallucination score high.
- 9
Step 9 — Feedback Loop
Log query, chunks, answer, user thumbs. Hard negatives retrain reranker; stale docs trigger re-ingestion.
Technical Deep Dive
Recall@k and MRR measure retrieval quality independently of generation. Chunk size trades context granularity vs embedding noise. ACL-aware retrieval filters vectors by user permissions before LLM sees content.
Practical Use Case
HR assistant indexes 15k policy pages; employees ask natural-language questions; answers include paragraph citations; legal team audits retrieval logs quarterly.
Agent Pipeline Architecture
Architecture Overview
An AI agent closes the loop between language reasoning and environment action: it observes state, plans, executes tools, reflects on outcomes, and iterates until the goal is satisfied or limits are hit.
Core Components
| Component | Role | Typical Technology |
|---|---|---|
| Perception Module | Parses user input, tool results, environment state | LLM + structured parsers |
| Planner | Decomposes goals into subtasks | CoT, ReAct, dedicated planner LLM |
| Tool Registry | Catalog of callable functions with schemas | OpenAPI, MCP tools, code sandbox |
| Executor | Invokes tools with validated arguments | Function-calling API, sandboxed Python |
| Memory Store | Short/long-term state | Context window, vector DB, Redis |
| Critic / Reflector | Evaluates progress, triggers replanning | Self-reflection prompts, rule engine |
Step-by-Step Procedure
End-to-end flow from initiation to production operation. Follow these steps when designing, implementing, or auditing this architecture.
- 1
Step 1 — Goal Initialization
Receive user objective + constraints (budget, time, allowed tools). Load session memory and user profile from long-term store.
- 2
Step 2 — State Assessment
LLM summarizes current knowledge gaps. Decide: answer directly, retrieve knowledge, or invoke tool.
- 3
Step 3 — Planning
Emit plan: ordered subtasks with success criteria. For ReAct: interleave Thought → Action → Observation traces.
- 4
Step 4 — Tool Selection
Model outputs structured tool call: {name, arguments} per JSON schema. Validator checks types, ranges, auth scope.
- 5
Step 5 — Tool Execution
Run API call / SQL query / code in sandbox. Capture result or error. Timeout and retry with backoff on transient failures.
- 6
Step 6 — Observation Integration
Append tool output to conversation state. Truncate/summarize if exceeds token budget.
- 7
Step 7 — Reflection
Critique: Did subtask succeed? Update plan. Detect loops (same action repeated) → break or escalate to human.
- 8
Step 8 — Termination
Stop when goal met, max iterations (e.g., 10), cost cap, or user approval. Synthesize final response with audit trail of actions.
Technical Deep Dive
State machine formalization: S × A → S. Each action a ∈ A has preconditions and effects logged immutably. Idempotent tools preferred; compensating transactions for partial failures.
Practical Use Case
Sales ops agent: reads CRM (tool), drafts email (LLM), schedules meeting (calendar API), logs activity—human approves sends above $50k deals.
Multi-Agent Ecosystem Architecture
Architecture Overview
Multi-agent systems distribute complex work across specialized agents coordinated by a supervisor, message bus, or shared state graph—mirroring organizational division of labor.
Core Components
| Component | Role | Typical Technology |
|---|---|---|
| Supervisor / Orchestrator | Routes tasks, resolves conflicts, aggregates outputs | LangGraph supervisor node, CrewAI manager |
| Worker Agents | Domain specialists with narrow tool sets | Researcher, coder, analyst personas |
| Message Bus | Async communication between agents | Redis pub/sub, Kafka, in-memory queue |
| Shared State | Blackboard or graph state object | LangGraph State, shared dict |
| Human Node | Approval gates for high-risk actions | Interrupt/resume in LangGraph |
Step-by-Step Procedure
End-to-end flow from initiation to production operation. Follow these steps when designing, implementing, or auditing this architecture.
- 1
Step 1 — Task Decomposition
Supervisor LLM analyzes request; assigns subtasks to agents by capability matrix (who can use which tools).
- 2
Step 2 — Parallel Dispatch
Independent subtasks run concurrently (e.g., research + data pull). Dependent tasks queued.
- 3
Step 3 — Intra-Agent Loop
Each worker runs full perceive-plan-act cycle on its subtask. Reports status: running, blocked, done.
- 4
Step 4 — Inter-Agent Messaging
Agents pass artifacts: research summary → writer; code patch → reviewer. Schema: {from, to, payload, message_type}.
- 5
Step 5 — Conflict Resolution
Supervisor detects contradictory conclusions; triggers debate round or defers to human.
- 6
Step 6 — Aggregation
Merge partial outputs; deduplicate; ensure consistent tone/format. Final QA agent checks completeness.
- 7
Step 7 — Delivery & Trace
Return unified deliverable. Distributed trace links each agent's tool calls for debugging.
Technical Deep Dive
Graph-based orchestration (LangGraph) models agents as nodes, edges as conditional transitions. Checkpointing persists state for crash recovery and human-in-the-loop resume.
Practical Use Case
Consulting firm deploys researcher + analyst + slide-writer agents for market reports; partner reviews final deck before client delivery—40% faster first draft.
Model Context Protocol (MCP) Architecture
Architecture Overview
MCP standardizes how AI applications discover and invoke tools and resources from external servers—replacing bespoke integrations with a uniform client-host-server protocol.
Core Components
| Component | Role | Typical Technology |
|---|---|---|
| MCP Host | IDE or agent runtime embedding the client | Cursor, Claude Desktop, custom agent |
| MCP Client | Maintains 1:1 connection to each server | Protocol handler in host app |
| MCP Server | Exposes tools, resources, prompts | postgres-mcp, filesystem-mcp, custom |
| Transport | stdio or HTTP+SSE message channel | JSON-RPC messages |
| Backend Systems | Databases, APIs, file systems | Enterprise data plane |
Step-by-Step Procedure
End-to-end flow from initiation to production operation. Follow these steps when designing, implementing, or auditing this architecture.
- 1
Step 1 — Server Registration
Admin configures MCP server executable + env vars in host config. Host spawns server process or connects to remote endpoint.
- 2
Step 2 — Capability Discovery
Client sends initialize → server returns ServerInfo, capability flags (tools, resources, prompts). Client caches tool schemas.
- 3
Step 3 — Resource Listing
Client requests resources/list → server returns URIs (e.g., file://, db://schema). Model can read resource contents on demand.
- 4
Step 4 — Tool Invocation Request
LLM selects tool; host sends tools/call with arguments. Server validates against JSON Schema.
- 5
Step 5 — Server Execution
Server runs query/API/action in isolated context. Returns structured content or error {code, message}.
- 6
Step 6 — Result to Model
Observation injected into conversation. Model continues reasoning or chains additional tool calls.
- 7
Step 7 — Lifecycle Management
Health checks, reconnection on failure, permission scopes per server (read-only vs write).
Technical Deep Dive
Messages follow JSON-RPC 2.0. Security boundary: each server runs with least-privilege credentials. Host must not expose server env secrets to model context.
Practical Use Case
Engineering team connects Jira + GitHub + Postgres MCP servers to coding agent—developer asks 'fix bug #4421' and agent reads ticket, queries DB schema, opens PR without custom plugins per system.
Enterprise AI Platform Architecture
Architecture Overview
An enterprise AI platform unifies experience channels, agent orchestration, model serving, data planes, and governance into a single governed stack deployed on private cloud or hybrid infrastructure.
Core Components
| Component | Role | Typical Technology |
|---|---|---|
| Experience Layer | Copilots, APIs, batch jobs | Web UI, Teams bot, REST |
| Orchestration Layer | Agents, RAG, workflows | LangGraph, custom DAG engine |
| Model Gateway | Routing, caching, billing | Portkey, custom gateway |
| Data Plane | Vector, feature, lakehouse | Snowflake, Databricks, Qdrant |
| Governance Plane | Policy, audit, model registry | MLflow, internal GRC tools |
| Infra | K8s, GPU pools, secrets | EKS, Azure AKS, Vault |
Step-by-Step Procedure
End-to-end flow from initiation to production operation. Follow these steps when designing, implementing, or auditing this architecture.
- 1
Step 1 — Identity & Access
User/service authenticates via SSO (OIDC). RBAC maps roles to models, datasets, tools. Attribute-based access on document collections.
- 2
Step 2 — Request Routing
Traffic enters WAF → API gateway → platform router. Classify workload: chat, embed, batch, agent.
- 3
Step 3 — Orchestration
Agent framework loads workflow definition. Retrieves context from data plane; calls model gateway for LLM steps.
- 4
Step 4 — Model Inference
Gateway selects endpoint (on-prem Llama vs Azure OpenAI). Applies rate limits, prompt templates from registry.
- 5
Step 5 — Data Access
Vector search and SQL tools enforce row-level security. Query logs attributed to user and use case.
- 6
Step 6 — Governance Hooks
Every response logged: inputs hash, output, model version, retrieved doc IDs. High-risk flows queue for human approval.
- 7
Step 7 — Observability & Cost
Metrics per tenant: tokens, GPU hours, $/request. Chargeback to business units. Dashboards for SRE.
- 8
Step 8 — Lifecycle Management
Model/prompt promotion through dev → staging → prod. Disaster recovery: multi-region failover for gateway.
Technical Deep Dive
Cell-based architecture isolates tenants. Service mesh (Istio) handles mTLS between microservices. Secrets never in prompts—resolved server-side at tool execution.
Practical Use Case
Global manufacturer runs unified platform for 12 countries—local data residency via regional model endpoints while sharing governance policies centrally.
AI Governance Platform Architecture
Architecture Overview
AI governance platforms operationalize responsible AI: inventory models, assess risk, enforce policies, maintain audit trails, and coordinate human oversight across all production AI workloads.
Core Components
| Component | Role | Typical Technology |
|---|---|---|
| Model Registry | Catalog of models, versions, owners | MLflow, internal CMDB |
| Risk Tiering | Classify use cases (low → critical) | EU AI Act aligned taxonomy |
| Policy Engine | Rules: allowed models, data classes, regions | OPA, custom DSL |
| Audit Store | Immutable logs of AI decisions | WORM storage, SIEM integration |
| Review Workflow | Human approval for high-risk outputs | ServiceNow, Jira integration |
Step-by-Step Procedure
End-to-end flow from initiation to production operation. Follow these steps when designing, implementing, or auditing this architecture.
- 1
Step 1 — Use Case Registration
Team submits AI initiative: purpose, data types, affected users, automation level. Governance assigns risk tier and required controls.
- 2
Step 2 — Impact Assessment
Complete DPIA/FRIA where required. Document limitations, bias testing plan, fallback when AI unavailable.
- 3
Step 3 — Model & Data Approval
Only registered model IDs allowed in production namespace. Training data provenance documented; prohibited sources blocked.
- 4
Step 4 — Policy Deployment
OPA policies enforce: no PII to public APIs, EU data stays in EU region, financial advice requires disclaimer + human review.
- 5
Step 5 — Runtime Enforcement
Gateway intercepts requests; checks policy; blocks or routes to approved path. Tool calls validated against allowlist.
- 6
Step 6 — Continuous Monitoring
Drift detection on input distribution and output quality. Incident playbooks for model failure, prompt injection spike.
- 7
Step 7 — Periodic Audit
Quarterly sample of traces reviewed by compliance. Evidence package for regulators: policies, logs, test results.
Technical Deep Dive
Lineage graph links datasets → training jobs → model versions → deployment endpoints → application prompts. Enables root-cause analysis and targeted recall.
Practical Use Case
Insurance group maps 80 AI use cases to risk tiers; high-risk claims adjudication requires dual human sign-off with full prompt/response archived 7 years.
AgentOps Framework Architecture
Architecture Overview
AgentOps extends MLOps/LLMOps to autonomous agents: distributed tracing of multi-step reasoning, evaluation of trajectories (not just final text), cost tracking, and regression gates before release.
Core Components
| Component | Role | Typical Technology |
|---|---|---|
| Tracing SDK | Instruments LLM calls, tools, retrieval | OpenTelemetry, LangSmith, Arize |
| Eval Platform | Trajectory + outcome scorers | Custom harness, DeepEval |
| Metrics Store | Time-series KPIs | Prometheus, Grafana |
| Alerting | SLO breaches, cost anomalies | PagerDuty, Slack |
| CI Regression | Block deploy on eval drop | GitHub Actions, Jenkins |
Step-by-Step Procedure
End-to-end flow from initiation to production operation. Follow these steps when designing, implementing, or auditing this architecture.
- 1
Step 1 — Instrumentation
Wrap every LLM invoke, tool call, retrieval with span: parent_trace_id, span_id, latency, tokens, status. Propagate context across async agents.
- 2
Step 2 — Trace Collection
Export spans to collector. Build waterfall view: which tool caused failure, token hotspots.
- 3
Step 3 — Define Eval Suites
Task-specific datasets with expected outcomes: final answer match, required tool sequence, max steps, max cost.
- 4
Step 4 — Offline Regression
On each PR: run agent against eval suite in sandbox. Compare to baseline: success rate, avg steps, P95 latency, $/run.
- 5
Step 5 — Canary in Production
Shadow 10% traffic; compare live metrics to baseline. Auto-rollback agent graph version on regression.
- 6
Step 6 — Human Feedback Loop
Thumbs-down triggers trace review; add failure to golden set; fix prompt/tool; re-run CI.
- 7
Step 7 — Cost & Capacity Planning
Dashboard: $/successful task by use case. Right-size models; cache frequent retrievals.
Technical Deep Dive
Trajectory eval: score sequence [(thought, action, observation)...] not only final string. Tool-error taxonomy: timeout vs auth vs validation vs business logic.
Practical Use Case
Support automation agent ships weekly; CI runs 500 scripted customer scenarios; deploy blocked if resolution rate drops >2% vs last release.