AI Agent Architecture: From Message Primitives to Managed Platforms
LLM APIs are evolving through layers of abstraction, not simply replacing older interfaces. This article examines how message primitives, agent runtime SDKs, and managed platforms divide responsibility for tool execution, state, context compaction, memory, and orchestration. It also presents a simplified agent loop and practical criteria for balancing control, delivery speed, governance, and migration costs.
AI Agent Architecture: From Message Primitives to Managed Platforms
1. The Evolution Is About Layering, Not Replacement
It is easy to interpret the evolution of large language model APIs as a replacement cycle: a new interface arrives, and the old one becomes obsolete. In engineering practice, however, a more robust approach is often to add runtime capabilities on top of stable primitives rather than rebuild everything.
Common approaches fall into two broad categories. One introduces new runtime interfaces that aim to subsume older interfaces through higher-level abstractions. The other preserves message primitives as the foundation, gradually adding optional layers for agent loops, tool execution, context management, compaction, memory, and managed orchestration.
The main advantage of the layered approach is choice. Developers do not have to choose between fully custom orchestration and a fully managed service. Instead, they can select an integration depth that matches the control they need.
For teams that require precise control over tool calls, state storage, and auditing, message primitives remain the foundation. For teams delivering multi-turn agent applications quickly, runtime SDKs and managed platforms can substantially reduce duplicated engineering work. Understanding these layers is essential to API selection, architecture, and long-term maintenance.
2. The Stable Core: Why Message Primitives Still Matter
A message-based primitive typically follows a straightforward model: the caller sends a sequence of messages, and the model returns structured content blocks. Depending on the API, those blocks can carry text, tool calls, tool results, or reasoning-related content.
This model is simple but extensible. It turns model output from a single string into a composable stream of structured events.
As these interfaces have matured, the message layer has become capable of supporting sophisticated agent workflows. Common capabilities include:
- Tool calling: The model decides when to request a tool and returns a tool-call block. The developer executes the tool and sends back a tool-result block, creating a multi-step loop.
- Passing reasoning blocks: Where supported, reasoning-related content is returned in separate blocks that can be carried across turns to support debugging, auditing, and subsequent decisions.
- Prompt caching: Repeated context can be cached at the block level or automatically, reducing repeated transmission and computation costs. This is especially useful for long system prompts, knowledge-base excerpts, and fixed tool descriptions.
- Structured output: Constraints such as JSON Schema make model output easier for software to consume.
- Server-managed tools: Capabilities such as web search, page retrieval, and code execution can run on the platform, reducing the complexity of client-side tooling.
The message layer offers the finest control. Developers own the agent loop, context management, tool execution logic, retry policies, and permission boundaries.
That control also creates work. Multi-step tool calls, subagents, session state, context compaction, and memory access must all be implemented. A prototype may need only a few dozen lines of loop logic. In production, that loop can quickly grow into a system involving state machines, queues, idempotency controls, audit logs, and cost governance.
Message primitives are therefore not merely a “low-level interface.” They are a controllable foundation, well suited to applications with strict requirements for behavioral boundaries, data flows, and compliance auditing. They can also serve as the common protocol beneath higher-level runtimes.
3. Runtime SDKs: Turning the Agent Loop into a Reusable Component
As agents move beyond single-turn responses to multi-step tasks, model invocation is rarely the most frequently rebuilt component. The agent runtime is.
A useful runtime typically includes message-history management, tool registration and execution, lifecycle hooks, permission controls, error retries, context-compaction triggers, subagent scheduling, and observability instrumentation. Agent SDKs package this shared logic into libraries or services so developers do not have to rebuild the loop for every application.
Two common integration patterns are:
| Integration pattern | Best suited to | Key characteristics |
|---|---|---|
| Stateless query interface | One-off tasks, batch processing, lightweight automation | Simple invocation for quickly starting agent tasks |
| Stateful client | Multi-turn conversations, complex workflows, permission-sensitive applications | Maintains session state and supports hooks and permission policies |
Built-in tools commonly cover file reading and writing, editing, command execution, path matching, content search, web search and retrieval, and skill invocation.
Lifecycle hooks are especially important. By inserting custom logic before or after a tool call, when a subagent starts, or before context compaction, developers can implement auditing, blocking, sensitive-data redaction, rate limiting, and behavioral customization without rewriting the agent loop.
The limits of this abstraction also matter. A runtime reduces the cost of implementing agent execution, but it does not automatically solve every production concern. Permission models, data boundaries, state persistence, failure recovery, and cost budgets still require application-level design.
A runtime accelerates development; it does not transfer responsibility away from the application team.
4. Managed Platforms: Context Compaction, Memory, and Multi-Agent Orchestration
In long conversations, multi-task workflows, and collaborative scenarios, the context window becomes a hard constraint. Context compaction is therefore a key component of managed agent platforms.
Compaction summarizes, trims, or stores message history in layers while preserving task objectives, critical facts, and unfinished work. Its purpose is to keep context from growing indefinitely.
A memory layer goes further by separating short-term conversation information from longer-term user preferences, task state, and domain knowledge. These become memory structures that can be retrieved, updated, and governed.
Managed agent platforms also commonly provide session-state management, subagent orchestration, tool-permission policies, execution logs, tracing, and cost monitoring. Together, these capabilities turn agent reliability from implicit application logic into explicit platform-level governance.
A managed platform does not have to be a black box. A sound design should let developers choose their level of control:
- Use message primitives directly.
- Use a runtime SDK while managing state independently.
- Use a managed platform while retaining critical hooks and access to audit records.
Finer control brings more development and operational responsibility. Greater use of managed services can speed delivery, but it also increases the importance of data boundaries, observability, and migration costs.
5. A Practical Architecture: Connect the Layers Through a Common Loop
Whichever layer you choose, use a consistent message and content-block model as the internal contract. The following simplified TypeScript example illustrates an agent loop:
type Block =| { kind: "text"; text: string }| { kind: "tool_call"; id: string; name: string; args: unknown }| { kind: "tool_result"; id: string; content: unknown }| { kind: "reasoning"; text: string };async function runAgent(input: string, tools: ToolRegistry, client: ModelClient) {let messages = [{ role: "user", blocks: [{ kind: "text", text: input }] }];for (let step = 0; step < MAX_STEPS; step++) {const resp = await client.createMessage({ messages, tools: tools.specs });messages.push({ role: "assistant", blocks: resp.blocks });const calls = resp.blocks.filter((b): b is ToolCall => b.kind === "tool_call");if (calls.length === 0) return resp;for (const call of calls) {const result = await tools.execute(call.name, call.args, {timeoutMs: 30_000,idempotencyKey: call.id,});messages.push({role: "user",blocks: [{ kind: "tool_result", id: call.id, content: result }],});}if (shouldCompact(messages)) {messages = await compact(messages, { keepGoals: true, keepOpenTasks: true });}}throw new Error("step limit exceeded");}
The example deliberately makes tool execution, idempotency keys, timeouts, compaction triggers, and a step limit explicit.
Production implementations also need tool allowlists and argument validation, sensitive-data redaction, audit logging, retries and dead-letter queues, cost budgets, concurrency isolation, and versioned prompts.
When integrating a managed platform, ensure that these governance points remain observable rather than relying entirely on internal platform state.
6. Selection Criteria and Governance Priorities
Evaluate the layers across four dimensions:
- Control requirements: Do you need to customize the agent loop, tool protocol, or state machine? Choose message primitives when fine-grained control is essential. Consider runtime or managed layers when delivery speed is the priority.
- State complexity: A stateless interface may be sufficient for one-off tasks. Multi-turn, multi-agent, and long-running tasks require state management, context compaction, and memory.
- Governance requirements: The stricter the requirements for auditing, permissions, data boundaries, and cost monitoring, the more important it is to retain hooks and access to logs.
- Migration costs: Keep internal contracts as independent of a particular runtime as practical. Avoid locking message structures, tool results, and memory formats into a single platform.
The architectural direction is straightforward: message primitives remain the stable core, runtime SDKs package the agent loop, and managed platforms provide context compaction, memory, orchestration, and governance.
Good technology selection is not about chasing the newest abstraction. It is about understanding which problems each layer solves, which dependencies it introduces, and where to preserve clear boundaries for future migration.
