Agent Architecture: From Message Primitives to Managed Agent Platforms

    Large language model (LLM) agent engineering has evolved along two main paths: lower-level message primitives and packaged agent runtimes. This article explains how message primitives work, how message APIs have expanded to cover tool calling, reasoning passback, context caching, structured outputs, and hosted tool execution, and where the primitive approach becomes expensive in engineering effort. It then examines agent runtime SDKs and managed agent platforms, including stateless versus stateful access, lifecycle hooks, orchestration, tool governance, observability, and production practices. It closes with selection guidance for primitives, runtimes, and hybrid architectures, plus an engineering checklist for moving agents from demos to production.

    In the early days of LLM applications, developers became familiar with a simple pattern: send a set of messages and receive a set of structured content. It looks simple, but it forms the foundation of agent engineering. As capabilities such as tool calling, reasoning passback, context caching, structured output, and hosted tool execution have been added, message primitives are no longer just a chat interface. They are becoming a core substrate for complex agent workflows.

    At the same time, another evolution path has emerged: packaging the agent runtime behind intelligent coding tools as a development kit, so enterprises can embed a mature runtime into their own products without building an agent loop from scratch. Understanding the differences and connections between these two paths is key to making sound agent architecture decisions.

    Why Message Primitives Remain the Foundation

    The core design of message primitives is very stable: the caller passes a set of messages, and the model returns structured content blocks. These blocks can include text, tool-call requests, and reasoning. After receiving a tool-call request, the developer executes the tool locally or in their own service, then sends the tool result back to the model as a new message. This forms a loop of “model decision—tool execution—result passback.”

    The value of this model is finest-grained control. Developers own the complete agent loop, context management, tool execution logic, permission checks, retry policies, and audit trails. For scenarios with high controllability requirements, such as finance, government, and core enterprise systems, message primitives provide minimal abstraction leakage: the model is responsible only for decisions and generation, while actual tool execution and data access remain under the control of business systems.

    For example, a typical single-turn tool call can be abstracted as the following pseudocode (illustrative only, not a real API):

    1. history = [user_message]
    2. resp = llm.chat(messages=history, tools=tool_specs)
    3. if resp.has_tool_call:
    4. result = execute_tool(resp.tool_call)
    5. history.append(resp.tool_call)
    6. history.append(tool_result(result))
    7. resp = llm.chat(messages=history, tools=tool_specs)
    8. return resp.text

    This logic is simple, but it reveals the basic skeleton of an agent. Around this skeleton, message primitives can support quite complex workflows: multi-step tool calls, conditional branches, result validation, human approval, and subtask decomposition. The problem is that developers must implement all of these capabilities themselves.

    From Primitive to Capability Matrix: The Evolution of Message APIs

    Message primitives themselves continue to evolve, gradually adding the key capabilities agents need. These capabilities can be grouped into several directions:

    1. Tool calling: The model decides when to call a tool and returns a tool-call block; the developer executes the tool and sends the result back. This is a key step in moving an agent from “conversation” to “action.”
    2. Reasoning passback: Reasoning content is returned as reasoning blocks and can be passed across turns. This makes multi-step decisions more explainable and helps maintain reasoning continuity in complex tasks.
    3. Context caching: Supports block-level or automatic caching, reusing repeated context such as system prompts, tool descriptions, and long documents to significantly reduce repeated computation costs. The specific discount depends on platform policy and cache hits; engineering teams should focus on hit rate and invalidation strategy.
    4. Structured output: Uses standards such as JSON Schema to constrain output format, so model output can directly enter downstream parsing, validation, and storage pipelines, reducing the uncertainty of natural-language parsing.
    5. Hosted tool execution: Tools such as web search, web fetching, and code execution are hosted on the platform side, so developers do not need to maintain execution environments. This is suitable for rapid validation and lightweight tasks.

    With these capabilities combined, message primitives are no longer just a chat interface; they are a programmable agent decision primitive. They break model capabilities into composable content blocks, allowing developers to orchestrate them precisely within their own business systems.

    But their boundaries are also clear: multi-step tool calls, sub-agent orchestration, session state persistence, context compression, long-task recovery, tool permissions, and auditing all need to be implemented by developers. In other words, message primitives provide the parts, not the whole vehicle.

    Control and Complexity: The Limits of the Primitive Path

    Choosing message primitives means choosing maximum control, and also maximum engineering complexity. Specific challenges include:

    • Agent loop implementation: Handling the loop in which the model returns a tool call, the tool is executed, the result is sent back, and the model is called again, while managing timeouts, retries, exceptions, and maximum step limits.
    • Session state management: Multi-turn conversations, long tasks, and interruption recovery require persistent session state, and must ensure consistency among message order, tool results, and reasoning blocks.
    • Context compression: Long tasks generate large amounts of history, so teams must design compression strategies such as summarization, truncation, and retrieval augmentation to avoid context window overflow.
    • Sub-agent orchestration: Complex tasks need to be split across multiple sub-agents, involving task assignment, result aggregation, conflict handling, and progress tracking.
    • Security and auditing: Tool execution must include permission checks, parameter validation, interception of sensitive operations, and end-to-end auditing.

    Therefore, message primitives are suitable for scenarios that require high control and teams with strong agent engineering capabilities. If a team wants to productize quickly, it needs a higher-level runtime abstraction.

    Product Value of Agent Runtime SDKs

    Another evolution path in the industry is to open up the agent runtime that powers intelligent coding tools and package it as a development kit. Its product positioning is not “another chat interface,” but “embedding an agent runtime proven through large-scale practice into your own product.”

    Such runtimes typically provide two access modes:

    Access mode Suitable scenarios Characteristics
    One-shot stateless call Single tasks, scripted processing, lightweight automation Simple integration, suitable for quickly starting an agent
    Stateful session client Multi-turn conversations, long tasks, permission control and hooks Supports session state, lifecycle hooks, and permission governance

    The stateless mode is suitable for short-chain scenarios of “input task—execute—return result,” where developers can start an agent with a small amount of code. The stateful mode is suitable for production scenarios that require multi-turn interaction, tool approval, audit interception, and context management. It encapsulates the agent loop, session state, and tool scheduling, so developers only need to focus on business tools and policy configuration.

    Such runtimes also typically include a set of out-of-the-box tool categories, such as file read, file write, content edit, command execution, path matching, text search, web search, web fetch, and skill extension. More importantly, they provide more than ten lifecycle hooks covering key points such as before tool call, after tool call, sub-agent startup, and before context compression. Developers can implement auditing, interception, parameter modification, result redaction, and behavior enhancement without rewriting the agent loop.

    For example, a stateful session can be abstracted as the following pseudocode:

    1. with agent.session(permissions=policy) as s:
    2. s.on("before_tool_call", audit_and_validate)
    3. s.on("after_tool_call", redact_sensitive_data)
    4. s.send("Complete a multi-step task")
    5. result = s.wait()

    The point of hooks is to decouple governance logic from the agent loop. Security teams can maintain permission checks before tool calls in a unified way, audit teams can subscribe to events after tool calls, and platform teams can inject summarization policies before context compression. This preserves runtime efficiency while avoiding coupling between business code and governance logic.

    Key Capabilities of a Managed Agent Platform

    When agents move from single calls to production systems, platform capabilities become important. A mature managed agent platform typically needs to cover the following capabilities:

    1. Hosted execution loop: The platform handles model calls, tool scheduling, result passback, and exception retries, while developers focus on tools and business logic.
    2. Session and state persistence: Supports long-task recovery, multi-turn conversations, interruption resume, and event replay.
    3. Sub-agent orchestration: Supports task decomposition, parallel execution, result aggregation, and failure isolation.
    4. Context compression and memory management: Provides strategies such as summarization, truncation, and retrieval augmentation to control context cost and quality.
    5. Tool governance and permission control: Tool registration, parameter validation, approval of sensitive operations, tenant isolation, and audit logs.
    6. Observability: Records model calls, tool execution, reasoning blocks, error rates, and cost metrics, and supports tracing and alerting.
    7. Structured output and validation: Constrains output through schemas and completes validation, retries, and fallback on the platform side.

    On cloud platforms such as Baidu AI Cloud, enterprises can combine an agent runtime with general cloud services such as object storage, message queues, logging, and monitoring and alerting to form a closed loop of “tool execution—event flow—log auditing—metric alerting.” Such integration should be based on general capability integration rather than dependence on custom, service-specific features.

    Selection Guidance: Primitives, Runtime, and Hybrid Architecture

    Developers do not have to choose one path exclusively. A more reasonable approach is to layer by scenario:

    • Strong control, strong compliance, tools residing in owned systems: Prefer message primitives and build the agent loop and governance chain in-house.
    • Fast productization, multi-turn sessions, and tool governance required: Prefer an agent runtime SDK and use hooks for auditing and interception.
    • Complex enterprise systems: Adopt a hybrid architecture. Keep core tool execution and permission checks in owned services, and hand the agent loop and session state to the runtime. Use hooks to write audit events to logs and monitoring, and use structured output to ensure downstream systems can parse results.

    The key to a hybrid architecture is clear boundaries: the model handles decisions, the runtime handles orchestration, and business systems handle execution and data permissions. The three are decoupled through structured events and tool results, avoiding the embedding of security policies in prompts.

    Production Engineering Checklist

    1. Tool idempotency and timeouts: All tool calls should support idempotency keys, timeouts, and retry limits to avoid duplicate side effects.
    2. Result validation: Apply schema validation to tool results and model structured output; on failure, enter retry or human review.
    3. Layered context: Manage system prompts, tool descriptions, long-term memory, and short-term conversation in layers, combined with caching and compression strategies.
    4. Least privilege: Authorize tools by tenant, role, and task; require approval for sensitive operations.
    5. End-to-end observability: Record model calls, tool calls, reasoning blocks, latency, cost, and error codes, and establish trace IDs.
    6. Hook-based governance: Put cross-cutting logic such as auditing, redaction, interception, and rate limiting into lifecycle hooks to avoid intruding into business code.
    7. Regression evaluation: Establish metrics such as task success rate, tool-call accuracy, and structured-output compliance rate, and evaluate continuously.

    Conclusion

    From message primitives to managed agent platforms, the underlying change is the evolution of division of labor in agent engineering. Message primitives provide the finest-grained control and are suitable for embedding agent capabilities into owned systems. Agent runtime SDKs provide packaged loops, sessions, tools, and hooks, and are suitable for rapid productization and unified governance. A truly mature architecture does not blindly pursue the highest-level abstraction or stubbornly stick to the lowest-level primitive. Instead, it makes layered design decisions based on control, engineering efficiency, security compliance, and operability. Understanding this evolution path is what allows agents to move from demos to production.