Architecture kata · K—09

Governed GenAI Data Agents with LLM Evaluation

Architecture kata · design study on a fictional brief

Sector
Enterprise analytics and AI governance
Technologies
LangGraph, LiteLLM, vLLM, OpenMetadata, Open Policy Agent, PostgreSQL, pgvector, Apache Iceberg, Langfuse, Flowable, Apache APISIX, Keycloak
Flow: a gateway passes user identity to agents, which use three governed tool surfaces, an evidence store and a CI gate.
The design at a glance: the one-page, 30-minute live drawing.

In short

Three enterprise agents limited to certified metrics, contracted data and permitted documents, with traced answers and gated releases.

Problem

A retail and consumer-goods company with 8,000 office employees ran two pilot chatbots over its warehouse. One produced a wrong revenue figure in a board deck. The other leaked a supplier contract summary to the wrong team. The CIO froze all GenAI releases until agents can ship safely. That means governed data only and traceable answers. Each release needs a measurable evaluation. An auditor must be able to see how an answer was produced six months later. Three agents are in scope: an analytics assistant, a data-onboarding agent and an operations agent that drafts actions such as reorders.

Approach

Both incidents have the same root cause: the pilots wrote raw SQL against ungoverned tables and read documents with their own service account. The design narrows the surface the agent can touch rather than choosing a better model. Agents call three schema-validated tool surfaces, and identity travels with the user. No answer is released without a trace, and a release is gated by a policy file in CI.

Architecture

  • Identity: APISIX and Keycloak issue a signed user claim that is forwarded to every tool call.
  • Agents: a LangGraph runtime with an allow-list of tools per agent. A LiteLLM gateway fronts two commercial providers and an on-premises vLLM model.
  • Tool surfaces: a metric API with certified definitions and per-user policy. Contracted data products in OpenMetadata. A document store filtered by access rights before ranking.
  • Decision point: an Open Policy Agent sidecar decides agent, user and resource on every tool.
  • Evidence: the answer, evidence set, tool-output hashes and prompt and model version go to PostgreSQL with an outbox row in one transaction. Iceberg keeps the archive for two years.
  • Approvals: Flowable records who approved each action, with rollback.
Architecture: one gateway passes user identity to three agents, which use three governed tool surfaces and a model gateway.
Solution overview: the gateway, the agent runtime, the three tool surfaces, the model gateway, the evidence store and the evaluation gate in one view.Open full size (opens in new tab)

Why these components

Need Choice Why
API gateway and identity Apache APISIX and Keycloak OpenID Connect login, then a short-lived signed user claim that travels with every agent and tool call. Per-user rate limits and an audit log. APISIX, because Kong OSS moved features out of its open edition.
Agent runtime LangGraph on Kubernetes Agent steps form an explicit graph. Tool calls are schema-checked, each agent’s tool allow-list comes from Git, and every step emits a span. Managed frameworks like Bedrock Agents hide the tool surface and traces.
Model gateway LiteLLM Two providers and vLLM behind one OpenAI-compatible interface. Provider keys live only here, with quotas per team, routing per agent and cost labels. Restricted documents route only to vLLM. The MIT core is enough.
Open-weight model serving vLLM with a 32B model under Apache 2.0 Two replicas with tensor parallelism of two cover the estimated peak of about 1,760 tokens a second. The on-premises path for sensitive document classes and for cost. The Llama community licence is not OSI-approved.
Metric API Certified definitions built with Dataform, plus a thin service The agent picks a metric ID and filters; the layer compiles SQL and applies the user’s row and column policy. Free text-to-SQL caused the wrong revenue figure, so it is closed by design.
Catalogue and data products OpenMetadata Agents see only products with a contract for schema, owner, SLA and policy; lineage and owner go into the evidence. DataHub is also Apache 2.0, but OpenMetadata’s contract and policy model is more direct.
Document store for retrieval PostgreSQL with pgvector, and OpenSearch Access list and class label per document come from the document system. The permission filter runs before vector ranking, so the model never sees an unauthorised chunk. OpenSearch over Elasticsearch after its licence change.
Policy decision Open Policy Agent as a sidecar Decides agent, user and resource in every tool service. Allow-lists and class policies are versioned bundles in Git, and every denial is counted. Policy is enforced on the data, not in the prompt.
Evidence store and archive Own PostgreSQL evidence store, outbox, Debezium, Apache Iceberg for two years Evidence row and outbox row in one transaction; the answer is released only after commit. Langfuse v3 cannot take an outbox row because of its ClickHouse store and async ingest, so evidence lives separately.
LLM observability Langfuse v3 with ClickHouse, Valkey and blob storage Spans, latency, tokens and evaluation scores, ingested asynchronously for observability only. Valkey because of the Redis 7.4 licence. Arize Phoenix was ruled out over its Elastic 2.0 licence.
Evaluation platform Own CI runners, Langfuse evals, a policy file in Git Golden set, tool-order score, injection and exfiltration suites, and a provider tolerance test per agent. Thresholds sit in a versioned policy file. Commercial eval services such as LangSmith were ruled out.
Approval flow Flowable with BPMN Every action with a side effect becomes a human task, recording who approved what and when, with rollback. Approval never runs automatically. Camunda 8 was ruled out after its move to a source-available licence.
Deterministic production Cloud Composer and Dataform The onboarding agent drafts code and contracts at design time; a person reviews and merges. Composer runs the merged code without an LLM. Chosen because it is already a platform component.
Governance register and cost PostgreSQL with a small UI, LiteLLM labels, Grafana Agent, risk class, owner, evaluation status, allowed models, incidents and EU AI Act duties. The register is a release precondition. Daily cost per agent and team comes from LiteLLM labels.

