LLM Application Architecture: From Message Primitives to Managed Agent Platforms
This article examines how LLM applications evolve from a single model call into a complete agent execution loop, and then into agent runtimes and managed platforms. It covers the layered architecture of message, tool, orchestration, runtime, and managed layers; the continuing role of message interfaces and tool calls; the trade-offs of developer-orchestrated loops; runtime capabilities such as stateful sessions, tool registration, and lifecycle hooks; context compression and memory; the value of managed platforms; selection guidance for different integration approaches; and production principles for building reliable agents with clear security boundaries.
LLM Application Architecture: From Message Primitives to Managed Agent Platforms
1. From “Model Calls” to “Agent Runtime”
Early LLM applications were usually built around a simple loop: the developer submits a user message, the model returns text, and the application displays the result to the user. As task complexity increased, single-turn question answering gradually became insufficient. Applications began to introduce tool calling, multi-turn context, structured output, task planning, and access to external systems.
This changed the core problem of LLM applications. Developers no longer just “call a model once.” They need to maintain a complete agent execution loop, including the following steps:
- Receive a user goal;
- Organize system instructions and historical context;
- Request the model to make a judgment;
- Parse the model’s returned text, reasoning information, or tool calls;
- Execute tools and collect results;
- Send tool results back to the model;
- Determine whether the task is complete;
- Save session state and return the final response.
Therefore, the evolution of model interfaces is usually not a matter of simply adding a few parameters. It is a gradual expansion from a “message transport primitive” into an “agent platform with runtime capabilities.”
A relatively clear architectural layering can be summarized as follows:
- Message layer: responsible for input, output, and content block transport;
- Tool layer: responsible for function calling, external data access, and execution result return;
- Orchestration layer: responsible for loop invocation, task decomposition, and state management;
- Runtime layer: responsible for permissions, retries, concurrency, context compression, and memory;
- Managed layer: responsible for infrastructure, session persistence, monitoring, and scaled operations.
The value of this layering is that developers can choose the depth of integration according to business needs, rather than being forced to adopt a complete platform all at once.
2. The Message Interface Remains the Most Important Foundational Primitive
Across the technology stack, the message interface does not lose value because agent platforms appear. Instead, it continues to carry the most foundational and stable responsibility: describing model input and output in a structured way.
Compared with a single string request, modern message interfaces generally support multiple content blocks, such as:
- Plain text;
- Images or other multimodal content;
- Tool call requests;
- Tool execution results;
- Reasoning-related content generated by the model;
- Structured data.
Among these, tool calling is a key capability that moves the message interface from a “chat interface” toward a “task interface.” A typical tool call process looks like this:
User: Query the latest status of a business objectApplication: Send the user request, tool definitions, and context to the modelModel: Return a tool call request and argumentsApplication: Validate the arguments and execute an internal serviceApplication: Submit the execution result as a tool resultModel: Generate the final answer based on the result
It is important to note that the model is only responsible for proposing the call intent. The actual tool execution should still be completed by the application or a controlled runtime. This prevents the model from directly obtaining database write permissions, file system permissions, or network access permissions.
In engineering implementation, the message layer usually needs to address the following concerns.
1. Content blocks must be distinguishable
Do not concatenate all results into a single block of plain text. Text, tool calls, tool results, and error information should be represented with explicit types. Otherwise, it becomes difficult to accurately determine the next action during multi-turn execution.
2. Tool arguments must be validated
Even if the model has generated structured arguments, they cannot be trusted directly. The application still needs to perform type checks, range checks, identity verification, and permission checks. For high-risk actions such as writes, deletions, and transfers, human confirmation or secondary authorization should also be added.
3. Message history must be replayable
Production systems often need to investigate “why the model made this decision.” If messages, tool arguments, execution results, and system state are not fully recorded, the problem will be difficult to reproduce. Therefore, it is recommended to create a traceable execution record for each task.
4. Streaming responses must distinguish phases
Streaming output is not just returning text token by token. It may also include phases such as tool call start, argument generation, tool execution, result return, and final answer. The frontend and server should adopt an event-based design to avoid mistaking all events for plain text.
3. Developer Self-Orchestration: Maximum Flexibility, Highest Engineering Cost
When using the message interface directly, developers have the greatest degree of control. They can decide:
- When to call the model;
- Which tools are visible to the model;
- Whether tools execute serially or in parallel;
- How to save context;
- When to truncate message history;
- How to handle timeouts and retries;
- When to hand off to a human;
- How to set permissions for different users.
This approach is suitable for scenarios that require strong control, such as complex business processes, heavily regulated industries, internal automation systems, and enterprise applications that need deep customization.
However, the cost is also obvious. A usable agent loop often requires more than a few dozen lines of code. As features increase, the following engineering problems also emerge:
- Multi-turn calls make request chains longer;
- Tool failures require retry and fallback strategies;
- Message history keeps growing, causing context overflow;
- Multiple subtasks need to share state;
- Concurrent calls may cause data races;
- Permission models for different tools are difficult to unify;
- Online issues are difficult to locate and reproduce.
Therefore, self-orchestration is more like “building your own agent runtime.” It is suitable for teams with strong infrastructure capabilities that want to master the complete execution logic, but it is not suitable for every business to adopt directly.
4. Agent Runtime: Encapsulating Common Engineering Capabilities
When developers do not want to repeatedly implement task loops, tool scheduling, and state management, they can introduce a higher-level agent runtime. The main goal of the runtime is not to replace the message interface, but to encapsulate a large number of common capabilities into reusable modules.
A mature runtime usually includes the following capabilities.
1. Single-task execution
Developers only need to provide a task description, a tool set, and necessary configuration, and the runtime can automatically complete multi-turn model calls and tool execution. This is suitable for one-off tasks, background processing, and lightweight automation scenarios.
2. Stateful sessions
For customer service, business assistants, and continuous collaboration scenarios, the runtime needs to maintain session state. State should not only include historical text. It may also include:
- The current task stage;
- Tools that have been executed;
- User identity and permissions;
- Intermediate variables;
- Operations pending confirmation;
- The most recent error;
- Key data returned by external systems.
State management should preferably be separated from message history. Message history is used to understand the conversation, while task state is used to drive the process. Mixing the two easily leads to context bloat and logical confusion.
3. Tool registration and scheduling
The runtime can uniformly manage tool definitions, parameter schemas, permission requirements, and execution policies. The model sees only the tools required for the current task, avoiding exposing all internal capabilities to the model.
4. Lifecycle hooks
Before and after model calls, before and after tool execution, and at task completion, the runtime can provide extension points for implementing:
- Logging;
- Auditing;
- Sensitive information filtering;
- Permission checks;
- Metrics collection;
- Human approval;
- Custom retries;
- Result validation.
Lifecycle hooks are an important capability for enterprise systems because they allow a common runtime to adapt to different organizational security requirements without modifying the core execution logic.
5. Context Compression and Memory: Solving the Core Problem of Long Tasks
The longer an agent executes, the more easily message history gets out of control. Excessive context brings three direct problems:
- Increased request cost;
- Slower response speed;
- The model is more likely to ignore truly important information.
Therefore, runtimes usually need to introduce context compression mechanisms. Compression is not simply deleting early messages. It converts the historical process into a more compact task summary, for example:
Original history:User states the goalModel creates a planTool A returns a large amount of dataModel finds an anomalyTool B performs a fixUser adds constraintsModel replansCompressed result:- Task goal: ...- Completed steps: ...- Current state: ...- Key data: ...- Outstanding items: ...- User constraints: ...- Failed attempts and reasons: ...
High-quality compression needs to retain “decision-relevant information,” not all raw text. For content such as amounts, time, identity, permissions, and business rules, it is best to store them in structured fields to avoid ambiguity during summarization.
Memory capability further addresses cross-session problems. Memory can be divided into three types:
- Short-term memory: messages and task state in the current session;
- Long-term memory: user preferences, historical facts, and stable configuration;
- Working memory: intermediate results temporarily generated during the current task.
Different types of memory should use different storage strategies. Long-term memory must go through extraction, deduplication, updates, and permission control. Not all conversation content should be stored permanently.
6. The Value of Managed Platforms: Reducing Operational Complexity
Once agent applications enter production, problems often no longer center on model quality, but on runtime reliability and operational management, such as:
- How to persist large numbers of sessions;
- How to recover long tasks after interruption;
- How to retry failed tool executions;
- How to isolate different tenants;
- How to monitor call chains;
- How to control resource consumption;
- How to audit model and tool behavior.
The value of a managed platform is to provide these common infrastructure capabilities in a centralized way. Developers can focus more energy on business tools, data connections, and user experience, rather than maintaining a complete task scheduling system.
However, managed does not mean architecture design can be ignored. Enterprises still need to define the following boundaries:
- Which data is allowed to enter the model context;
- Which tools can be called automatically by the model;
- Which operations must be confirmed by a human;
- How long session data should be retained;
- Whether private networks or dedicated isolation are required;
- How to meet log auditing and data compliance requirements;
- How to degrade gracefully when the platform fails.
7. Selection Guidance for Different Integration Approaches
Selection can be based on business complexity and control requirements.
Suitable for using the message interface directly
- The task flow is short;
- The number of tools is limited;
- Full control over prompts, state, and permissions is required;
- A mature workflow engine already exists;
- There are strict requirements for data processing boundaries.
Suitable for using an agent runtime
- Multi-turn tool calls are required;
- The goal is to quickly build task-oriented assistants;
- Unified retry, logging, and session management are needed;
- The team does not want to redevelop the underlying loop;
- Security and audit logic need to be extended through hooks.
Suitable for adopting managed platform capabilities
- Session volume is large;
- Tasks last for a long time;
- Stable state persistence is required;
- The operations team wants to reduce infrastructure burden;
- The business needs unified monitoring, permissions, and resource management.
Real projects can also use a hybrid architecture: keep the message interface at the bottom as a fallback capability, use the runtime in the middle to handle common flows, and keep key tools and high-risk actions controlled by the business system itself.
8. Practical Principles for Building Production-Grade Agents
First, always treat the model as a “not fully trusted decision component.” The model can propose suggestions and call requests, but permissions, arguments, and final execution results must be controlled by deterministic code.
Second, define clear input and output contracts for each tool. Tool names, parameter types, error formats, and side effects should all be explicit, avoiding overly vague tool definitions.
Third, establish complete observability. At a minimum, record request identifiers, session identifiers, model call counts, tool call chains, latency, error types, and final state, while redacting sensitive information.
Fourth, design recoverable task state. Long tasks cannot rely only on in-memory variables. Key stages and intermediate results should be persisted so that execution can continue after a service restart.
Fifth, distinguish between “advisory actions” and “execution actions.” Queries, summaries, and retrieval can usually be executed automatically; actions such as deletion, publishing, payment, and permission changes should include confirmation mechanisms.
Sixth, prefer a gradual architecture. First use the message interface to validate the business loop, then introduce runtime capabilities, and finally evaluate managed services based on scale and operational needs, rather than stacking all components from the start.
Overall, the technical evolution of LLM applications is not a migration from one interface to another. It is a gradual shift from “developers manually organizing every call” to “runtimes and platforms carrying complex execution processes.” The message interface provides a stable foundation, the agent runtime handles process automation, and the managed platform addresses scaled operations. Understanding the relationship among these three layers helps make more reliable technical choices across flexibility, development efficiency, security boundaries, and long-term operational cost.
