AI Agents for Long-Running Tasks: Engineering Beyond Chat
Moving from conversational AI to task-oriented agents requires more than better answers. This article examines the engineering foundations of reliable end-to-end execution: external state management, incremental replanning, multi-agent coordination, verifiable outputs, and cost per successful task. It also outlines practical workflows for document analysis and debugging existing codebases, along with a deployment checklist.
1. Why Progress Is Easy to Miss: Benchmarks Versus Real Workloads
Perceptions that model capabilities have plateaued often reflect a mismatch in evaluation criteria. If the reference points are single-turn question-answering accuracy or text fluency, improvements over the past year may appear modest. If the question is whether a system can deliver an objective end to end, the change is much more substantial.
The workload itself has changed. Conversational workloads typically involve short contexts, single-step reasoning, and immediate feedback. Task-oriented workloads involve long contexts, multistep dependencies, tools in the loop, and verifiable outcomes. Language understanding largely determines the ceiling for the former; state management determines the ceiling for the latter. Measuring both with conversational benchmarks obscures the difference.
Three measurable dimensions offer a more useful view of progress:
- How many steps the system can advance without human intervention.
- How successfully it continues after requirements change mid-task.
- How much it costs to complete the same task.
These dimensions are generally absent from traditional model leaderboards.
2. From Suggested Answers to End-to-End Accountability
A conventional question-answering model acts as an adviser: it receives a question, provides guidance, and its responsibility ends with the text. An agent receives an objective, and its responsibility ends with the outcome. Between those points, it must handle four functions:
- Task decomposition: Turn an ambiguous objective into verifiable subgoals and define completion criteria for each step.
- Workflow orchestration: Decide which steps should run sequentially or in parallel, and where external tools are needed.
- Execution and observation: Invoke tools, inspect artifacts, and proceed based on actual results rather than assumptions.
- Dynamic correction: Roll back, retry, or change course when results fail to meet the criteria.
These functions place several demands on the model at once: consistency over long workflows, reliable tool-call formatting, and the ability to preserve the original objective through failures. A weak link can cause end-to-end success rates to fall sharply. This is a major reason an impressive demonstration may still be unsuitable for production.
3. Three Engineering Challenges and How to Address Them
3.1 Long-Running Tasks: Context Compression and External State
Complex workflows repeatedly read files, retrieve information, and invoke tools. Context grows quickly. Simply truncating the history can discard earlier conclusions, leading to duplicated work or contradictory decisions.
A more robust approach has three layers:
- Externalize state: Store intermediate conclusions in structured working memory, such as files, task tables, or a key-value store. Keep only references and summaries in the model context.
- Use hierarchical summaries: Compress and archive completed stages, preserving decisions and constraints while discarding raw noise.
- Deduplicate reads: Track previously read files using content fingerprints to avoid repeatedly loading the same material.
An illustrative working-memory structure:
task_state = {"goal": "Produce a quarterly business performance report","constraints": ["Use the same reporting definitions as the previous year","Express all monetary amounts in units of 10,000"],"artifacts": {}, # Produced artifacts: path -> summary"read_index": set(), # Content fingerprints for read deduplication"next_steps": [], # Pending task queue}
3.2 Steerability: Adapt to Changes Without Starting Over
Requirements change in real projects. Poor steerability shows up when a user adds a constraint and the model restarts the entire workflow, discarding completed artifacts.
Instead, changes should be modeled as incremental updates to task state. Identify the affected subgoals, recompute only their downstream dependencies, and reuse unaffected artifacts. This requires explicit dependencies in the task graph rather than a plan hidden in natural-language prose.
3.3 Multi-Agent Collaboration: Coordinators and Workers
A single agent wastes time when it processes independent subtasks sequentially. A practical alternative is a two-tier coordinator–worker structure:
- The coordinator partitions the task graph, defines responsibilities and boundaries, and merges results.
- Workers execute their assigned tasks in parallel within those constraints.
The critical concerns are write conflicts and acceptance criteria. Parallel branches should write to isolated namespaces, with consistent validation during the merge stage to prevent results from overwriting one another.
4. Two Practical Workflows
Batch Document Analysis
For dozens of reports, invoices, and supporting documents, the workflow is:
Inventory → Parse → Extract → Align reporting definitions → Cross-check → Generate charts → Write the report
Key engineering requirements include fallback handling for parsing failures, such as routing scanned documents through a text-recognition pipeline; traceable annotations for conflicting reporting definitions; and source references in the final output. Without those references, the conclusions cannot be audited.
Debugging an Existing Codebase
For a legacy project spread across hundreds of files, the workflow is:
Build a call graph → Narrow the suspect area → Form a hypothesis → Make a minimal change → Run tests to verify
Changes must be small and reversible. Verification must rely on actual builds and tests, not the model’s claim that the issue has been fixed.
5. Cost Measurement: From Tokens to Completed Tasks
The optimization target should shift from a cheaper individual call to a cheaper successful delivery. Task-oriented workloads can incur substantial retry costs, so a useful approximation is:
End-to-end cost ≈ Cost per attempt × Number of attempts
Reducing the number of attempts can be more effective than reducing the unit price. Practical measures include:
- Assigning deterministic logic to code rather than the model.
- Reusing cacheable intermediate artifacts.
- Using smaller models for routing and filtering.
- Reserving larger models for steps that genuinely require reasoning.
General-purpose cloud services can support the surrounding infrastructure: object storage for intermediate artifacts, message queues to decouple tasks, container platforms for parallel workers, and logging, monitoring, and alerting to track step counts and failure rates.
Baidu AI Cloud’s offerings in these general categories can be considered as infrastructure options for task-oriented agents, subject to the availability of the relevant services in the intended deployment region.
6. Deployment Checklist
- Define completion criteria before selecting a model. Do not delegate tasks whose outcomes cannot be verified.
- Require external state storage. The model context must not be the sole source of truth.
- Set timeouts, retry limits, and fallback paths for every tool call.
- Maintain end-to-end traceability. Every conclusion should be traceable to a specific artifact.
- Evaluate staged rollouts using three metrics: steps completed without intervention, successful continuation after requirement changes, and cost per completed task. These are more useful than isolated subjective impressions.
What is often underestimated is not the model itself, but the way it is evaluated. As workloads move from conversation to execution, the central question must shift from “How good was the answer?” to “Was the task completed?”