Decisions and trade-offs

  • No raw SQL tool at all. The wrong board-deck figure came from a model inventing a query on an ungoverned table. Now the agent picks a metric and filters; the layer compiles the SQL. An unknown metric fails validation, and the agent logs a request instead of guessing. A better model does not fix a wrong figure; a narrower surface does. The cost is coverage limited to certified metrics.
  • No agent service account. The contract summary leaked because the agent had more rights than the person asking. Now a signed user claim is checked by the runtime, the tools and the policy decision. Answers are never cached across users. The cost: the agent can never help with data the user could not query alone.
  • No answer without evidence. The evidence row and an outbox row are written in one PostgreSQL transaction, and the answer is released only after commit. Replay rebuilds the answer from stored tool outputs and never calls the model again. The guarantee is “same evidence, same assembly”, not “the model would say the same today”. The cost is running my own evidence store next to Langfuse.
  • Design time versus run time. An LLM may draft pipeline code and contracts, and a person merges them. Production pipelines run without an LLM, so the same input gives the same output. The operations agent only drafts; Flowable records the human approval. The cost is a review step on every change.
  • Evaluation gate. Each agent faces a 300-question golden set, tool-order checks, 200 injection cases, 100 exfiltration cases and a provider tolerance test. Thresholds sit in a versioned file, and a regression blocks the pipeline with no “just this once”. The cost is about 20 minutes per run, by the kata’s estimate, plus keeping the sets current.
  • One model gateway, portability as a goal. Secrets, quotas and cost labels live in LiteLLM, so a provider switch is a routing change. If the switch drops golden accuracy by more than 2 points or tool-order match by more than 5%, the agent stays on its current model. Restricted documents can only go to the on-premises model. The cost is a gateway every call must pass.
Flow: every answer is stored with its evidence before release, and a CI gate blocks releases that fail evaluation.
One question through the governed hop chain: authorisation, plan, governed tools, evidence, answer and trace. The answer is released only after the trace write is acknowledged.Open full size (opens in new tab)

What I would revisit

  • Metric coverage. I assumed 400 certified metrics. How many questions fall outside them, and who handles the requests, within what time?
  • Document labels. Are access lists and classes in the document system reliable? Unlabelled documents stay out by default.
  • Provider agreements. Which data classes may go to an external provider, and is pseudonymisation enough for the impact assessment?
  • Tolerance thresholds. I assumed 2 points and 5%. Do business owners accept them, or does each agent need its own?

Outcome notes (design assumptions, not measurements)

This is a design exercise, not a running agent platform. The output is a four-page diagram set, a one-page whiteboard version and a 16-page Turkish PDF. It includes an AI governance register and an EU AI Act mapping. Tolerance thresholds (2 points of golden accuracy, 5% trajectory) are assumptions awaiting business owners.

Sources

  • Architecture PDF (Turkish, 16 pages).
  • draw.io diagrams (English labels): four-page set and a one-page 30-minute version.

Real projects on this topic

  1. P—03

    Active

    Featured

    Contract-Driven Data Platform with GenAI-Assisted Onboarding

    New data sources join through validated YAML contracts; LLM agents work at design time only, so production runs stay deterministic.

    • Data contracts
    • GenAI
    • LLM evaluation data
    • AI-ready data
    • Data governance
    • Data pipelines

    Role

    Architecture and hands-on development · Data Solution Architect

  2. P—04

    Completed

    Fashion Retail Competitive Intelligence & GenAI Trend Platform

    Competitor price, stock and colour data for 20+ brands in ~95 markets, normalized with LLMs: pricing and assortment decisions from 1 week to 1 day.

    • GenAI
    • AI-ready data
    • Decision support
    • Data platform
    • Cloud

    Role

    Design and build · Data Solution Architect

AI & GenAI: projects, katas and publications

About the katas

Write to me about a similar design problem.