Why We Built a Multi-Agent Brain Instead of a Single Chatbot
A single agent juggling requirements, database design, frontend architecture, and QA produces mediocre results at every stage. We built six specialized agents with isolated contexts and a MessageBus that prevents context pollution.
The Problem We Found
We started HubAI with a single agent. One system prompt, one context window, one model call that handled everything — from parsing requirements to designing the database to generating frontend components.
It worked for demos. It failed at scale.
The failure mode was subtle. The agent did not crash or produce errors. It produced mediocre output everywhere. Database schemas would be reasonable but not optimized. Frontend components would work but ignore the entity relationships defined in the backend. QA checks were superficial because the agent’s context was already overloaded with generation artifacts.
We profiled the single-agent architecture and found three compounding problems:
- Context bleed — Database design decisions contaminated frontend generation. The agent would “remember” a MongoDB index strategy while trying to lay out a React form, wasting attention on irrelevant tokens.
- Attention fracture — With requirements, schemas, component trees, and validation rules all in one context, the model spread its attention too thin. No single domain got the focus it deserved.
- No recovery — When one phase produced suboptimal output, it polluted every subsequent phase. There was no way to isolate a mistake to one domain.
A single agent cannot be a requirements analyst, database architect, frontend designer, code generator, and QA engineer simultaneously. Humans do not work that way, and AI should not either.
How Chat-Based Tools Handle This
Most chat-based tools use a single agent with a single context window. Some add a “planning” step, but it is cosmetic — the same context window handles planning and execution, so the planning tokens compete with execution tokens for attention.
The fundamental issue is that chat-based tools treat code generation as a conversation — a linear sequence of messages between a human and a model. But enterprise code generation is not a conversation. It is an orchestrated pipeline with distinct phases, each requiring specialized knowledge and isolated focus.
How We Solved It
We replaced the single agent with a multi-agent architecture built on the Orchestrator-Worker pattern.
Six Specialized Agents
Each agent in HubAI has a single responsibility and an isolated context window:
┌──────────────────────────────────────────────────┐
│ Orchestrator Agent │
│ Analyzes task → Creates plan → Spawns workers │
│ Synthesizes results → Decides next steps │
└────────────┬──────────────┬──────────────────────┘
│ │
┌────────▼────┐ ┌──────▼───────┐
│ Requirement │ │ Database │
│ Agent │ │ Architect │
│ ~8K tokens │ │ ~8K tokens │
└──────┬──────┘ └──────┬───────┘
│ │
┌──────▼──────┐ ┌──────▼───────┐
│ Frontend │ │ QA │
│ Architect │ │ Agent │
│ ~8K tokens │ │ validation │
└──────┬──────┘ └──────────────┘
│
┌──────▼──────┐
│ Code │
│ Generator │
│ 0 LLM tkns │ ← deterministic templates
└─────────────┘
- Orchestrator Agent — Analyzes the task, creates an execution plan through the
PlanningModule, spawns specialized agents, and synthesizes their results. It decides the strategy; workers execute. - Requirement Agent — Parses project briefs, extracts entity definitions, identifies relationships, and produces a structured requirements document.
- Database Architect — Takes the requirements document and designs the database schema — collections, fields, indexes, validation rules, relationships.
- Frontend Architect — Consumes the database schema and designs the frontend — page layouts, component trees, form configurations, data flow.
- QA Agent — Validates every artifact against quality standards. This is not a post-hoc check — it is an integral gate in the pipeline.
- Code Generator — Takes validated schemas and renders production code through Handlebars templates. This agent uses zero LLM tokens — it is purely deterministic.
MessageBus: Communication Without Context Pollution
The critical architectural decision was how agents communicate. The naive approach — passing one agent’s full context to the next — recreates the single-agent problem at a larger scale.
HubAI uses a MessageBus for inter-agent communication. Agents exchange structured messages with defined schemas, not raw context. When the Database Architect sends its output to the Frontend Architect, it sends a condensed, structured representation of the schema — not the full design conversation.
This prevents the “game of telephone” that degrades output in naive multi-agent setups. Each agent receives exactly the information it needs, in the format it expects, with no noise from upstream processing.
ExecutionEngine: Parallel When Possible, Sequential When Required
Not every phase depends on the previous one. The ExecutionEngine analyzes the dependency graph and runs independent phases in parallel:
- Phases with no dependencies run concurrently — significant latency reduction
- Dependent phases wait for their prerequisites
- Progress tracking and cancellation are built in
- Failed phases can be retried without re-running the entire pipeline
Scaling Effort to Complexity
Not every generation task needs all six agents. HubAI scales its effort to match the query:
- Simple task (single entity, basic CRUD) — 1-2 agents, 3-10 tool calls
- Medium task (multiple entities, relationships) — 3-4 agents, 10-15 tool calls each
- Complex task (full project scaffold, dozens of entities) — All agents with parallelized execution
This scaling is embedded in the orchestrator’s planning logic, not hardcoded. The orchestrator evaluates the task complexity and decides how many agents to spawn and what each one should focus on.
Why Multi-Agent Outperforms Single-Agent
Multi-agent architectures provide two fundamental advantages:
Compression — Multiple context windows process different domains simultaneously. The Database Architect reasons about indexing strategies while the Frontend Architect reasons about component hierarchies. Both operate with full attention on their domain, then compress their output into condensed summaries for the orchestrator.
Separation of concerns — Each agent has distinct tools, prompts, and trajectories. The Database Architect has tools for schema validation and index optimization. The Frontend Architect has tools for component analysis and layout planning. No agent is overloaded with tools it does not need.
The token math tells the story:
| Architecture | Tokens Used | Quality Profile |
|---|---|---|
| Single agent | 50K-200K+ (all in one window) | Degrades as context fills |
| Multi-agent (HubAI) | ~8K per agent (isolated) | Constant per agent |
A single agent with 200K tokens of context has worse effective intelligence than six agents with 8K tokens each, because the signal-to-noise ratio in each agent’s window is dramatically higher.
The Key Insight
Multi-agent is not about using more AI. It is about using AI more precisely. Google’s Agent2Agent protocol, announced in April, validated what we had already learned: agents need structured communication protocols, not shared context dumps. Each agent gets a clean context window, a focused task, and specialized tools. The orchestrator ensures they work together without stepping on each other.
The MessageBus is the critical enabler. Without structured inter-agent communication, multi-agent systems devolve into a more expensive version of single-agent chaos. With it, each agent operates at peak effectiveness while the system as a whole produces enterprise-grade output.
One agent cannot do everything well. Six specialized agents, each excelling at one thing, orchestrated by a coordinator that ensures they work in concert — that is how you build AI systems that scale.