AI Agents from Generation to Delivery: Engineering Practices for Long-Running Tasks
This article examines the shift in AI agent evaluation from single-turn output quality to end-to-end task delivery. It breaks down four core engineering capabilities—long-running execution, self-correction, multi-agent collaboration, and cost control—and covers typical use cases, common anti-patterns, and practical design guidance for building agents that reliably finish complex work.
1. From “Answering Correctly” to “Getting the Job Done”: A Shift in the Objective Function
Over the past two years, models were mainly evaluated on single-turn Q&A accuracy and the fluency of their generated text. Once agents began taking on real work, the evaluation criteria changed fundamentally: Was the task fully delivered? Did it require repeated human intervention along the way? Was the cost per task under control?
Behind this is a change in the objective function. Single-turn generation optimizes for the expected quality of a single output, whereas task delivery optimizes for the expected return of the entire trajectory minus total cost. A stunning answer that cannot be put into practice has zero value from a delivery perspective; a mediocre but stable execution that runs the workflow to completion is worth more.
As a result, the engineering focus has shifted from prompt tuning to task orchestration, state management, failure recovery, and cost accounting. This is also the technical meaning of “compete not on being the biggest, but on being the most capable of getting work done”: capability boundaries are no longer determined solely by parameter scale, but by an agent’s closed-loop capability in real environments.
2. Breaking Down the Four Core Capabilities
2.1 Long-Running Task Execution
The first enemy of long-running tasks is the context window and state loss. A workable approach is to separate “context” from “state”: context retains only the minimal information needed for the current decision, while long-term state is persisted to external storage.
- Task decomposition: Break the goal into verifiable sub-goals, each with a clear completion criterion.
- External memory: Write intermediate artifacts to files, object storage, or structured tables instead of stuffing everything back into the conversation.
- Checkpointing: Persist to disk after each sub-goal is completed, so a failure can resume from that point rather than starting over.
An illustrative state structure:
task = {"goal": "Analyze this batch of files and output a conclusion report","steps": [{"name": "parse", "status": "done", "artifact": "raw.jsonl"}],"budget": {"max_steps": 200, "max_tokens": 400000},"checkpoint": "s3://bucket/run-01/step-3"}
2.2 Task Self-Correction
The essence of self-correction is “verifiability.” An agent without verifiers will only accelerate along the wrong path. Engineering practice recommends introducing three layers of validation:
- Syntax/compilation layer: Can the code build, and is the schema valid?
- Unit validation layer: Do key functions have assertions and test cases?
- Result consistency layer: Are the outputs self-consistent with the input scale and statistical characteristics?
When validation fails, feed the failure information back to the agent in a structured form rather than letting it guess the cause from memory. The key design here is “minimize and make errors actionable”: provide only the necessary error messages and reproduction commands, avoiding context being flooded with noise.
2.3 Multi-Agent Collaboration
Multi-agent collaboration is not about copying one large task into several, but about dividing responsibilities: a planner handles decomposition and acceptance, an executor handles the concrete operations, and a reviewer performs independent review. The three communicate through explicit data contracts, avoiding the semantic drift caused by passing free-form text between them.
The most common causes of collaboration failure are overlapping responsibilities and missing acceptance criteria. In practice, ensure that: each sub-task has only one owner; the reviewer does not participate in execution; and all handoff artifacts are machine-verifiable outputs.
2.4 Cost Control
Cost is not just the unit price, but “total cost per task = number of calls × cost per call + cost of failed retries + cost of human intervention.” The levers for reducing cost, ordered by payoff, are usually: improving the first-pass success rate > reusing caches > tiered model routing > compressing context.
Cache reuse is an underestimated technique: placing stable system instructions, code repository indexes, and reference documents in a cacheable prefix, and putting volatile content afterward, can significantly reduce repeated billing. Tiered routing lets simple sub-tasks go to lightweight models, upgrading only when deep reasoning is required.
3. How It Plays Out in Typical Scenarios
- Batch file analysis and structuring: A four-stage pipeline of parsing, cleaning, extraction, and aggregation, where each stage’s output is persisted and can be re-run independently.
- Repository-level code refactoring: First perform dependency and impact analysis, then commit in small steps, with each step paired with build and test validation.
- Data processing and report generation: Use a schema as the contract, and after generation automatically perform three checks on row counts, null rates, and aggregate values.
- Research-style reasoning: Store hypotheses, experiment designs, data, and conclusions in separate stores, ensuring conclusions are traceable to the original data.
4. Common Anti-Patterns
- Delivering an overly long context all at once, causing key constraints to be diluted.
- Letting the agent “decide on its own whether it is done” without acceptance criteria.
- Re-running everything on failure, with no checkpoints.
- Multi-agents conversing freely, with handoff artifacts that cannot be verified.
- Looking only at unit price rather than total cost per task, ignoring the overhead of retries and human intervention.
5. Conclusion
The measure of a truly valuable agent is not how stunning a single output is, but whether it can reliably deliver after taking on a troublesome task. For developers, the focus of the next round of investment should be on task decomposition, verifiability design, externalized state, and cost observability. In related engineering practice at Baidu AI Cloud, such capabilities are typically implemented by combining general-purpose building blocks such as container platforms, object storage, message queues, and monitoring and alerting, rather than relying on any single feature. Only when the closed loop is built solidly does an agent possess genuine productivity.
