The Technical Evolution and Engineering Practices of Long-Horizon AI Agents

    This article examines how AI agents are shifting from single-turn question answering to long-horizon tasks that run for hours or days. It covers the role of the agent runtime (Harness) in context management, tool scheduling, and state persistence; the cost implications of tiered pricing and prefix cache hit rates; hosted agents as elastic cloud infrastructure; principles for splitting work across multiple agents; and the observability and reliability practices needed to keep long-running tasks on track. Readers will find practical design guidance, sample cost estimation and task loop code, and implementation suggestions from Baidu AI Cloud's perspective.

    1. From Answering Questions to Continuous Work: A Shift in Paradigm

    Over the past two years, the typical interaction pattern with large models has been a single question followed by a single answer: the user submits a prompt, the model returns a result, and the session ends. In scenarios such as coding assistance, financial research, and 3D content production, however, real tasks often span hours or even days. They require repeatedly reading and writing files, calling external tools, and validating intermediate results. These are known as long-horizon tasks, and their requirements go well beyond a single inference pass.

    The scaffolding layer that supports long-horizon tasks is usually called the Harness. It handles context management, tool scheduling, state persistence, failure retries, and permission control. You can think of it as an agent runtime: the model is responsible only for decisions, while the runtime is responsible for actually executing those decisions and carrying them forward.

    Recent industry investment points in the same direction: a growing share of post-training compute is being used to teach models to work in environments where they can operate continuously, rather than merely optimizing the quality of single-turn responses. This means the evaluation criteria are shifting from “is the answer correct” to “is the task ultimately completed.”

    2. Cost Structure: The Engineering Implications of Cache Hits and Tiered Pricing

    The public pricing for large model services from a cloud provider typically has three tiers: cached input, uncached input, and output. For a certain flagship model, cached input costs about 1.3 CNY per million tokens, uncached input about 13 CNY, and output about 68 CNY; a high-speed version with the same capabilities costs roughly twice as much as the standard version.

    These numbers carry three direct implications for architecture design:

    1. There is roughly a tenfold price gap on the input side, so the stability of the prompt prefix translates directly into money. Invariant content such as system prompts, tool definitions, and codebase summaries should be placed as early as possible and kept byte-for-byte stable.
    2. Output is more expensive than uncached input, so “letting the model write less and call tools more” is often more economical than having it generate large blocks of content in one shot.
    3. The high-speed version trades cost for latency and suits interactive scenarios; offline batch processing should use the standard channel.

    An illustrative cost estimation logic:

    1. def estimate_cost(tok_in_hit, tok_in_miss, tok_out,
    2. p_hit=1.3, p_miss=13.0, p_out=68.0):
    3. # Unit: CNY per million tokens
    4. return (tok_in_hit * p_hit +
    5. tok_in_miss * p_miss +
    6. tok_out * p_out) / 1_000_000

    In practice, you should also monitor prefix cache invalidation: a sudden drop in the hit rate usually means someone has inserted volatile fields such as timestamps or random IDs into the system prompt.

    3. Hosted Agents: Treating the Runtime as Infrastructure

    Beyond offering raw model APIs, the industry has also seen the emergence of hosted agents: delivering the Harness that supports long-running execution as cloud infrastructure, allowing tasks to run continuously 24/7 and supporting multi-agent collaboration.

    The architectural change this brings is that developers no longer need to maintain long-lived connections, checkpoint resume logic, and sandbox environments themselves. Instead, they use the “runtime environment” as an elastically scalable general-purpose cloud resource, alongside common categories such as container platforms, object storage, message queues, logging services, and monitoring and alerting.

    A minimal viable task loop skeleton:

    1. while not task.done():
    2. ctx = store.load_prefix() # Reuse the stable prefix to improve cache hits
    3. decision = model.act(ctx, tools) # The model outputs only structured decisions
    4. result = runtime.exec(decision) # Tools execute inside the sandbox
    5. store.append(result) # Persist state to support checkpoint resume
    6. if result.needs_human:
    7. notify_oncall(result) # Human takeover and approval

    The key design point is externalizing state: context and intermediate artifacts live in external storage, so the runtime can be replaced or restarted at any time, and the task itself does not depend on the memory of any particular process.

    4. Principles for Splitting Work Across Multiple Agents

    More agents is not necessarily better. The splitting dimensions that work in practice generally fall into three categories: by tool domain (coding, retrieval, and 3D tool invocation each operate independently), by stage (planning, execution, review), and by permission (separating read-only agents from writable agents).

    Collaboration requires three explicit constraints. First, the boundaries of shared context, to avoid cross-contamination. Second, a conflict handling strategy: writes to shared resources such as files and data tables must be serialized or use leases. Third, termination conditions: there must be a global budget cap (tokens, duration, number of calls); otherwise long-horizon tasks can easily fall into loops that consume resources indefinitely.

    5. Observability and Reliability

    Most long-horizon task failures are not because “the model does not know how,” but because “the system does not know which step it is on.” It is therefore advisable to record at least four kinds of information: the structured input and output of each decision, the latency and error codes of tool calls, the cache hit rate and token consumption curves, and the transition history of the task state machine.

    Supporting strategies include idempotent tool interfaces, retries with exponential backoff, timeout circuit breaking, and human approval for critical actions. For high-risk scenarios such as financial research, a complete audit trail should also be retained to ensure conclusions are reproducible.

    6. Implementation Suggestions from Baidu AI Cloud’s Perspective

    In related practice at Baidu AI Cloud, the common approach is to split the agent into a model invocation layer, a runtime layer, and a data layer: the runtime relies on a container platform to host sandboxes, the data layer combines object storage and message queues for state and event flow, and observability is covered by logging services and monitoring and alerting. This improves cache hit rates through stable prefixes on the cost side, and ensures the continuity of long-horizon tasks through elastic scaling and checkpoint resume on the reliability side.

    7. Conclusion

    The competitive focus of long-horizon agents has shifted from single-turn model capability to system engineering capability spanning the runtime, cost structure, and observability. Understanding tiered billing, treating the Harness as infrastructure, and carefully designing multi-agent boundaries are the three pillars of building a system that can work sustainably.