Production Agent Engineering: Adversarial Verification, 3-Layer Permissions & Compaction
Eliminating circular provenance with three hostile review lenses, gating tools with circuit-breaker permissions, and microcompacting long-running agent context.
- 01Asking an LLM reviewer "is this finding accurate?" invites confirmation bias; commission three distinct hostile lenses—Arithmetic, Interpretive, and Provenance—defaulting to refuted under uncertainty.
- 02Validation gates keyed only to written tokens reward omission: every compliance or citation gate requires an explicit absence mode.
- 03Production harnesses combine O(1) static ontology rules, a circuit-broken sidecar classifier, and human write-gates—while microcompacting stale tool outputs in-place.
1. Adversarial Verification & Defeating Circular Provenance
In financial, regulatory, and operational audits, the subtler cousin of hallucination is circular provenance: an earlier export or fixture generated by your own pipeline round-trips through a collaborator’s folder under a new filename, creating the illusion of independent corroboration.
High-stakes verification splits review across three orthogonal hostile lenses rather than N redundant copies of the same prompt:
- Arithmetic Lens: Recomputes every aggregate and implied ratio (
output ÷ activity) from raw records rather than summary tables, exposing undeclared input shifts. - Interpretive Lens: Grants every number as true, then attacks whether the numbers actually support the causal or business claim.
- Provenance Lens: Audits the evidential chain—checking timestamps, SHA-256 byte lineage, build-gate constraints that forced cardinality agreement, and whether a cited URL is an in-force normative act rather than a stale draft.
A checker that only flags malformed citations lets a document with zero citations pass cleanly. Pair every token-keyed validator with an absence mode that distinguishes "verified clean" from "omitted / could not parse".
2. The Three-Layer Tool Permission Model With Circuit Breakers
Prompting humans on every read kills adoption; blanket auto-approval invites disaster. Production agent harnesses layer tool authorization into three tiers:
evaluateToolCall(tool, input, caller):
// Layer 1: Deterministic O(1) Ontology & Static Rules (~80% of calls)
if matchesAllowRule(tool, caller.role): return ALLOW
if matchesDenyRule(tool, input): return DENY
// Layer 2: Sidecar Policy Classifier (bounded auto-mode for novel reads)
if autoMode and denials.consecutive < 3 and denials.total < 20:
verdict = sidecarClassifier(tool, input, ontologyContext)
if verdict == "ALLOW": return ALLOW
trackDenial()
// Layer 3: Human Write-Gate (all ERP mutations & post-circuit-breaker fallback)
return ENQUEUE_HUMAN_APPROVAL3. Three-Tier Context Compaction & Vectorless Hierarchical RAG
Long-running enterprise agents choke on accumulated tool payloads (SQL result sets, schema dumps) needed for a single turn. Three-tier compaction keeps reasoning sharp: Tier 1 Microcompact clears stale tool results in-place with zero LLM latency (180K -> 40K tokens); Tier 2 Full Compact forks a structured summarizer preserving user intent, errors, and active schemas; Tier 3 persists durable lessons to session memory.
For structured ERP manuals and SOPs, pairing ontology queries with a hierarchical tree index (Root -> Module -> Leaf Page summaries, zero embeddings required) lets the agent navigate exact procedural sections without mid-sentence vector chunking.
Glossary Concepts Referenced in This Guide
Agent = Model + Harness) responsible for tool-calling loops, context compaction, retries, sandboxing, and execution traces.UPDATE/INSERT statements on ERP/CRM databases, requiring typed action proposals validated against preconditions and approved by a named human role.Free to reference in engineering docs, ADRs, articles, and course syllabi with attribution.
[Production Agent Engineering: Adversarial Verification, 3-Layer Permissions & Compaction — Ontoloji.org](https://ontoloji.org/en/guides/ai-agent-verification-three-layer-permissions-and-context-compaction)