The Evolution of Large Model APIs and the Practice of Hosted Agents

    This article explains why a single message-based API cannot support complex agents, and how the interface layer has evolved into three stacked levels: stable message primitives, developer-facing runtime libraries, and server-side hosted agents. It covers state management, tool-use loops, and context budgets as the driving forces behind that evolution; the core design tradeoff of keeping semantics stable instead of expanding features; the tradeoffs between stateless and stateful integration; and the idempotency requirements of hosted tasks. It also outlines practical guidance on cost governance, context engineering, reliability, migration and vendor selection, plus the supporting cloud infrastructure needed in production.

    1. Why a Single Endpoint Cannot Carry a Complex Agent

    Early large model APIs had a narrow goal: accept a list of conversation messages and return a structured result. The model was abstracted as “text in, text out,” and all orchestration logic lived in the caller’s business code. As applications grew more complex, three problems surfaced at the same time.

    The first is state management. A single request is stateless, but agent tasks are inherently multi-step: they must remember the goal, retain intermediate artifacts, and roll back and retry after a failure. If the caller maintains all of that locally, business code gets buried under glue logic.

    The second is closing the loop on tool use. Getting a model to emit “the tool I want to call, plus arguments” is easy. The hard part is the full loop that follows: argument validation, authorization checks, execution, error handling, result trimming, and chunked return of oversized results. The longer this chain, the worse its stability.

    The third is the context budget. Conversation history, tool results, and retrieved snippets keep growing until they hit the window limit and the cost limit. Choosing between fidelity and affordability requires a shared compression and summarization mechanism.

    So the evolution at the API layer is not about “a fancier endpoint.” It is about pushing these recurring problems down from business code into platform capabilities.

    2. Three Threads: Stable Primitives, Runtime Libraries, and Hosted Platforms

    2.1 The Stable Message API: The Minimal Contract Under Everything

    The message-style API widely adopted across the industry shares one trait: it takes a message list plus tool definitions as input and returns an array of structured content blocks. Blocks typically include plain text blocks, thinking blocks, and tool call blocks. By returning different block types, the model tells the caller what to do next.

    The key design tradeoff here is keeping semantics stable rather than expanding features. The value of a stable contract is that upgrading a model version, enabling a new reasoning feature, or swapping the underlying inference engine requires almost no change on the caller side. New capabilities are introduced incrementally, as new block types or new optional parameters, instead of by changing the meaning of existing fields.

    Take tool calls as an example. A typical two-turn exchange looks like this in pseudocode:

    1. # Turn 1: declare available tools; the model returns a tool_use block
    2. resp = client.messages.create(
    3. model=MODEL,
    4. messages=[{"role": "user", "content": "What share of the logs are 5xx?"}],
    5. tools=[query_metrics_tool],
    6. )
    7. for block in resp.content:
    8. if block.type == "tool_use":
    9. # Execution is the caller's job: validate arguments, authorize, rate limit, time out
    10. result = run_tool(block.name, block.input)
    11. # Turn 2: return the execution result as a tool_result block
    12. resp2 = client.messages.create(
    13. model=MODEL,
    14. messages=[
    15. {"role": "user", "content": "What share of the logs are 5xx?"},
    16. {"role": "assistant", "content": resp.content},
    17. {"role": "user", "content": [{"type": "tool_result",
    18. "tool_use_id": block.id,
    19. "content": result}]},
    20. ],
    21. tools=[query_metrics_tool],
    22. )

    This code shows the boundary of the primitive layer clearly: the model only decides; the caller executes and stitches the steps together. The upside of this minimal contract is that it is controllable, observable, and replaceable. The downside is that the orchestration cost of complex tasks falls entirely on the developer.

    2.2 Runtime Libraries for Developers: Exposing the Skeleton of a Mature Agent

    The second thread exposes an agent runtime that has been hardened in large-scale practice, packaged as a library for developers. Such runtimes typically include:

    • A built-in general toolset: file reading, content writing, targeted editing, command execution, path and content search, web fetching and search. Developers do not have to implement details like “how to avoid truncation when reading a file” or “how to locate an anchor when an edit fails” one by one.
    • An extensible tool registration mechanism: internal systems (tickets, monitoring, data platforms) can be wrapped as model-callable tools, with their input and output schemas described uniformly.
    • Hooks and permission control: custom logic inserted before and after execution to implement approval flows, blocking of sensitive operations, and audit logging.
    • Context compaction: when history exceeds the budget, early content is automatically summarized and compressed, keeping the goal and key conclusions while dropping verbose original text.
    • Memory: a distinction between short-term conversation memory and long-term preference memory, where the latter is usually reused across sessions via files or vector retrieval.

    Stateless and stateful integration are the dividing line at this layer. The stateless form suits one-off batch tasks and completes a query in a single call. The stateful form maintains a session object and supports multi-turn interaction, interruption and recovery, and fine-grained permission policies. A simple rule guides the choice: does the task need to retain mutable state across steps. If not, prefer stateless; if so, you must accept the extra engineering constraints that come with a session lifecycle.

    2.3 Platform-Managed Capability: Moving the Runtime to the Server

    The third thread moves part of the runtime from the client to the server, forming hosted agents. The driver is operational complexity: a client-side runtime means the developer owns process liveness, concurrency scheduling, failure retries, result persistence, and observability. Once call volume reaches production scale, these non-functional requirements often consume more engineering effort than model quality itself.

    The typical capability boundary of the hosted form includes a unified entry point for defining and submitting tasks, queuing plus polling or event callbacks for long-running tasks, sandbox isolation of the execution environment, persistence of intermediate artifacts and final results, and traceable execution traces. One thing deserves particular attention in engineering: idempotency. Hosted tasks may naturally be retried, so tool calls and external side effects must be designed to be idempotent; otherwise you get duplicate orders, duplicate writes, and other data problems that are hard to notice.

    The relationship among the three layers can be summarized as:

    Layer Focus Developer responsibility Typical scenario
    Message primitives Semantic stability and portability All orchestration, state, compaction Deep customization, self-owned inference pipeline
    Runtime library Reusing the agent skeleton Tool implementation and business integration Embedding agent capability in a product
    Hosted platform Runtime environment and operations Task definition and result consumption High concurrency, long-running, auditability required

    3. Cost, Context, and Reliability: Three Dimensions to Design Up Front

    Cost governance should not start only after an anomalous bill. Practices that can be layered together include prompt caching for stable prefixes such as system prompts, tool definitions, and long documents, which significantly reduces repeated charges; choosing the cache scope at block level rather than caching everything; routing high-frequency short requests and low-frequency long tasks to different model tiers; and truncating and summarizing tool results so large blocks of raw text do not re-enter the context repeatedly.

    The core of context engineering is allocating a limited budget to the most valuable information. A workable order is: fix the system instructions and output spec first, then inject the current task goal, then add the last few turns of conversation, and finally add retrieved external material. When the budget gets tight, compress earlier turns before the current instructions, because a missing instruction changes model behavior directly.

    Reliability needs three layers of protection: at the parameter level, constrain with structured output (defining fields and types via a schema); at the execution level, apply timeouts, retries, and circuit breaking; at the business level, keep a human confirmation step. Any tool with write operations or external side effects should have automatic execution off by default, and instead require explicit confirmation in a permission hook.

    4. Migration and Selection: Three Practical Recommendations

    First, do not introduce high-level abstractions too early. If the requirement is just “add two or three tools to the model,” a direct implementation at the primitive layer is the cheapest and the easiest to debug.

    Second, keep the interface layer thin. Wrapping model calls in an internal adapter means switching providers, switching model versions, and adjusting caching strategy do not intrude into business logic. This is the most economical way to handle API evolution.

    Third, integrate in tiers by control granularity. Use the primitive layer for core paths to keep them controllable, and hand peripheral capabilities (sandbox-style tasks such as web retrieval and code execution) to hosted services to carry the operational burden. The two do not conflict.

    5. Supporting Infrastructure in a Public Cloud Environment

    Whichever layer you choose, production needs a ring of common infrastructure: object storage for large intermediate artifacts and call traces; a message queue to carry asynchronous long-running tasks; a container platform to provide sandboxed tool execution environments; logging, monitoring, and alerting for call-chain tracing, latency distribution, and failure-rate alerts; and a key management service to hold credentials centrally and support rotation. In this kind of scenario, Baidu AI Cloud typically provides these common capabilities in combination, so developers can assemble what they need and avoid the extra maintenance cost of building it themselves.

    6. Conclusion

    The direction of model API evolution is essentially the continuous downward shift of recurring engineering problems. Stable primitives ensure long-term portability, runtime libraries reuse a mature skeleton, and hosted platforms offload operational burden. Together they form a technology stack that can be deepened layer by layer. Understanding this layered structure has more long-term value than memorizing any single API detail, because it determines how long your architecture can upgrade smoothly as capabilities evolve, rather than being rebuilt over and over.