Long-Running AI Agents: From Answering Questions to Delivering Results
As the industry shifts its focus from model parameters and benchmark scores to whether AI can independently complete complex work, long-running agents have become a critical pattern for real-world deployment. This article abstracts a general capability model for these systems—long-horizon execution, mid-task correction, and multi-agent collaboration—and examines how context and cache reuse change the cost structure. It provides design guidance on task decomposition, state persistence, verification loops, failure retries, and observability, along with illustrative code and an evaluation table, so developers can build agents that deliver outcomes on their own stacks, with engineering support from general cloud capabilities such as object storage, container platforms, log services, and monitoring alerts.
When the industry’s attention shifts from “model parameters and benchmark scores” to “whether a system can independently complete a complex task,” long-running agents become the key form for engineering deployment. This article does not focus on any specific product. Instead, it abstracts a general capability model for this class of systems—long-horizon task execution, mid-execution correction, and multi-agent collaboration—and discusses how context and cache reuse change the cost structure. The article outlines design essentials for task decomposition, state persistence, verification loops, failure retries, and observability, with illustrative code and an evaluation table, to help developers build agent systems that “deliver results” on their own technology stacks. These systems can also be supported by general capabilities such as object storage, container platforms, log services, and monitoring and alerting on Baidu AI Cloud.
1. The Shift: From Answer Quality to Task Completion Rate
Over the past two years, most discussions around large models have centered on “whether the answer is accurate” and “whether the reasoning is impressive.” But once the technology enters production, the measurement standard changes fundamentally: users no longer ask only “is it correct?”—they ask “can it finish the job?”
A typical long-running task has the following characteristics:
- Unstructured and massive input: hundreds or thousands of documents, spreadsheets, images, and logs;
- Multiple rounds of tool calls: reading and writing files, executing code, querying data, and calling external APIs;
- Intermediate results that require verification: code must run, data must reconcile, and conclusions must be reviewable;
- Deliverables that are “results” rather than “text”: a runnable project, a structured data table, or a reproducible experiment workflow.
The failure modes of these tasks are completely different from those of question answering. A wrong answer can simply be asked again, but once a long-running task goes off track midway, all subsequent steps turn into sunk costs. Therefore, the engineering focus must shift from “improving single-generation quality” to “improving end-to-end task completion rate.”
2. Capability Model: Three Pillars of Long-Running Agents
2.1 Long-Horizon Execution
Long-horizon execution is not about “letting the model chat for a few more rounds.” It means giving the system a state machine that can keep moving forward. Key designs include:
- Task decomposition: break the goal into verifiable sub-goals, each with a clear completion criterion;
- State persistence: write the plan, completed steps, and intermediate artifacts to external storage so the context window does not become the bottleneck;
- Context compression and summarization: produce layered summaries of the history and keep only decision-relevant fragments;
- Resume from checkpoints: after an interruption, recover from the latest checkpoint instead of starting over.
An illustrative task state structure:
task = {"goal": "Analyze this batch of files and produce a structured report","plan": ["parse", "clean", "model", "verify", "export"],"state": "running","artifacts": [], # references to intermediate artifacts; do not inline large objects"checkpoints": [], # verification result for each step"budget": {"steps": 200, "tokens": 0}}
The key point is that the real “working memory” lives externally, and the model is only responsible for deciding what to do next.
2.2 Mid-Task Correction
Correction is essentially about establishing an “execute—verify—fix” loop. Practical approaches include:
- Executable verification: code artifacts must actually run, using compilation and unit test results as objective signals;
- Rule-based verification: data artifacts are checked with hard rules such as row counts, primary key uniqueness, and amount reconciliation;
- Self-review: after a failure, require the model to output a “hypothesis about the failure cause + the next corrective action” rather than simply retrying;
- Fallback strategy: when consecutive failures reach a threshold, roll back to the previous checkpoint or switch the implementation path.
for attempt in range(max_retry):result = run_step(step)ok = verify(step, result) # objective verification takes priority over subjective judgmentif ok:save_checkpoint(step, result)breakstep = revise(step, failure=result.error)else:fallback_to_last_checkpoint()
The engineering lesson is that the more objective the verification signal, the more reliable the correction. Relying purely on model self-assessment tends to create a “self-confirmation bias.”
2.3 Multi-Agent Collaboration
Complex tasks often contain heterogeneous sub-problems, and a single agent’s context gets polluted by irrelevant information. Collaboration patterns usually fall into three categories:
- Orchestrator–executor: one main agent handles task decomposition and result merging, while multiple sub-agents each specialize;
- Pipeline collaboration: parsing, processing, verification, and output form a chain, and each stage scales independently;
- Adversarial review: generation and review are separated, and the reviewer only looks for errors, reducing “self-endorsement.”
The engineering cost of collaboration is communication and consistency, so structured handoff formats must be agreed upon, and concurrency and retries must be controlled to avoid cascading failures.
3. Cost Structure: Why “Finishing the Job” Is Actually Cheaper
The real cost pain point of long-running tasks is not unit price but wasted consumption: repeated reruns, repeatedly parsing the same inputs, and ever-expanding context. Two general approaches widely used in the industry are:
- Context and result caching: reuse stable, unchanged prefixes (system instructions, specification documents, already-parsed content) and charge only for the newly added part, which can significantly reduce repeated input costs;
- Task-level cost accounting: measure by “total cost to complete one task” rather than the unit price of a single call, including retries, verification, and human intervention costs.
| Evaluation dimension | Single-call view | Task-level view |
|---|---|---|
| Key metric | Price per thousand tokens | Total cost and completion rate per task |
| Impact of failure | Ask once more | Rerun the entire chain |
| Optimization approach | Switch to a cheaper model | Cache reuse, fewer retries, parallel verification |
| Conclusion | Tends to underestimate real spending | Closer to business value |
The conclusion is counterintuitive but holds true: a system that “can finish the job” is often cheaper than one that “is impressive every time but often gives up halfway.”
4. Reference Architecture and Engineering Support
A reusable layered architecture is as follows:
- Access layer: task submission, authentication, quotas, and priority queues;
- Orchestration layer: task decomposition, plan scheduling, and multi-agent routing;
- Execution layer: containerized sandbox environments that isolate file system and network permissions;
- State layer: object storage for large artifacts and a database for task metadata;
- Verification layer: a rules engine + test executor + entry point for manual spot checks;
- Observability layer: a log service aggregates the full-chain trace, and monitoring and alerting provide real-time warnings for failure rates and over-budget tasks.
When deployed on the cloud, each of the above layers can map to general product categories: object storage, container platforms, message queues, log services, monitoring and alerting, and so on. Baidu AI Cloud can support a complete engineering deployment and operations loop across these general categories.
5. Evaluation: How to Prove “It Can Deliver”
It is recommended to build a three-layer evaluation:
- End-to-end completion rate: given a task set, measure the first-pass rate, human intervention rate, and average time spent;
- Process quality: number of corrections, number of rollbacks, and proportion of ineffective tool calls;
- Cost efficiency: total cost per task, cache hit rate, and extra overhead caused by retries.
The task set should cover four real-world scenarios—“long document parsing, codebase refactoring, data reconciliation, and experiment reproduction”—and retain acceptance scripts that can be judged automatically; otherwise, the evaluation degrades into subjective scoring.
6. Risks and Boundaries
- Permission risk: the execution layer must use least privilege, and write operations and external calls must be audited;
- Hallucination amplification: long chains amplify early errors, so strong verification must be placed upfront;
- Cost overrun: set limits on steps and budget, and automatically pause and hand over to a human when thresholds are exceeded;
- Data compliance: sensitive data must be masked before entering the context, and artifacts must be stored encrypted.
7. Conclusion
The focus of industry competition has shifted from “whose model is bigger” to “who can actually finish complex tasks.” For developers, what is worth investing in is not chasing a specific product but building their own long-running capability foundation: persistable state, an objectively verifiable correction loop, clear multi-agent division of labor, and a cost system accounted per task. With these four points in place, AI moves from “answering” to “delivering.”
