Architectural Choices for Embedding AI Agents into Business Systems
This article examines a key architectural decision when moving AI agents beyond standalone use cases: where the agent should run relative to core business systems. It contrasts external orchestration, where an agent calls business systems over HTTP, with code-native integration, where agent capabilities live inside the business process. Using an e-commerce order-change scenario, it breaks down the authentication, latency, consistency, and evolution costs of external orchestration, outlines when external orchestration still makes sense, and offers practical guidance on pushing domain tools down, keeping execution inside transaction boundaries, managing state, unifying observability, and evolving incrementally.
1. The Starting Point: An Agent Is Not an Island
The two most common requests when deploying AI agents inside an enterprise are “enterprise knowledge base Q&A” and “customer service bots.” These scenarios share one characteristic: they are loosely coupled with core business systems. The input is a piece of natural language, and the output is a block of text or a structured suggestion, with almost no need to write back to the business database. For this kind of requirement, low-code visual orchestration platforms are nearly unbeatable—drag in nodes, configure prompts, attach a knowledge base, and publish a callable service in a matter of hours, with an extremely high return on investment.
But real technical debt tends to surface in the next stage: when the business side asks that “the agent must be able to read my orders, change my configuration, and trigger my approval workflows,” the question shifts from “can it be done” to “where should it be done.” This article does not compare specific products. Instead, it abstracts the applicable boundaries of two technical paths and provides a more rigorous architectural argument.
2. The Essential Difference Between the Two Paths: Orchestration Location and Coupling Direction
The first path can be called “external orchestration”: the agent runs outside the business system and calls back into it through HTTP interfaces. The second path can be called “code-native integration”: agent capabilities are embedded into the business process as a library or framework, sharing the same dependency direction as the domain model.
The key difference is not the language but the coupling direction. External orchestration forces the business system to expose a set of interfaces “customized for the agent.” The granularity, authentication scheme, and idempotency semantics of these interfaces are determined by the agent’s needs rather than by domain boundaries. Over time, the business system’s external contract becomes bound to the agent’s iteration cadence, forming a bidirectional dependency.
3. Calculating the Cost with an E-Commerce Scenario
Suppose a user says in a conversation: “Was that red cup I bought last week shipped? If not, change it to blue.”
Under the external orchestration path, at least three capabilities are required: query the user’s order history, query the logistics status of a specific order, and modify the product color of an order item. Inside the business system, these three things are often a coherent piece of logic that can be completed within a single transaction. But once split into three cross-network calls, they introduce four kinds of cost.
- Authentication cost: the agent side must carry and pass through the user identity, and the business side must distinguish “user self-service operations” from “internal service calls,” forcing the permission model to expand.
- Latency cost: a single conversation may trigger multiple rounds of tool calls, each adding network round trips and serialization overhead, amplifying the end-to-end response time.
- Consistency cost: a time window exists between the query and the modification. Between “querying as not shipped” and “submitting the color change,” the warehouse may have already dispatched the order, causing the modification to fail or producing dirty data.
- Evolution cost: when a business rule changes (for example, changing the color requires validating inventory and price difference), the Java-side code and the external orchestration configuration must be modified in sync, binding their release cadences together.
Under the code-native integration path, these three steps can converge into a single domain service method, completing validation and writes within one transaction boundary. Authentication reuses the system’s existing security context, network round trips disappear, and consistency is guaranteed by the database transaction.
// Illustration: converge "query + validate + change" into one domain operationpublic ChangeResult changeColorIfShippable(Long userId, Long orderId, String color) {Order order = orderRepository.findForUpdate(orderId, userId); // row lock + ownership checkif (order.shipped()) {return ChangeResult.rejected("Already shipped, cannot change color");}order.changeItemColor(color); // domain method encapsulates business rulesreturn ChangeResult.ok(order.snapshot());}
4. External Orchestration Still Has Value, but the Boundary Must Be Drawn Clearly
Dismissing external orchestration is another form of laziness. It remains reasonable in three types of scenarios: the agent is maintained by an independent team, capabilities must be aggregated across multiple heterogeneous systems, and the conversation flow needs frequent adjustment without triggering a core system release. In these cases, the right approach is not to eliminate it but to constrain it:
- Make interfaces use-case-oriented rather than model-oriented, avoiding exposing a fine-grained interface for every tool;
- Merge “query + action” into a use-case interface with an idempotency key to reduce round trips;
- Use a unified gateway to handle authentication and rate limiting, so the business system remains unaware of the agent’s existence;
- Make eventually consistent actions asynchronous through events or a message queue, rather than enforcing strong-consistency waiting inside the conversation flow.
5. Actionable Architecture Recommendations
- Push domain tools down. Implement the capabilities that agents can call as domain services inside the business process, exposing only a thin adapter layer externally.
- Cohesive orchestration, external execution. Flow orchestration can stay on the agent side, but the execution of each node must land within a business transaction boundary.
- Controllable state. Introduce explicit task states and human confirmation nodes for long-running flows; write operations follow “confirm first, execute next, rollback possible.”
- Unified observability. Put the agent call chain and the business chain into the same logging, monitoring, and alerting system, linking them with a unified trace identifier to avoid “two systems blaming each other” during fault localization.
- Incremental evolution. First use low-code orchestration to validate the scenario’s value; when write operations and transactional consistency become the bottleneck, migrate the tool layer back to the code side while keeping the external contract unchanged.
6. Conclusion
There is only one core criterion for the selection: whether the agent needs to participate in the transactions and rules of core business. For read-only, loosely coupled cases, leave it to visual orchestration; for cases involving writes, strong consistency, and frequent rule changes, the capabilities should return to the code and domain model. If an enterprise already uses general-purpose infrastructure such as cloud platform containers, message queues, logging, and monitoring, these can serve as the hosting and observability foundation. But the question of where the agent “lives” should still be decided by coupling direction rather than technical preference.
