Engineering Long-Horizon Tasks with Multi-Agent Collaboration
Long-horizon software work exposes limits of single-turn evals: diluted context, compounding error, and cheap generation versus expensive verification. This article covers role split (plan, execute, verify), isolated parallel workflows, human-in-the-loop observability, and common anti-patterns.
Where long-horizon tasks break
Most benchmarks stay at single-turn Q&A or one-shot function completion. Real engineering work often spans hours or days. Completing a complex software change is rarely about “writing a snippet.” The hard parts are reading project structure and conventions, turning vague requirements into executable steps, calling multiple tools, and recovering after repeated failures. Stretch the timeline and three structural bottlenecks show up together.
Context length is not effective context. A larger window is necessary, not sufficient. As turns accumulate, early constraints fade and mid-sequence facts are underused—the model can “see” the transcript and still miss what matters. A practical approach is to externalize volatile state: task lists, decision logs, interface contracts, and failure logs live in files or other storage. Each turn loads only the minimum context for the current step and retrieves the rest on demand.
Error compounds along the chain. A 95% per-step success rate yields under 40% expected success after twenty steps. Long-horizon systems need checkpoints, roll-backable versioned state, failure classification, and a bounded retry budget—not a single path to the end.
Generation is cheap; verification is expensive. Producing a patch costs far less than confirming it is correct. Without an automated verification loop, the system quickly becomes “looks done.” Compile, unit tests, static analysis, type checks, and contract tests in the loop are what make long tasks trustworthy.
Role split: plan, execute, verify
A single agent overloads one chain with too many jobs: understand the request, assign work, code, summarize, and review. Cross-module changes then hit both progress and context limits. Multi-agent collaboration is valuable not because there are “more models,” but because duties are specialized and contexts are isolated.
- Coordinator: decomposes work, orders dependencies, assigns tasks, and tracks progress. Output is a structured task graph, not a prose checklist.
- Executor: makes concrete changes in an isolated workspace. Context is narrow and deep: only the owned module and its conventions.
- Verifier: runs tests, inspects diffs, and challenges results. Permissions are read-only or tightly limited writes.
- Aggregator: merges results and writes change notes plus residual risk.
A core rule is separate execution from verification. The same agent writing code and judging it correct introduces confirmation bias; an independent verifier supplies an adversarial view. Stronger reasoning models fit planning, architecture, and review—work that needs long thinking and multi-round checks. Lighter models handle well-bounded mechanical edits. That split follows cost as much as capability.
Parallel workflows: isolate, partition, merge
Parallelism is not free. Design concentrates on three points.
Workspace isolation. Each executor gets its own branch or containerized directory so filesystems and dependencies do not collide.
Partition by write set. Split first on modification boundaries, not features. Overlapping write sets must run serially or merge into one task. Read-heavy research can scale in parallel.
# Sketch: schedule by write sets and dependenciestasks = [Task(id="t1", writes={"api/schema.py"}, deps=[]),Task(id="t2", writes={"api/handler.py"}, deps=["t1"]),Task(id="t3", writes={"docs/usage.md"}, deps=[]), # no write-set overlap with t1/t2]def schedule(tasks, max_parallel=4):done, running, results = set(), set(), {}while len(done) < len(tasks):ready = [t for t in tasksif t.id not in done and t.id not in runningand set(t.deps) <= done]for t in ready[: max_parallel - len(running)]:running.add(t.id)results[t.id] = run_in_isolated_workspace(t)for tid in list(running):if results.get(tid, {}).get("status") == "verified":done.add(tid); running.discard(tid)return merge(results)
Conflict detection and fallback. Before merge, compare write-set intersections. Conflicts go back to the coordinator for serial re-execution. Schedule critical-path work first; non-critical failures can degrade instead of blocking the whole job.
Human in the loop and observability
Long tasks must be interruptible. Sensible intervention points: scope confirmation, course correction, conflict arbitration, and final acceptance. The UI should show each executor’s live progress, diff previews, and verification reports so people can correct cheaply.
On the engineering side, log every tool call, command, and verification result, with alerts and traces for a replayable trail. Metrics should cover completion rate, first-pass rate, average repair rounds, human intervention rate, and time/compute cost. Evaluation sets should come from real repositories with automatically checkable acceptance criteria—otherwise you cannot tell “actually finished” from “said finished.”
Security boundaries still apply: run in sandboxes or containers, restrict writable paths and command allowlists, open network access only as needed, and inject secrets through controlled credentials rather than the model context.
Common anti-patterns
- Over-parallelism: grains too fine and write sets overlapping; merge cost exceeds the gain.
- Weak verifiers: text comparison only is not verification.
- Ungoverned context: dumping full history every turn raises cost and noise together.
- No checkpoints: failure cannot return to a known-good state; the whole job restarts.
- No termination: no budget or step cap, so the task diverges forever.
Closing
Gains on long-horizon work come from model reasoning and systems engineering. Role split addresses overloaded duties; isolated workspaces make parallelism safe; automated verification supplies trust; observability supplies control. With all four, agents deliver runnable, inspectable, acceptable artifacts—not just prose. These workflows are still evolving: whether decomposition is accurate and whether parallelism collides still depends on the task’s structure and the quality of the workflow design.
