Cloud-Hosted AI Agents: Runtime Architecture and Fine-Grained Billing in Practice

    As LLM applications shift from single-turn Q&A to long-horizon, multi-step tasks, AI agents have become a focal point. This article examines the harness architecture behind cloud-hosted agent services, including state persistence, exception recovery, sandbox isolation, and multi-agent orchestration. It then analyzes a fine-grained billing model composed of sandbox runtime, model inference, and plugin calls, and discusses enterprise use cases, API-based operations, and a pre-inference security interception mechanism.

    As large language model (LLM) technology moves into deeper industrial adoption, enterprise requirements have evolved from simple single-turn Q&A to complex, long-horizon tasks that require multi-step coordination. This shift has made AI agents a major focus. However, building a stable agent is not trivial. Developers must handle not only model inference but also tool orchestration, state preservation, and exception recovery. Recently, a new trend has emerged: treating the agent runtime environment as a cloud-hosted service. This model lowers engineering barriers and introduces an innovative billing approach that signals more fine-grained commercialization of LLM applications.

    1. Core Architecture of Hosted Agents: The Harness System

    An agent is not an isolated model but a complete system. Within this system, the runtime and orchestration layer built around the LLM is called the harness. The harness acts as the agent’s central nervous system, responsible for organizing model calls, tool execution, session management, and task scheduling.

    In a cloud-hosted service, the harness layer is encapsulated above the underlying model inference API, providing developers with a 24/7 continuous execution environment. Its core technical capabilities include:

    1. State persistence and session management: Long-horizon tasks often span extended periods. By integrating cloud-native components such as message queues and object storage, the harness persistently stores session history and ensures that context is not lost.
    2. Exception recovery and timeout retries: When calling external tools or performing complex reasoning, network jitter and API timeouts are unavoidable. The harness includes built-in retry mechanisms and failure rollback strategies to improve the robustness of task flows.
    3. Isolated execution in cloud sandboxes: For agents that need to run code or manipulate files, the system provides independent cloud sandbox environments. These sandboxes are typically implemented with lightweight container technology to isolate resources and data between tenants and prevent malicious code escape.
    4. Multi-agent orchestration: For complex business scenarios, a single agent is often insufficient. The harness supports multi-agent collaboration, allowing developers to define agents with different roles and achieve high-level goals through task distribution and result aggregation.

    2. Evolution of Billing: From Tokens to Runtime Environments

    In the past, model providers mainly charged developers based on token usage. This model works well for single-turn conversations but faces challenges in agent scenarios. When executing tasks, agents not only consume inference tokens but also occupy computing resources for extended periods to maintain state and frequently call various external plugins. As a result, a more fine-grained billing model has emerged that separately itemizes sandbox runtime and plugin calls.

    This billing system typically consists of three parts: Total cost = sandbox runtime fee + model inference fee + plugin call fee.

    1. Sandbox runtime fee: Charged by runtime duration (for example, CNY 0.072 per hour). If a cloud sandbox runs continuously for 30 days, the base environment cost is approximately CNY 51.84. This billing logic reflects the CPU, memory, and state-preservation resource overhead generated by the agent runtime environment itself, marking the runtime environment as an independent billing object.
    2. Model inference fee: This continues to use the traditional token-based billing model and is calculated based on the number of tokens the agent actually consumes during reasoning and generation.
    3. Plugin call fee: Calculated as the product of call count and unit price. Because different plugins have different underlying resource costs, unit prices vary significantly. For example, a basic web search costs about CNY 0.03 per call, image retrieval about CNY 0.045, while calls involving professional financial data interfaces may reach CNY 0.35 to CNY 0.45 per call. This differentiated pricing encourages developers to optimize tool invocation strategies when designing agent workflows and avoid unnecessary calls.

    3. Enterprise Use Cases and Engineering Practices

    Hosted agent services provide flexible access methods for enterprises, including web consoles, command-line tools, and standard APIs. Enterprises typically apply them in two major scenarios:

    3.1 Internal System Integration: Business Monitoring and Operations Response

    By integrating agents with internal IT systems, enterprises can automate operations and maintenance. For example, a monitoring agent can be configured to read anomaly alerts from log services in real time, automatically analyze stack information, and call operations tools to perform restarts or scaling operations.

    The following is a pseudocode example of calling a hosted agent through an API to execute an operations task:

    1. import requests
    2. url = "https://api.cloud-platform.com/v1/agents/run"
    3. headers = {"Authorization": "Bearer YOUR_API_KEY"}
    4. payload = {
    5. "agent_id": "ops-monitor-agent-01",
    6. "task": "Analyze error logs from the last 10 minutes and extract the names of abnormal services",
    7. "tools_enabled": ["log_search", "service_restart"],
    8. "sandbox_config": {
    9. "max_runtime_seconds": 300
    10. }
    11. }
    12. response = requests.post(url, json=payload, headers=headers)
    13. print(response.json())

    3.2 External Product Embedding: Investment Research Assistants and Intelligent Customer Service

    In external services, agents can be embedded into products as value-added services. For example, in finance, predefined financial agent templates can be combined with general financial data source APIs (offered as standardized plugins on the hosting platform) to build assistants for investment research modeling, IPO tracking, or fund reconciliation. Platforms often provide hundreds of predefined skills and dozens of plugins, greatly shortening the time required to launch business services.

    4. Security and Compliance: Pre-Inference Interception

    In enterprise applications, data security is a red line that cannot be crossed. When executing tasks, agents not only need to read internal enterprise data but also send intermediate results to LLMs for inference, increasing the risk of sensitive data leakage.

    To address this challenge, modern hosted agent platforms introduce an independent security component that can be called a pre-inference interceptor. It works by acting as middleware before each model inference call, intercepting and inspecting task inputs and tool-returned content. Enterprises can define custom rules based on their compliance requirements (such as regular-expression matching for ID numbers or desensitization of financial data) and decide whether to allow or block the request. This mechanism is usually made available first to enterprise-certified users with high security requirements, ensuring that core data does not pass through the model inference stage.

    5. Conclusion and Outlook

    Treating the agent runtime environment as a cloud-hosted service and introducing a three-dimensional billing model of sandbox, inference, and plugins is an inevitable result of LLMs moving deeper into industry. It decouples application development from underlying infrastructure, allowing developers to focus more on business logic, while also providing cloud service providers with a more reasonable path to commercial return. In the future, as multi-agent orchestration technology matures and security components continue to improve, hosted agents will become standard infrastructure for enterprise digital transformation.