From Q&A to Execution: Technical Architecture and Practices for Multi-Agent Collaboration
Large language model usage is shifting from single-turn Q&A toward agentic execution, where systems receive a goal, plan steps, call external tools, and correct course along the way. This article explains the paradigm shift, breaks down the core building blocks of multi-agent systems—task decomposition, role assignment, parallel execution, state sharing, and quality control—and provides a platform-agnostic Python orchestration skeleton demonstrating dependency handling, concurrency limits, and retry logic. It also discusses when multi-agent architectures are worth their added cost in tokens and latency.
Introduction
The way large language models are used is changing. Early applications centered on single-turn or multi-turn Q&A: the user asks a question, the model answers, and humans handle decomposition, execution, and verification of the results. As models improve at long-context processing, tool calling, and planning, an increasing number of scenarios require the model to accept a goal, plan its own steps, invoke external tools, and adjust course during execution. Such systems are commonly known as Agent systems.
Understanding this shift helps you decide which business scenarios are suitable for agents, and what engineering capabilities need to be added once you introduce them.
1. From Q&A to Execution: A Paradigm Shift
The Q&A model maps one interaction to one output, with humans at the center of the process and the model responsible only for local text generation. The execution model takes a goal as input and handles task decomposition, step scheduling, and result aggregation internally. The differences show up in three areas:
- Interaction granularity: from sentence-by-sentence instructions to phased goals.
- Responsibility boundaries: the model takes on decisions for intermediate steps, while humans shift to setting constraints and validating final results.
- Failure modes: in Q&A, an error usually means an inaccurate sentence; in execution tasks, an error can lead to files being modified incorrectly, bad data being written, or a pipeline breaking—so additional validation and rollback designs are required.
In short, as applications move from Q&A to execution, the technical focus shifts from “how well does it generate” to “can the process run to completion in a controllable way.”
2. Basic Concepts of Multi-Agent Collaboration
Multi-agent collaboration means multiple agents with different responsibilities jointly complete a task. Each agent typically consists of four elements: a role definition (system instructions), an available toolset, input/output conventions, and a communication mechanism with other agents. An Orchestrator is responsible for decomposing tasks, dispatching work, and aggregating results.
Compared with a single agent, the multi-agent structure offers three main advantages:
- Context isolation: each subtask carries only the necessary information, reducing interference from irrelevant content on model judgment.
- Parallel progress: independent subtasks can run simultaneously, reducing total time.
- Clear responsibilities: different roles can have separate permissions and evaluation criteria, making problems easier to locate.
The costs are just as clear. More calls mean higher token consumption and latency; information passed between agents can be distorted; and upstream errors get amplified along the chain. Whether to adopt a multi-agent structure should therefore depend on whether the task can be cleanly decomposed—not on treating it as the default option.
3. Task Decomposition: Turning Goals into Executable Subtasks
Task decomposition is the starting point of the whole system. A well-formed subtask must meet three conditions:
- Clear inputs and outputs, so downstream tasks can consume its results directly;
- Clear boundaries, with no reliance on implicit state from other unfinished subtasks;
- A verifiable completion criterion.
Decomposition usually involves two steps. First, the orchestrator generates a plan based on the goal, listing subtasks and their dependencies. Second, the plan undergoes structural validation—for example, checking for circular dependencies or subtasks missing output definitions. Dependencies can be represented as a directed acyclic graph (DAG), where nodes without prerequisite dependencies can run in parallel. Circular dependencies make related tasks impossible to start and must be detected before execution.
Take “writing API documentation for an internal tool and generating test cases” as an example. The decomposition might be: extract the list of APIs, write descriptions for each API, generate test cases, and verify consistency between the documentation and the test cases. “Extract the API list” is a common prerequisite for both “write descriptions” and “generate test cases,” so those two can run in parallel; “verify consistency” can only start after both are complete.
4. Role Assignment and Parallel Execution
Roles should be defined around “the professional judgment required,” not set arbitrarily. Common roles include:
- Retrieval roles: gathering materials and reading structured data;
- Writing roles: producing body text, code, or report sections;
- Review roles: checking consistency, formatting, and compliance;
- Aggregation roles: consolidating subtask results into the final deliverable.
Three things require attention when running tasks in parallel:
- Concurrency limits: cap the number of simultaneously running agents to avoid triggering model service rate limits and resource contention.
- Timeouts and retries: set a timeout for each subtask, retry with a backoff strategy on failure, and mark it as failed and report after exceeding the retry limit.
- Idempotency: any step that writes to an external system must guarantee that repeated execution does not produce duplicate data.
5. State Sharing and Context Management
In multi-agent systems, state management largely determines collaboration quality. It is advisable to manage shared state and local context separately. Shared state should hold only the plan, the structured results of each subtask, and status flags; local context should hold only the inputs needed for that subtask. This approach controls token costs and reduces mutual interference between agents.
Structured output is key. Downstream agents should read data with defined fields, not free-form text. For example, you can require every subtask result to include three fields—status, content, and evidence—and the aggregation role reads only these fields, refusing to proceed when any field is missing.
6. Quality Control and Human Oversight
Multi-agent outputs need validation before being passed to the next step. Common practices include:
- Rule-based validation: format, length, required fields, numeric ranges, and the like can be checked programmatically at the lowest cost.
- Cross-checking: an independent review role verifies whether key conclusions are supported by evidence. The review role should use prompts and inputs different from those of the generating role.
- Sampled human review: keep a human confirmation step for high-risk results, and periodically sample results that passed validation to check whether the validation rules themselves are effective.
For steps that modify data, send messages, or publish content, human confirmation points should be set up. The system should be read-only by default, with write actions requiring explicit authorization and a complete operation log for post-hoc auditing.
7. Engineering Implementation Example
The following code is a platform-agnostic orchestration skeleton demonstrating the basic logic of dependency waiting, concurrency limits, timeout retries, and result collection. Here, call_model is an abstract wrapper around any large language model API and needs to be implemented for your actual environment.
```python
import asyncio
from dataclasses import dataclass, field
from typing import Optional
@dataclass
class SubTask:
name: str
role: str
prompt: str
depends_on: list[str] = field(default_factory=list)
result: Optional[str] = None
status: str = “pending”
async def call_model(role: str, prompt: str) -> str:
# Placeholder implementation: replace with an actual model callawait asyncio.sleep(0.1)return f"[{role}] processed: {prompt[:30]}"
async def run_task(task: SubTask, tasks: dict[str, SubTask], sem: asyncio.Semaphore):
# Wait for all prerequisite tasks; fail immediately if any prerequisite failedfor dep in task.depends_on:while tasks[dep].status not in ("done", "failed"):await asyncio.sleep(0.05)if tasks[dep].status == "failed":task.status = "failed"return# Concurrency is capped by the semaphore; timeout and exponential backoff retries are handled hereasync with sem:for attempt in range(3):try:task.result = await asyncio.wait_for(call_model(task.role, task.prompt), timeout=60)task.status = "done"returnexcept Exception:await asyncio.sleep(2 ** attempt)task.status = "failed"
async def orchestrate(tasks: list[SubTask], max_concurrency: int = 4):
index = {t.name: t for t in tasks}
sem = asyncio.Semaphore(max_concurrency)
await asyncio.gather(*(run_task(t, index, sem) for t in tasks))
return {t.name: (t.status, t.result) for t in tasks}
if name == “main“:
plan = [
SubTask(“extract”, “retrieval”, “Extract the list of APIs”),
SubTask(“describe”, “writing”, “Write descriptions for each API”, [“extract”]),
SubTask(“testcase”, “writing”, “Generate test cases”, [“extract”]),
SubTask(“review”, “review”, “Verify consistency between docs and test cases”, [“describe”, “testcase”]),
]
print(asyncio.run(orchestrate(plan)))
