# LLM API Evolution and Hosted Agent Platforms: Building Agent Applications with Agent SDKs and Managed Runtimes
This article traces how LLM APIs have moved from stateless text completion toward hosted agent platforms, and what that shift means for developers building production AI applications. It explains the architectural role of the Agent SDK, contrasts stateless query mode with stateful client mode, and covers the runtime capabilities each one depends on: agent loops, context management, hooks, three-layer permission and sandbox isolation, model routing, standardized tool integration, and full-chain observability. Drawing on the layered architecture of Baidu AI Cloud's Qianfan large-model platform, it closes with practical guidance on gradual privilege granting, structured output constraints, context compression, and human-in-the-loop approval. Readers will come away with a clear map of the technical path from Messages primitives to a managed agent runtime.
1. Introduction: From Answering Questions to Executing Tasks
The service model of large language models (LLMs) is undergoing a profound paradigm shift. In the early stage, developers mainly called a model’s “completion” or “chat” capabilities through RESTful interfaces or SDKs. This pattern is essentially a stateless function call: text in, text out. As business complexity has grown, however, enterprises have found that text generation alone cannot handle tasks that require multi-step reasoning, interaction with external data, and tool invocation.
To close this gap, agentic coding tools such as Claude Code, followed by the emergence of the Agent SDK, marked the start of a new phase in the industry: exposing the agent runtime to developers so they can build hosted agent platforms. This is more than a simple API upgrade. It decouples and reuses the underlying architecture that powers agentic coding tools.
Against this technical backdrop, this article discusses how to build efficient and secure agent applications on top of a general-purpose LLM service platform, using the layered architecture of Baidu AI Cloud’s Qianfan large-model platform as an example to detail the implementation path from Messages primitives to a hosted agent platform.
2. Core Concepts: Where the Agent SDK Sits Architecturally
In September 2025, a landmark event took place in the industry: a leading AI company rebuilt its existing coding assistant SDK and renamed it the “Agent SDK.” The move made one technical trend explicit: an agent should not be a plugin locked inside a code editor, but a general-purpose runtime environment that can be embedded into any business system.
The core value of the Agent SDK lies in the three categories of capability it encapsulates:
- Agent loop control. Manages the iterative “think–act–observe” cycle, automatically handling tool call results and deciding the next action.
- Context management. Automatically compresses context and slices memory during long tasks to prevent token overflow.
- Security and sandboxing. Isolates the agent’s execution environment (shell commands, filesystem, and so on) from the host system, using fine-grained permission controls to prevent out-of-scope operations.
In general architecture designs, an agent runtime typically offers two core integration modes, and developers should choose based on the “state complexity” of the business scenario:
| Integration mode | Core characteristics | Suitable scenarios | Implementation notes |
|---|---|---|---|
| Stateless query mode | Single request–response, no persistent session, lightweight logic | Offline batch processing, simple text summarization, one-off code review | Similar to a query() function; agent logic orchestration usually fits within 20 lines of code |
| Stateful client mode | Maintains session context, supports multi-turn interaction, can mount hooks | Interactive IDE assistants, customer service bots, long-cycle task flows | Similar to a ClaudeSDKClient class; supports the Hooks mechanism and dynamic permission injection |
3. Mode 1: The Stateless Query
For the vast majority of automation scripts and backend services, there is no need to maintain a long-lived session. The stateless query mode is the minimal expression of agent capability, and its core idea is to wrap the agent as a pure function.
3.1 Design principles
In stateless mode, the developer passes in an initial system_prompt (system instructions), a user_query (the user request), and tools (the list of available tools). The agent runtime completes all reasoning inside a closed loop and finally returns a structured result, without retaining the intermediate conversation history.
3.2 Code example and walkthrough
The following Python pseudocode shows how to start an agent with file analysis capability in under 20 lines of code:
from agent_sdk import query, Tool# 1. Define the tool function (declaration only, stateless)analyze_code = Tool(name="code_analyzer",description="Analyze the code quality of a given file",func=run_custom_linter)# 2. Issue a single agent query# Note: there is no need to manually manage the messages list or tool_resultresponse = query(model="general-purpose-llm",system="You are a senior code reviewer.",prompt="Please check src/main.py for potential bugs.",tools=[analyze_code],max_turns=5 # Cap the agent's maximum number of turns to prevent deadlock)print(response.content)
3.3 Recommendations for enterprise use
In production, particularly when calling SDKs on Baidu AI Cloud’s Qianfan platform, stateless mode requires attention to the following:
- Timeout control. A strict timeout must be set, because an agent’s multiple tool calls can make total elapsed time far exceed that of a normal LLM request.
- Idempotency design. If the network is interrupted mid-execution, the stateless nature means retry logic must guarantee idempotent operations, so that destructive tools such as “delete file” are not executed repeatedly.
4. Mode 2: The Stateful Client
When a business needs to simulate the sustained interaction of a human assistant, a stateful client (the ClaudeSDKClient concept) becomes the natural choice. It is not merely a conversation interface but an extensible runtime environment.
4.1 The Hooks mechanism: injecting business logic
Hooks are a core feature of advanced agent platforms. They let developers insert custom logic at key points in the agent lifecycle without modifying the agent’s core loop.
- PreToolUse hook. Triggers before a tool executes. Commonly used for security auditing and parameter injection. For example, when an agent attempts to run an
rm -rfcommand, the hook can intercept the request and raise a manual confirmation dialog. - PostToolUse hook. Triggers after a tool returns its result. Commonly used for logging and context enrichment. For example, automatically masking sensitive fields after a database query.
4.2 Permission control and sandbox isolation
In a hosted agent platform (such as the agent runtime of Qianfan), the permission model is typically divided into three layers:
- API-layer permissions. IAM-based policies that control who can invoke a given agent instance.
- Tool-layer permissions. A fine-grained tool access control list (ACL) that ensures agent A cannot reach a database reserved for agent B.
- Execution-layer sandbox. Code or commands generated by the agent run inside a containerized sandbox, with CPU, memory, and outbound network access restricted, preventing system escape caused by prompt injection attacks.
# Example: initializing a stateful clientclient = ClaudeSDKClient(model="claude-3-5-sonnet",allowed_tools=["Read", "Bash"], # Explicit whitelist of permitted toolspermission_mode="acceptEdits" # Permission mode: accept edits but disallow dangerous commands)# Open the session and maintain contextasync with client:await client.query("Initialize a new React project.")# The agent will loop over the Bash tool to run commands such as npm create vite# Developers can listen to streamed output or interrupt here
5. From API to Platform: Architectural Evolution from the Qianfan Perspective
Whether you choose the stateless query or the stateful client, both need a powerful hosted platform underneath. Using Baidu AI Cloud’s Qianfan large-model platform as an example, its architecture reflects the current common best practices of an AI middle platform.
5.1 Model routing and load balancing
Agent tasks are inherently uncertain: a simple request may only need a small model, while complex reasoning demands a large one. At the platform layer, model routing policies dynamically schedule underlying compute resources (such as the ERNIE series of models) according to task complexity, achieving an optimal balance between cost and performance.
5.2 Tool ecosystem and the MCP protocol
To make tools reusable across agents, the industry is moving toward standardized tool-calling protocols (for example, the Model Context Protocol, or MCP). The Qianfan platform supports registering enterprise-internal APIs (such as order lookup or ticketing systems) through a standardized plugin interface, so an agent can call enterprise microservices as easily as local functions, greatly reducing integration cost.
5.3 Observability and debugging
The “black box” nature of agents is the biggest obstacle to adoption. A hosted platform must provide full-chain tracing:
- Execution trace replay. Records the agent’s thought, action, and observation at each step.
- Token consumption analysis. Identifies which steps consume large amounts of tokens so prompt design can be optimized.
- Hallucination detection. Uses a rule engine or a secondary verification model to flag low-confidence content generated by the agent.
6. Best Practices and Pitfalls to Avoid
When integrating an Agent SDK into production, enterprises should follow these principles:
- Grant permissions progressively. Never give an agent “super administrator” privileges from the start. Apply the principle of least privilege: first let it validate its logic in read-only mode, then gradually open up write permissions.
- Constrain structured output. Require the agent in the system prompt to emit JSON or a specific XML format, and validate it against a backend schema, avoiding process failures caused by parsing errors in natural language.
- Adopt a context compression strategy. In long conversation scenarios, history messages cannot accumulate indefinitely. Implement a sliding window or summary memory that preserves key information while controlling token cost.
- Keep a human in the loop. When designing high-risk task flows, always reserve interrupt points. When agent confidence falls below a threshold or it attempts a sensitive operation, it should automatically pause and request human approval.
7. Conclusion
From “Messages primitives” to the “hosted agent platform,” the evolution of the LLM API is a history of progressively encapsulated capability and steadily rising levels of abstraction. Developers no longer need to worry about low-level tensor computation or complex state machine maintenance; they can focus on defining business logic and orchestrating tools. For enterprises in China, combining the agent runtime capabilities offered by mature platforms such as Baidu AI Cloud Qianfan with their own industry know-how will make it possible to build AI-native applications that are both intelligent and reliable, achieving a genuine leap from “conversational AI” to “execution AI.”
