Multi-Agent Collaboration Architecture: Running Multiple Bots on a Single Instance
This article explains how to build a multi-agent collaboration runtime on top of a single service instance that serves multiple chat bot identities in the same group. It covers a five-layer architecture (adapter, router, orchestrator, capability, and observability layers), message normalization and routing rules, role definitions with capability declarations and boundaries, three collaboration patterns, an explicit task state machine, observability and governance practices, and common pitfalls to avoid. Readers will learn what determines feasibility: clear routing, stateful orchestration, isolated context, and end-to-end traceability.
1. Problem Background and Goals
A common enterprise requirement is to maintain a single agent service while connecting multiple instant messaging group bots, adding them to the same group, and letting one “supervisor” role handle task decomposition and progress tracking while other roles handle content creation, research, data organization, and similar work. This is not about “spinning up several more bots.” It is about building a multi-agent collaboration runtime on top of a single service instance.
The desired outcome breaks down into four verifiable goals:
- One service instance hosting multiple bot identities, so you do not deploy a separate service per role;
- All bots in the same group, with shared messages and context but clear role boundaries;
- An explicit dispatcher role responsible for task distribution, status aggregation, and escalation;
- Full traceability, so any output can be traced to who generated it, under which task, and based on what context.
2. Layered Architecture
Split the system into five layers that communicate through explicit contracts, keeping business logic decoupled from integration details.
- Adapter layer: handles event callbacks from the messaging platform, message send/receive, identity verification, deduplication, and rate limiting;
- Router layer: classifies group messages as “broadcast,” “directed,” or “system command” and decides how each is handled;
- Orchestrator layer: maintains task objects, the role capability table, and collaboration policies; this is the core of the system;
- Capability layer: wraps shared capabilities such as model calls, retrieval, file and object storage, and scheduled jobs;
- Observability layer: logs, metrics, distributed tracing, and audit trails.
A sample directory structure:
agent-runtime/adapters/ # platform integration and event normalizationrouter/ # message classification and routing policiesorchestrator/ # task orchestration and role schedulingcapabilities/ # model, retrieval, storage capability wrappersobservability/ # logs, metrics, tracing
3. Multiple Bot Identities and Message Routing
The key to hosting multiple identities on one instance is maintaining separate credentials and identity identifiers per bot in the adapter layer, and normalizing raw platform events into a standard internal message:
{"bot_id": "bot_editor","group_id": "g_1024","sender": "u_88","msg_type": "text","content": "Please add today's topic suggestions","timestamp": 1700000000}
The router layer decides based on three rules:
- Directed first: when an explicit role prefix or a mention of a specific bot appears, the message enters a point-to-point processing path;
- Broadcast fallback: group messages with no clear target go to the supervisor role, which decides whether to split them into subtasks;
- Command isolation: management commands (pause, resume, check progress) never enter the creation path and are handled directly by the orchestrator layer.
Two engineering details must be handled. First, platform callbacks may be delivered more than once, so deduplicate idempotently using a unique message identifier. Second, group traffic can be concurrent, so serialize per group or apply bounded concurrency to prevent the same task from being triggered repeatedly.
4. Role Orchestration and Collaboration Policies
Define roles through “capability declaration plus boundary constraints” rather than hard-coded prompts:
roles:supervisor:capabilities: [task_split, progress_track, quality_gate]boundary: does not produce final content directlycreator:capabilities: [topic_generation, drafting]boundary: does not change task priorityresearcher:capabilities: [retrieval, summarization]boundary: provides facts and citations only
Choose a collaboration pattern from the simplest to the most complex:
- Serial pipeline: the supervisor decomposes the task and passes it through “retrieval → creation → review”; low implementation cost and stable results;
- Parallel fan-out and aggregation: multiple roles work on independent subtasks simultaneously, and the supervisor merges the results; suitable for batch topic generation or writing by section;
- Review loop: outputs that fail the quality gate are sent back for rework; set a maximum loop count to prevent infinite resource consumption.
For context management, separate task-level context (goal, constraints, acceptance criteria) from group-level shared context (confirmed facts, index of completed outputs). The former is destroyed with the task lifecycle; the latter is summarized, compressed, and retained long term to avoid unbounded context growth.
5. Task Flow and State Machine
Give every task an explicit state machine; this is the key to avoiding “bots waiting on each other”:
CREATED -> ASSIGNED -> IN_PROGRESS -> REVIEWING -> DONE| |+--> FAILED <--+
State transitions are written by the orchestrator layer only. Any role may submit a “result plus suggested state” but cannot change state itself. Tasks that time out enter a retry queue; past a threshold, the supervisor role escalates in the group with the task identifier and failure reason so a human can step in.
6. Observability and Governance
Multi-role systems are far harder to troubleshoot than a single bot, so instrument them up front:
- Trace identifier: one unique trace ID per user request, carried through all subtasks;
- Structured logs: record role, task, duration, token usage, and retry count;
- Metrics dashboard: track task success rate, average flow duration, and loop count distribution;
- Audit trail: store outputs linked to prompt versions and model versions to meet traceability requirements.
For elasticity and stability, deploy the runtime on a container platform, use a message queue to buffer tasks, use object storage for outputs, and use a logging service plus monitoring alerts for observability. These are standard categories of cloud capabilities.
7. Common Pitfalls and Implementation Advice
- Too many roles raise the cost of consensus: start with three or four roles, validate the flow, then expand;
- Context bleed: contexts of different tasks must be physically isolated, or outputs will contaminate each other;
- No quality gate: a supervisor that only distributes and never validates leaves output quality uncontrolled;
- Ignoring cost limits: set call and duration budgets per group and per task;
- Blurred permission boundaries: manage access credentials, task data, and outputs by least privilege with tiered access.
In summary, the feasibility of single-instance multi-bot collaboration does not depend on how many bots you connect. It depends on whether routing is clear, orchestration is stateful, context is isolated, and the process is observable. Implement the layers above step by step to build a stable, extensible multi-agent collaboration mechanism in your own environment.
