A real-world case study of a production-ready agentic RAG system in a regulated domain: Bayer’s Preclinical Information Center (PRINCE), built with Thoughtworks. It’s the enterprise-search counterpart to the vault’s other production exemplar, Agentic Data Analytics (Anthropic’s self-service analytics) — both arrive at the same conclusion from different problems: reliability is an engineering discipline, not a model upgrade. Source: A Case Study in building production-ready agentic AI systems (PRINCE at Bayer) (Sarang Kulkarni, martinfowler.com, 2026).
The thesis
Production-ready agentic AI is not only about better models or better prompts. Reliability comes from engineering both the context the model sees (Context Engineering) and the harness within which the model acts (Harness Engineering).
The article’s lens is explicitly those two vault concepts: context engineering shaped what each model received and how context moved between steps; harness engineering shaped the scaffolding — orchestration, tool boundaries, state, retries, fallbacks, validation, reflection, observability, human review. PRINCE is the worked example both pages were describing in the abstract.
The problem and the Search → Ask → Do arc
Decades of preclinical knowledge sat in siloed systems and, crucially, in unstructured PDF study reports whose structured metadata was often incomplete or wrong after years of migrations. The “gold standard” lived in the approved PDFs. PRINCE evolved in three phases that map cleanly onto a capability ladder:
- Search — a unified gateway over structured metadata (filter-based).
- Ask — RAG question-answering over the unstructured reports (natural-language).
- Do — an active research assistant: multi-agent workflows that orchestrate tasks and draft regulatory documents.
This is the same maturation AI Agents - Real-World Adoption and Use Cases describes — retrieval → answering → acting — grounded in one organization’s actual roadmap since early 2024.
The standout idea: three reflection loops
PRINCE’s most transferable contribution is splitting “reflection” into three distinct loops, each catching a different failure. Most agent writeups collapse these into one vague “self-critique” step; separating them is what makes the system debuggable.
| Loop | Agent | Question it answers | What it catches |
|---|---|---|---|
| Process reflection | Think & Plan | Is the workflow on the right path? | bad trajectory, wrong tool choice, poor sequencing |
| Data reflection | Reflection Agent | Is the gathered evidence sufficient? | thin evidence, missing context, coverage gaps |
| Draft reflection | Writer (review loop) | Is the output complete? | missing sections, inconsistent tables, synthesis gaps |
- Think & Plan (inspired by Anthropic’s “Think tool”) is a dedicated reasoning space before acting. Its biggest payoff: as tools multiplied across domains (toxicology vs pharmacology, summaries vs detailed data), the LLM struggled to pick the right one. An explicit “reason about which tool fits” step produced a dramatic jump in tool-selection accuracy. It also sequences multi-step plans (query metadata → get study IDs → retrieve report details → synthesize).
- Reflection Agent compares retrieved context against the original query; if insufficient, it generates specific follow-up questions handed back to Think & Plan to drive more retrieval. Process can be perfect while data is thin, or vice versa — hence two separate checks.
- Writer review loop checks completeness and presentation of the drafted answer.
Context discipline: route context, don’t accumulate it
The design principle running through the architecture: larger context windows did not remove the need to be selective. Early iterations dumped everything into the prompt and the system got harder to steer and evaluate. PRINCE instead routes the right context to the right capability at the right stage:
- planning context → Think & Plan
- retrieval context → Researcher Agent
- evidence context (question + collected evidence, not full history) → Reflection Agent
- synthesis context (curated chunks + citation constraints, not raw retrieval) → Writer
Text-to-SQL injects only the relevant schema components, never the full schema. This is Context Engineering’s “smallest set of high-signal tokens” made concrete, and the reason each agent can be evaluated, debugged, and improved in isolation. It’s also why the system is a multi-agent design at all: the split exists for context hygiene and testability, not for novelty.
Contrast with the 200k-token rule
RAG and Retrieval says don’t build RAG under ~500 pages — just stuff the context. PRINCE is the legitimate other side: a corpus of thousands of multi-decade reports that genuinely can’t fit, so retrieval mechanics matter. It’s the case the rule carves out.
The retrieval mechanics worth stealing
Query-time RAG pipeline (hybrid, over OpenSearch):
- Keyword extraction (LLM) — pull search terms from the natural-language query.
- Metadata filter generation (LLM, few-shot) — e.g.
eq(study_id, T123456-2), pre-filtering millions of vectors down to tens–hundreds. - Query expansion (small/fast model) — n=5 paraphrases to absorb phrasing/terminology variation.
- Weighted hybrid search — semantic (kNN) + keyword, 0.7 / 0.3 (tuned), run in parallel across the 5 queries, aggregated to k≈20.
- Rerank — cross-encoder (
bge-reranker-large) selects the top k=7. - Cited generation — a reasoning model answers from the 7 chunks with citations back to source chunks/study IDs.
Text-to-SQL for structured data adds several hard-won details:
- Dynamic schema selection — inject only the schema the query needs.
- Dynamic few-shot from a vector “semantic layer” — retrieve hand-picked (question → Athena SQL) examples by similarity; grow the collection as new challenges appear.
- SELECT-only validation — DELETE/INSERT/UPDATE blocked; essential columns always selected.
- They removed an LLM SQL-review step — it false-flagged valid queries, costing efficiency without an accuracy gain. (A useful counter-data point to the “always add a reviewer” instinct — compare the adversarial-review cost trade in Agentic Data Analytics.)
- Error-feedback retry loop — failed query + error + context fed back to the model, up to 3 attempts; results capped at 50 rows.
Harness engineering in practice (reliability + trust)
This is the part that makes it production rather than a demo, and the most directly relevant section for reliability and regulated use:
- State persistence — full LangGraph workflow state persisted per node (Agent State in Postgres via a checkpointer; logs/steps/citations in DynamoDB), so the system resumes from the failed node instead of restarting. User-initiated retries reuse persisted state and skip completed steps.
- Layered retries + LLM fallbacks — retries at both LLM-call and logical-node level; on repeated failure, automatic fallback to an alternative model/provider via a unified OpenAI-compatible endpoint. (Provider-swappability as a reliability feature, echoing Provider Abstraction in Agent Harnesses.)
- Trust through citations — every claim grounded, hover any sentence to see the source document, page number, and exact quote. Intermediate steps and shortlisted chunks are shown. Verifiability is the design constraint, not a feature.
- Two-tier evaluation — dataset evals (curated SME reference answers, RAGAS metrics: faithfulness, answer/context relevancy, accuracy, semantic similarity) on significant changes; daily live-traffic evals on real queries to catch production hallucinations. Langfuse is the observability spine. This is Eval-Driven Agent Development running continuously, not once.
- NER data-quality loop — a utility extracts annotations from PDFs with a confidence score per field: high-confidence auto-updates the warehouse, low-confidence is quarantined for human review. Human-in-the-loop gated by machine confidence.
- Accuracy first, cost later — the team deliberately optimized for accuracy even at higher cost, and only optimized cost after hitting the accuracy bar.
The closing nuance matches Harness Engineering’s “harnesses don’t shrink, they move”: as models improve, parts of today’s harness may thin or go native — but in regulated systems where trust, traceability, and reviewability matter, explicit control over context, state, recovery, reflection, and verification stays essential.
Relation to other vault concepts
- Agentic Data Analytics — the sibling production case study. Both conclude reliability = governance/structure + verification, not a smarter model. Analytics has “a single correct answer, no deterministic way to prove it”; PRINCE has the same trust problem in a regulated domain and answers it with citations + two-tier evals + human gating. Read them as a pair.
- Context Engineering — PRINCE is the explicit worked example: context discipline, route-don’t-accumulate, schema-slicing for Text-to-SQL.
- Harness Engineering — the LangGraph control layer (pause points, retries, state, fallbacks) is harness engineering by name; the “harness thins but doesn’t vanish” point is here too.
- RAG and Retrieval — the legitimate large-corpus case for RAG, with a concrete hybrid + rerank pipeline the concept page describes abstractly.
- Multi-Agent Systems / Five Workflow Patterns for AI Agents — Researcher/Reflection/Writer is an orchestrator-worker split justified by context hygiene and testability; the Researcher is evolving into a coordinator routing to domain sub-agents.
- Eval-Driven Agent Development / Making Your Agent Reliable — dataset + daily live-traffic evals, stage-level metrics (testing-pyramid analogy), fix-one-thing-at-a-time discipline.
- Verification Bottleneck — citations down to page + exact quote are exactly the “make a human’s verification cheap” move; trust is the rate limiter in a regulated domain.
- Agent Legibility — showing intermediate steps and source chunks is legibility applied to the end user, not just the developer.
Sources
- A Case Study in building production-ready agentic AI systems (PRINCE at Bayer) — Sarang Kulkarni (Thoughtworks), A Case Study in building production-ready agentic AI systems, martinfowler.com, 2026-06-16; the primary source. Companion paper in Frontiers in Artificial Intelligence (2025).