Building a 24/7 Multi-Agent Development Legion: Architecture, Roles, and Quality Gates
This article explains how to build a multi-agent system that runs a complete software delivery pipeline around the clock. It covers why a single agent struggles with end-to-end delivery, a four-layer architecture based on role separation and context isolation, ticket-driven collaboration with a state machine, artifact management, unattended scheduling with idempotency and cost controls, observability and quality gates, and a phased rollout plan with common pitfalls.
1. Why a Single Agent Cannot Handle the Full Delivery Pipeline
Agents are evolving from single-purpose Q&A tools into engineering components capable of executing long-running tasks. Many teams notice the same pattern in practice: when one agent handles a task from start to finish, output quality starts to degrade midway. There are three main reasons.
First, context expansion. A complete delivery pipeline covers requirement clarification, competitor and user research, product requirement definition, technology selection, coding, testing, and regression. The intermediate artifacts far exceed what a single session window can reasonably hold, so early constraints get diluted by later details.
Second, mixed responsibilities. The same model has to act as a demanding product owner and a rigorous tester. Switching roles causes judgment standards to drift, and self-review tends to become “letting yourself off the hook.”
Third, no auditable process. A single-agent run produces only one black-box trace. When something goes wrong, it is impossible to tell whether the cause was a misunderstanding of requirements, an interface design error, or insufficient test coverage.
The value of a multi-agent legion is that it addresses these three problems with context isolation, role specialization, and explicit processes. This is not about stacking model capabilities; it is a system architecture design problem.
2. Overall Architecture: Role Layers, Context Isolation, and a Message Bus
A practical development legion typically has four layers.
- Coordination layer: an orchestrator agent receives requirements from humans, breaks down tasks, dispatches tickets, aggregates results, and requests human confirmation at key checkpoints.
- Specialist layer: dedicated agents for market research, product definition, architecture design, development, and testing. Each maintains only its own context and artifacts.
- Support layer: a message queue or event bus, object storage for documents and code artifacts, logging, and monitoring with alerting.
- Runtime layer: a container platform hosts the agent runtimes, with scheduled triggers enabling unattended overnight execution.
The key design principle is “share artifacts, not contexts.” Agents do not pass long conversations to each other; they pass structured tickets and artifact references. An example structure:
{"ticket_id": "T-20260818-001","from": "orchestrator","to": "researcher","goal": "Propose the feature scope for competitor price monitoring","constraints": ["Use only publicly available information", "Conclusions must include supporting rationale"],"artifacts": {"input": "oss://agent-space/req/brief.md"},"deadline": "2026-08-18T23:00:00Z"}
The ticket is the only “official language” of the legion. The benefits: any failure can be replayed, and any artifact can be traced to a specific responsible role.
3. Role and Responsibility Design: Each Agent Owns Only Its Segment
A role definition must specify three things: input contract, output contract, and acceptance criteria. Using an e-commerce competitor price monitoring system as an example:
- Market research agent: takes a requirement summary as input and outputs target user profiles, a competitor feature list, and differentiation opportunities. Acceptance criterion: every conclusion must be labeled with its source type (public information, general industry knowledge, or hypothesis to be validated).
- Product definition agent: converts research conclusions into a requirement list, where each item has a priority and acceptance conditions. Unverifiable descriptions are not allowed.
- Architecture design agent: outputs module breakdown, data flows, rationale for storage choices, and failure mode analysis. Acceptance criterion: the design must include handling approaches for at least two types of exception paths.
- Development agent: implements module by module, follows a unified interface contract, and submits change notes and self-test records.
- Testing agent: generates test cases based on requirement acceptance conditions, covering normal flows, boundary values, and exception flows. It outputs a defect list rather than modifying code directly.
The last point is especially important: development and testing must be handled by different agents, and the testing agent should not have permission to modify business code. Otherwise the self-review mechanism is meaningless.
4. Collaboration Mechanism: State Machine Driven, Avoiding “Mutual Waiting”
The most common multi-agent failures are deadlocks and circular discussions. The solution is to model the process as an explicit state machine, with state transitions controlled solely by the orchestrator agent:
RECEIVED -> RESEARCH_DONE -> PRD_DONE -> DESIGN_DONE-> DEV_IN_PROGRESS -> TESTING -> DELIVEREDAny state --failure--> BLOCKED --human confirmation--> roll back to the corresponding upstream state
Three hard rules apply. First, every ticket must have a timeout; on timeout it is marked as failed and escalated. Second, the retry limit for the same module is two; beyond that, it is escalated to a human. Third, agents are not allowed to start open-ended free-form conversations; they can only respond in a structured way based on tickets and artifacts. These three rules eliminate most cases of “agents politely talking to each other all night with zero output.”
5. Context and Artifact Management: Reproducibility Is the Baseline
Assign each role an independent context space, and store artifacts in object storage using the ticket ID as a path prefix, forming a natural version directory. This yields three direct benefits: controllable context length, diffable artifacts, and replayable failures.
At the prompt level, each role’s system prompt should contain only three types of content: the role goal, output format constraints, and prohibited actions. Do not repeatedly stuff global background into every role’s context; let it read artifacts on demand. If external information retrieval is needed, wrap it in a unified retrieval service to avoid inconsistent standards across roles.
6. 24/7 Unattended Operation: Scheduling, Idempotency, and Cost Control
Overnight long runs require three engineering conditions.
- Scheduling: use scheduled jobs to trigger the pipeline in a fixed window, with task descriptions and parameters externalized as configuration for easy adjustment.
- Idempotency: each ticket carries a unique identifier, so repeated delivery produces no duplicate side effects; write operations must validate state before executing.
- Cost guardrails: set limits on model calls per task, total duration, and budget thresholds. When triggered, pause and alert.
Cost control is often overlooked, but it is often decisive in long pipelines. Practical approaches include: using more economical models for divergent stages such as research and testing, and more capable models for architecture and key reviews; caching and reusing repeated artifacts; running only tasks without human dependencies overnight, and concentrating confirmation checkpoints during the day.
7. Observability and Quality Gates
Connect logging and monitoring with alerting to the pipeline, and collect at least four metrics: stage duration, ticket success rate, retry counts, and invocation cost per delivery. Logs should record the ticket ID, role, input artifact references, and output summary, forming an end-to-end trace.
Quality gates should be automated: interface contract consistency checks, static checks, unit test pass rate, and requirement acceptance condition coverage. If any gate fails, the pipeline is set to blocked and a human is notified, rather than letting downstream roles “continue while sick.”
8. Rollout Roadmap and Common Pitfalls
A three-step rollout is recommended: first implement only the two stages from research to requirement definition to validate whether the ticket contract is clear; then add development and testing along with the gates; finally enable overnight unattended operation.
There are four common pitfalls: role granularity that is too fine, so communication overhead exceeds the benefits; inconsistent artifact formats that downstream roles cannot parse; missing human checkpoints, causing errors to be amplified overnight; and stuffing all background into every role’s context, which raises both cost and noise.
To reduce infrastructure overhead, you can use Baidu AI Cloud’s container platform to host the runtime, object storage to hold artifacts, a message queue to handle ticket flow, and logging and monitoring with alerting for observability, leaving attention for process design itself. The success of a multi-agent legion ultimately depends on contract design and the strictness of quality gates, not the number of roles.
