Business Logic Collapse: What to Build for the AI Agent Era
This article explains why business logic tends to collapse into prompts and model discretion as teams adopt AI agents, and what engineering assets should replace it. It starts from a technical premise: LLM services are probabilistic and not strictly reproducible, because floating-point non-associativity, non-deterministic parallel reduction order, batching and memory layout differences, multiple server replicas and hardware variance, and sampling randomness all affect outputs even at temperature 0. From there it traces three collapse paths—semantic migration into prompts, orchestration bloat, and missing observability—and the cost that surfaces in compliance audits, cost accounting, and cross-version consistency. The proposed answer is four core assets: a domain semantic layer, a deterministic execution kernel, an observability and evaluation system, and governance for permissions, cost, and data boundaries. A layered target architecture, a four-step adoption path, and common anti-patterns are included.
1. Introduction: From Skepticism to Understanding to Repositioning
For a long time, I treated the hype around large models as a short-lived phenomenon, expecting everything to return to normal once the buzz faded. After writing code against these systems, reading their low-level implementations, and comparing new designs with traditional architectures item by item, my view reversed: what has actually changed is not “whether a given tool is useful,” but the distribution of value in the application layer.
Talking to practitioners from different fields, I kept seeing two extreme narratives. One claims most jobs are about to be replaced. The other claims models are just a few matrix multiplications and not worth overrating. Both skip the most important middle layer: the engineering system. What gets replaced is not engineering, but the parts of engineering that only move parameters around, map fields, and stitch flows together.
There is also a frequently misread phenomenon: many organizations say they value AI, but their actual investment stops at wrapping existing APIs. This raises a question that must be answered: when model capability can be purchased and tool calls can be assembled, where exactly do our own technical assets live? This article offers a framework that can be put into practice.
2. Clarifying the Technical Premise: Why Model Output Is Non-Deterministic
Before discussing how to build the application layer, we need to explain a phenomenon that is often mystified: even with sampling temperature set to 0, the same input can still produce different outputs. The reason is not that “the model has moods,” but the computation and serving path itself.
- Floating-point arithmetic is not associative.
(a+b)+canda+(b+c)can differ under finite precision. - Parallel reduction order is not fixed. Matrix multiplication and attention computation are split across different compute units, and the reduction order changes with scheduling.
- Batching and memory layout differences. The same request may land in a different batch or a different sequence-length bucket, taking different operator branches.
- Multiple server replicas and hardware differences. A request may be routed to a different instance or a different accelerator, so the numerical path is not fully identical.
- Sampling and random number state. Temperature only affects the sharpness of the distribution; it does not remove randomness or the non-determinism introduced by concurrency.
The conclusion is direct: an LLM service is a probabilistic, not strictly reproducible external dependency. Any design that pins business correctness on “the model gives the same answer every time” is invalid from the start. This is the starting point for every architectural decision that follows.
3. How Business Logic “Collapses”
Collapse means that domain rules, constraint validation, state transitions, and audit evidence that used to settle in the application layer are gradually pushed out into prompts and model discretion, leaving only glue code in the application layer. There are three typical paths.
The first is semantic migration. Teams write “what counts as a compliant order” and “which states allow a refund” into prompts instead of into testable rules. Change the prompt and the business definition drifts with it, with no way to run regression checks.
The second is orchestration bloat. To compensate for insufficient model capability, teams keep stacking retries, second-pass validation, and multi-turn clarification. Control flow complexity rises fast, but without state machines, timeouts, and idempotency design, failures are hard to localize.
The third is missing observability. Only the final answer is logged—not retrieval hits, tool inputs and outputs, token consumption, or failure reasons. Production issues cannot be reproduced, and optimization relies on guesswork.
The cost of collapse does not appear immediately. It erupts in three places at once: compliance audits, cost settlement, and cross-version consistency.
4. What to Build: Four Core Assets
4.1 Domain Semantic Layer
Extract business concepts, terminology, states, and constraints out of prompts into machine-readable, versionable definitions. The model handles only language understanding and candidate generation; the decision authority stays in deterministic code.
Domain semantic layer = glossary + entity relations + state machine + rule set (unit-testable)
Key point: express rules as pure functions or declarative configuration with stable inputs and outputs. Every rule change goes through code review and regression cases, not verbal synchronization.
4.2 Deterministic Execution Kernel
An agent’s “hands” must be stricter than its “brain.” Tool calls should be treated as controlled side effects and funneled into a single execution kernel.
def run_tool(name: str, args: dict, ctx: Context) -> ToolResult:schema = registry[name].schemaargs = validate(schema, args) # structural validationif not policy.allow(ctx.subject, name, args): # permissions and quotareturn ToolResult.deny("policy")key = idem_key(ctx.request_id, name, args) # idempotencyif hit := cache.get(key):return hitres = registry[name].handler(args, ctx) # timeout/retry handled herecache.set(key, res, ttl=registry[name].ttl)audit.write(ctx, name, args, res) # audit trailreturn res
Key design: validate before executing, allow failures to be replayed, make side effects rollback-able or compensable, and log all inputs and outputs. Arguments produced by the model are always untrusted input.
4.3 Observability and Evaluation System
Treat AI features as software that needs continuous regression, not a one-off demo.
- Tracing: retrieval, tool calls, and model calls within a single request are linked under one trace ID.
- Layered metrics: task success rate, tool call success rate, average number of turns, token and latency cost, and human takeover rate.
- Evaluation sets: accumulate cases from real production failures, run offline regression on fixed inputs, and focus on “did it exceed its authority” and “did it skip validation” rather than writing style alone.
- Canary release and rollback: prompts, model versions, and rule sets can each be rolled back independently, avoiding coupled releases.
4.4 Governance for Permissions, Cost, and Data Boundaries
The more autonomous an agent is, the more it needs boundaries. At minimum, cover: a least-privilege tool allowlist, quota limits per subject and per tenant, masking and minimal passing of sensitive fields, data residency and retention policies, and mandatory human confirmation for high-risk actions. On the cost side, establish an allocation scheme by business dimension so it is obvious which path is burning money.
5. Target Architecture: Layers and Responsibilities
Access layer Session/task entry point, identity and tenant recognitionOrchestration Task decomposition, planning, retry policy (no business decisions)Semantic layer Glossary, state machine, rule set (deterministic, testable)Execution layer Tool registry + validation + idempotency + auditModel layer Probabilistic capabilities: generation, extraction, ranking (replaceable)Foundation layer Object storage / message queue / container platform / logging / monitoring and alerting
The decision rule is one sentence: any logic that must be identical every time goes down into the semantic and execution layers; any capability where “good enough most of the time” is acceptable goes to the model layer, backed by evaluation and human fallback.
6. Adoption Path and Common Anti-Patterns
A four-step path is suggested. First, inventory existing glue code and mark which parts are actually implicit business rules. Second, extract those rules into unit-testable rule sets and state machines. Third, funnel tool calls into a single entry point and fill in validation, idempotency, and audit. Fourth, build evaluation sets and a cost dashboard, then move into continuous regression.
Anti-patterns to watch for: writing compliance decisions into prompts; using unlimited retries to mask design flaws; monitoring only API availability instead of task success rate; coupling model version releases with business rules; and pursuing “full automation” before there is a permission model.
7. Conclusion
Models will keep getting stronger and interfaces will keep changing. What will not depreciate is verifiable domain knowledge, controllable execution boundaries, and a measurable quality system. When the application layer is no longer just glue but the carrier of semantics, constraints, and evidence, we move from “calling AI” to “harnessing AI.”
