How to Build a 24/7 Multi-Agent System: A Complete Engineering Guide
This article explains how to build a 24/7 multi-agent system that runs unattended, handles parallel task chains, and recovers from failures. It covers the five-layer architecture (scheduling, agents, memory, tools, observability), model selection criteria, context management techniques, state machines with checkpoints, stability safeguards, cost control, and a four-week rollout plan. The focus is on using engineering practices rather than relying on a single model to keep long-running agent workflows stable and recoverable.
1. Why 24/7 Agent Fleets Are a New Engineering Challenge
Single-turn conversational LLM applications can no longer meet real business needs. What enterprises actually need is an agent system that runs continuously without supervision, processes multiple task chains in parallel, and self-recovers when failures occur. This kind of system is commonly referred to as a Multi-Agent System.
Compared with one-off question answering, long-running systems place three higher demands on models and engineering frameworks:
- Long-task stability: Tasks may run for tens of minutes or even hours, and a single inference hiccup must not bring the whole system down.
- No forgetting over long contexts: Constraints, terminology, and delivery formats passed across turns must always stay in effect.
- Unbroken task chains: Subtasks depend on one another, where earlier outputs become later inputs; if the chain breaks, it must be recoverable.
It is worth stressing that these capabilities are not exclusive features of any single model. They are agent engineering problems widely discussed across the industry. This article takes a neutral perspective on how to solve them with general technical approaches.
2. Overall Architecture: From One Model to a Fleet
A practical fleet-style architecture is typically divided into five layers:
- Scheduling layer: Handles task decomposition, dispatch, prioritization, and retries.
- Agent layer: Split by role into research, planning, execution, review, delivery, and so on.
- Memory layer: Short-term session memory + mid-term task memory + long-term knowledge base.
- Tool layer: Common tools such as retrieval, code execution, file read/write, and message notifications.
- Observability layer: Logging services, monitoring and alerting, and trace tracking.
A sample role definition can be written as a structured configuration so the scheduler can read it uniformly:
agents:- name: researcher # Collects materials and verifies factsmodel: local-llmmax_steps: 40- name: planner # Breaks down tasks and assigns subtasksmodel: local-llmmax_steps: 25- name: executor # Produces and executes outputsmodel: local-llmmax_steps: 60- name: reviewer # Performs quality checks and decides on reworkmodel: local-llmmax_steps: 20
The key point is: agents communicate through structured messages, not free-text conversation. Structured messages (such as JSON) can significantly reduce the probability of a broken chain.
3. Model Selection: Verifiable Capability Dimensions Instead of Brand Narratives
The core takeaway of the original experience is that “a certain open-source model performed beyond expectations on long tasks.” Abstracted out, selection should focus on four verifiable dimensions:
- Instruction following: Whether it can reliably output the agreed format (such as strict JSON).
- Long-context retention: Whether it can still reference early constraints under tens of thousands of tokens of input.
- Tool-calling reliability: Whether function-call arguments are valid and whether required fields are omitted.
- Multi-turn consistency: Whether role drift or goal drift occurs across turns.
It is recommended to build a small evaluation set on your own business samples (for example, 50–100 real tasks) and make decisions based on pass rates rather than subjective impressions. The evaluation can rely on container platforms and object storage on Baidu AI Cloud to achieve environment isolation and sample management, which is a general engineering practice.
4. Context Management: Four Safeguards Against Forgetting in Long Tasks
- Layered memory: Write “immutable constraints” (delivery format, compliance requirements) into the system prompt as read-only; write “process information” into task memory files.
- Rolling summaries: Generate a compressed summary every N turns to replace verbose early conversations.
- Externalized state: Persist task state to structured files or a database, and have the model read only the fragment it currently needs.
- Retrieval augmentation: Retrieve historical details on demand instead of stuffing all history into the context.
Sample code (pseudo-implementation):
def build_prompt(task_id, step):constraints = load_readonly_constraints() # Immutable constraintssummary = memory.rolling_summary(task_id) # Rolling summarystate = store.get_state(task_id) # Externalized statehits = retriever.search(state["focus"], k=5) # On-demand retrievalreturn f"{constraints}\n{summary}\n{state}\n{hits}\nCurrent step:{step}"
5. Keeping Task Chains Intact: State Machine + Checkpoints
Do not let the model “remember where it got to”; let the system remember instead. An explicit state machine is recommended:
INIT -> RESEARCH -> PLAN -> EXECUTE -> REVIEW -> DELIVER -> DONE^ | |+---- RETRY <----------+
Write a checkpoint before each state transition, containing an input summary, output paths, and failure reasons. This way, even if the process restarts, it can continue from the most recent checkpoint, achieving true unattended operation.
6. Stability Safeguards: Let the Fleet Get Back on Its Feet
- Idempotent design: Repeated execution of the same subtask produces no side effects.
- Tiered retries: Retry recoverable errors; roll back to the previous state and request review for logic errors.
- Circuit breaking and rate limiting: Pause a role when the tool-call failure rate exceeds a threshold to avoid cascading failures.
- Human gates: Keep manual confirmation nodes for high-risk actions such as external sending or writing to production.
7. Observability and Cost Control
The cost of long-running systems comes mainly from tokens and tool calls. Recommendations:
- Use a logging service to collect the input, output, and latency of each inference in a unified way;
- Use monitoring and alerting to set thresholds for “task backlog, failure rate, average steps”;
- Tier model calls: use small-parameter models for simple subtasks and large-parameter models for complex reasoning;
- Cache repeated retrieval results to reduce unnecessary calls.
8. Rollout Roadmap
- Week 1: Define roles and the structured message protocol, and get a single chain running end to end.
- Week 2: Integrate layered memory and checkpoints, and verify restart recovery.
- Week 3: Add the review and rework mechanism, and build an evaluation set.
- Week 4: Complete observability and alerting, and roll out gradually to real business.
9. Conclusion
The essence of a 24/7 agent fleet is not “switching to a stronger model,” but using engineering means to cage uncertainty: structured communication guarantees the chain, layered memory guarantees no forgetting, the state machine and checkpoints guarantee recoverability, and the observability system guarantees operability. Model capabilities can be replaced as the ecosystem evolves, but this engineering skeleton is a long-term asset. If you need elastic compute and managed environments, you can build on general capabilities such as the container platform, object storage, logging service, and monitoring and alerting on Baidu AI Cloud, keeping the architecture neutral and portable.
