Long-Running Tasks and Multi-Agent Collaboration: An Engineering Guide
This article breaks down what it takes to run long-horizon AI tasks reliably and coordinate multiple agents toward a deliverable. It explains why traditional text benchmarks fall short, then details four pillars of stability—layered context compression, task decomposition with state machines, layout-first chart and document understanding, and multi-agent role handoffs—alongside structured output generation, dual-channel validation, observability, cost control, and common failure modes to avoid.
1. Why Traditional Text Benchmarks Fall Short
In real engineering work, the tasks that consume the most human effort and compute are rarely single-turn Q&A. They are long-horizon jobs that span tens of minutes or even hours. A typical example: reading chart-heavy files (scanned reports, slides packed with axes and legends, multi-column annual reports), extracting information about the same business entity from multiple inconsistently structured documents, and then producing tables, presentations, or analytical reports.
Traditional text benchmarks have three key limitations:
- They assume input is clean, linear, single-modality plain text, while real documents mix layout, images, tables, and footnotes.
- They score only the final answer, which says nothing about the stability of the intermediate process—yet long-task failures usually happen at step 7, not step 1.
- They assume a single call is enough, with no state management or collaboration semantics, so they cannot cover scenarios that require multiple roles dividing the work.
The focus of evaluation and engineering must therefore shift from “answering correctly” to “finishing, recovering, and verifying.”
2. Four Pillars of Long-Task Stability
2.1 Layered Context and Compression
The first enemy of a long task is context bloat. A practical approach is to split information into three layers: a raw layer (document chunks, cropped charts, and their extraction results), a working layer (the fragments required by the current subtask), and a conclusion layer (confirmed structured facts with confidence scores). Only the working layer enters the model context; the rest is retrieved on demand.
# Example: layered context assemblydef build_context(task, store, budget=12000):facts = store.get_confirmed(task.entity_id) # conclusion layerchunks = store.retrieve(task.query, top_k=6) # raw layer, retrieved on demandctx = summarize(facts) + render(chunks)return ctx[:budget] # hard limit for the working layer
This also requires rolling summaries and a write-back mechanism: each time a subgoal is completed, write the conclusion to the conclusion layer to avoid reasoning about the same fact repeatedly.
2.2 Task Decomposition and State Machines
Model a long task as an explicit state machine rather than a one-shot prompt. States should include at least: parsing, extraction, alignment, generation, validation, and write-back. Each state has a clear input contract and output contract, and on failure only the current state rolls back instead of restarting the whole task. This yields two direct benefits: resumable execution, and a drop in failure-localization cost from “read all the logs” to “inspect one state’s input and output.”
2.3 Chart and Layout Understanding
Chart-heavy documents need a layout-first processing order: run layout analysis to get block types (title, body text, table, figure), then reconstruct tables at the cell level, bind figures to their legends and axes, and only then perform semantic extraction. Skipping layout and extracting directly is the main source of misaligned numbers and lost units. In engineering terms, keep the source coordinates and page number for every value so it can be traced back for verification.
2.4 Multi-Agent Division of Labor and Collaboration Protocol
Multi-agent systems are not about splitting one large prompt into several; they are about defining role boundaries and handoff artifacts. A common split: a parser handles layout and chart reconstruction; an extractor handles fields and entities; an aligner disambiguates the same entity across documents; a generator produces tables, presentations, and reports; a reviewer handles rule-based validation and conflict escalation.
The collaboration protocol must specify three things: the schema of handoff artifacts, conflict-resolution rules (source authority and update time take priority), and termination conditions (stop when no new facts are confirmed). A missing termination condition is a common reason collaboration systems get stuck in circular discussion.
{"handoff": {"entity": "Customer A", "field": "annual revenue","value": "1.23B", "unit": "CNY","source": {"doc": "report_07", "page": 42, "bbox": [120, 88, 640, 210]},"confidence": 0.86}}
3. Structured Output Generation: From Extraction to Delivery
The endpoint of extraction is not JSON but a deliverable. Table generation must keep column semantics stable and values traceable; presentation generation must map conclusions to a page skeleton (conclusion pages, evidence pages, appendix pages); report generation must distinguish facts, inferences, and items pending confirmation, avoiding writing low-confidence content as conclusions.
Run “dual-channel validation” on all outputs: the structure channel checks the schema and required fields, while the fact channel traces every value back to its source coordinates. If either channel fails, return to the alignment state rather than emitting output.
4. Engineering Practice: Observability and Cost Control
Long tasks must be observable. The minimum set includes time and retry count per state, the context-usage curve, tool-call success rate, the increment of confirmed facts, and the output validation pass rate. Alerts should be bound to “stalls” rather than only “errors”—for example, trigger human intervention when the number of newly confirmed facts stays at zero for two consecutive cycles.
For cost control, adopt a tiered model strategy: use lightweight models for layout reconstruction and structural validation, and high-capability models for semantic disambiguation and report writing; build a result cache for repeated documents, keyed by document fingerprint. Asynchrony is equally important: decouple long tasks through a message queue, persist state to object storage and database tables, let the container platform handle elastic scaling, and rely on logging and monitoring/alerting services for tracing and threshold reminders.
5. Common Failure Modes and How to Avoid Them
- Lost units and dimensions: require the
unitfield to be non-empty; treat a missing value as a failure. - Cross-document entity mismatch: disambiguate with a composite key of multiple fields; forbid single-field matching.
- Value drift: every value must carry source coordinates; values without a source must not enter the conclusion layer.
- Collaboration loops: set a maximum number of rounds and a no-increment termination condition.
- False success on long tasks: define completion by validation pass rate, not by “whether a file was produced.”
6. Conclusion
Building capabilities for long-horizon tasks and multi-agent collaboration is essentially about wrapping uncertain model behavior in deterministic engineering constraints: layered context controls bloat, state machines guarantee recoverability, role protocols guarantee collaboration, and dual-channel validation guarantees deliverability. On Baidu AI Cloud, using general-purpose capabilities such as object storage, message queues, container platforms, logging, and monitoring/alerting, teams can assemble this pipeline as needed and build an internal evaluation set from their own business documents, continuously measuring improvement with three metrics: stall rate, validation pass rate, and manual rework rate.
