Agent Composition Architecture: A Practical Guide to Design and Implementation

    This article explains why a single AI agent is often not enough in production and how to design a composite agent system with clear capability boundaries, a layered communication protocol, context governance, failure recovery, and observability. It covers the division of responsibilities between conversational and execution agents, a five-layer protocol abstraction, semantic registries, idempotency and compensation, security guardrails, and a phased adoption path, along with open questions that still lack consensus.

    1. The Starting Problem: Why a Single Agent Is Not Enough

    In real engineering work, many teams run into a similar situation. Marketing material emphasizes the capabilities of a certain class of agent product, but once it is integrated into a business workflow, it turns out to be incomplete. Conversational agents are good at understanding intent, organizing language, and maintaining multi-turn context, yet they lack a stable execution sandbox, file system access, and deterministic task orchestration. Task-execution agents are good at calling tools, reading and writing files, and running scripts, yet they are weaker at natural language understanding, clarifying questions, and presenting results.

    The natural next idea is to simply combine the two kinds of capability. That is possible, but “simply stitching them together” usually introduces new complexity. This article does not focus on any specific product. Instead, it frames the problem as a general architecture question: how to build an agent collaboration system that is layered and decoupled, uses clear protocols, is observable, and can recover from failures.

    2. Defining Capability Boundaries: Decide Who Is Responsible for What First

    The first principle of a composite architecture is to make responsibility boundaries explicit so that two agents do not overstep each other.

    • Conversational layer agent: responsible for intent recognition, slot extraction, clarifying questions, result aggregation, and user-visible output. It does not touch the production environment and does not directly perform high-risk actions.
    • Execution layer agent: responsible for running code in a controlled sandbox, manipulating files, calling external interfaces, and producing structured results. It does not hold free-form conversations with end users.
    • Orchestration layer: responsible for decomposing a user request into steps and deciding call order, concurrency, timeouts, and retry policies.

    A common anti-pattern is to let the conversational layer hold production credentials and execute commands directly. This amplifies prompt injection risk straight down to the infrastructure layer. A sound approach is to let the execution layer accept only signed task descriptions that come from the orchestration layer.

    3. Communication Protocol Design: A General Abstraction Across Five Layers

    To let the two agent layers collaborate reliably, communication can be broken down into five layers. This is also a common abstraction in protocol design across the industry:

    1. Transport layer: choose long-lived or short-lived connections and handle heartbeats, reconnection, and backpressure.
    2. Encoding layer: define the message serialization format and control the context waste caused by repeatedly transmitting redundant fields.
    3. Semantic layer: agree on field meanings, enum values, and time formats so that semantic interpretation does not have to be stuffed into the prompt on every call.
    4. Identity and authorization layer: make clear who the caller is, what the permission scope is, and whether credentials have been revoked.
    5. Orchestration and transaction layer: define the task lifecycle, idempotency keys, and compensation actions.

    Optimization at the encoding layer is often underestimated. Paginated list responses repeat the same field names in every record. The model has already learned the structure from the first screen, but it keeps paying for the repetition afterwards. Practical general optimizations include: sending a field dictionary only once, replacing per-row repeated key names with columnar or compact encoding, and caching static structures locally while transmitting only a version number in messages.

    A sample message structure can be expressed like this:

    1. {
    2. "msg_id": "uuid",
    3. "schema_ref": "catalog.v3",
    4. "task": { "op": "list", "cursor": "c_01" },
    5. "auth": { "subject": "agent-exec-7", "scope": ["read:catalog"] }
    6. }

    4. Context Governance: Turn Repeated Explanation into a One-Time Asset

    The traditional approach writes field meanings and status code mappings into the system prompt and consumes tokens on them during every call. A more engineering-oriented approach is to build a semantic registry: version data structures, enums, units, and timezone conventions, have the agent fetch a reference once at the start of a session, and pass only the version number afterwards. This reduces context overhead and also makes semantic changes auditable and rollback-friendly.

    At the same time, set a context budget: allocate separate quotas for conversation history, tool results, and semantic references. When the limit is exceeded, trim low-value earlier turns first rather than truncating tool output and leaving the execution layer with incomplete data.

    5. Failure Recovery and Idempotency: The Real Difficulty of Composite Architectures

    When a single agent fails, a retry is enough. When a composite architecture fails, it may leave half-finished state behind. Three things must be in place:

    • Idempotency keys: every write operation carries a business idempotency identifier so that repeated delivery produces no side effects.
    • Compensation transactions: define inverse operations for multi-step tasks and roll back in reverse order on failure.
    • Checkpoint resume: externalize task state to persistent storage so a process can continue from a checkpoint after a restart.

    It is advisable to define an explicit state machine for tasks: pending → running → pending confirmation → completed / compensated. Any unauthorized transition should be treated as an anomaly and trigger an alert.

    6. Observability and Security Guardrails

    Before going live, prepare at least four capabilities: structured logs (with task identifiers and call chains), metrics monitoring (latency, failure rate, retry count), distributed tracing, and alerting policies. On the security side, you need sandbox isolation, least-privilege credentials, output content moderation, a second confirmation for high-risk actions, and treating all external input as untrusted data.

    7. A Suggested Adoption Path

    In the first phase, implement collaboration only for read-only scenarios to validate the protocol and the benefits of context governance. In the second phase, introduce controlled write operations and compensation mechanisms. In the third phase, add parallel orchestration across multiple agents and cost optimization. If a team lacks the capability to build everything itself, it can rely on general infrastructure from cloud providers, such as container platforms, message queues, object storage, logging services, and monitoring and alerting, to host the runtime without binding to proprietary interfaces.

    8. Open Questions

    To be honest, there is still no widely accepted answer for cross-organization recognition of semantic registries, the propagation delay of agent identity credential revocation, or deadlock avoidance during multi-agent negotiation. Explicitly recording these uncertainties is more valuable than pretending they have been solved.