When I started building Busara AI, I knew that the future of AI wasn't a single monolithic model doing everything — it was a team of specialized agents, each an expert in its domain, working together in a coordinated pipeline. What I didn't fully appreciate was how challenging it would be to orchestrate 50 agents with complex dependencies, handle failures gracefully, and do it all fast enough to deliver results in under 30 seconds.
This article is the technical deep-dive into how I built the Busara AI v7.0 multi-agent framework — the architecture, the algorithms, and the hard-won lessons.
The Problem: Why Multi-Agent?
Most AI applications today use a single LLM to handle everything: understanding the request, retrieving relevant data, reasoning about the answer, and generating the response. This works for simple tasks but breaks down for complex, multi-dimensional analysis. A single model can't be an expert in everything. When you ask it to forecast time series data AND detect anomalies AND infer causal relationships AND generate code, the quality of each individual task degrades.
The multi-agent approach is different. Instead of one model trying to do everything, you have 50 specialized agents, each focused on a specific domain. The Data Profiling agent knows everything about statistical summaries. The Anomaly Ensemble agent is an expert in Z-score, IQR, and EWMA detection. The Holt-Winters Forecast agent lives and breathes triple exponential smoothing. Each agent does one thing extremely well, and the results are combined into a comprehensive analysis.
The Architecture: DAG-Based Orchestration
The core of the framework is a Directed Acyclic Graph (DAG) that defines the execution order and dependencies between agents. Agents are organized into 7 stages, and within each stage, agents run in parallel. The DAG ensures that an agent only executes after all its dependencies have completed.
Here's the stage layout:
- Stage 0 — Ingest (10 agents): Data ingestion, schema inference, profiling, PII detection, quality scoring
- Stage 1 — Engineer (10 agents): Median imputation, mode imputation, standard scaling, feature engineering, type coercion
- Stage 2 — Detect (10 agents): Anomaly ensemble (Z+IQR+EWMA), Isolation Forest, K-Means, DBSCAN, GMM, fraud detection, sentiment, correlation, stationarity, seasonality
- Stage 3 — Forecast (4 agents): Holt-Winters, ARIMA, moving average, anomaly forecasting
- Stage 4 — Infer (8 agents): OLS regression, causal inference, feature importance, SHAP, Auto-ML, benchmark, knowledge graph, Africa market intel
- Stage 5 — Report (8 agents): Insight generator, narrative composer, code generator, visualization, synthetic data, reflection, real-time alert, orchestrator
Kahn's Topological Sort
To determine the execution order, I implemented Kahn's algorithm for topological sorting. The algorithm works by repeatedly finding agents with no unmet dependencies (in-degree of zero), executing them, and removing their outgoing edges. This naturally groups agents into stages that can run in parallel.
function topologicalSort(agents: Map<string, AgentMetadata>): string[][] {
const inDegree = new Map<string, number>();
const adjList = new Map<string, string[]>();
// Build graph
for (const [id, meta] of agents) {
inDegree.set(id, meta.dependencies.length);
for (const dep of meta.dependencies) {
if (!adjList.has(dep)) adjList.set(dep, []);
adjList.get(dep)!.push(id);
}
}
// Kahn's algorithm — process in layers (stages)
const stages: string[][] = [];
let current = Array.from(agents.keys()).filter(id => inDegree.get(id) === 0);
while (current.length > 0) {
stages.push(current);
const next: string[] = [];
for (const id of current) {
for (const neighbor of adjList.get(id) ?? []) {
const newDegree = inDegree.get(neighbor)! - 1;
inDegree.set(neighbor, newDegree);
if (newDegree === 0) next.push(neighbor);
}
}
current = next;
}
return stages;
}
Circuit Breakers
In a 50-agent pipeline, failures are inevitable. An API might time out, a dataset might be malformed, or an algorithm might hit an edge case. Without protection, a single failure can cascade through the entire pipeline. I implemented circuit breakers for each agent, following the pattern from Michael Nygard's "Release It!".
After 3 consecutive failures, the circuit "opens" — subsequent calls to that agent are skipped for 60 seconds, returning a "circuit_breaker_open" status. After the reset timeout, the circuit goes "half_open" — one trial call is allowed. If it succeeds, the circuit closes; if it fails, it reopens. This prevents the pipeline from repeatedly invoking a broken agent and wasting time.
Smart Caching (O(1) LRU)
Many agents produce the same output for the same input. Rather than re-computing, I implemented a Least Recently Used (LRU) cache with O(1) operations using JavaScript's Map data structure. The Map maintains insertion order, so the oldest entry is always the first one iterated. When the cache is full, we delete the first entry (oldest) in O(1) time.
Real-Time Progress Broadcasting
One of the most important features for user experience is transparency. When a user uploads a dataset, they don't want to stare at a spinner for 30 seconds — they want to see what's happening. I implemented Server-Sent Events (SSE) to stream progress updates in real time. As each agent starts, runs, and completes, the server pushes an event to the client, which updates the DAG visualizer with status colors and timing information.
Results
The 50-agent pipeline processes a typical dataset (1,000 rows × 10 columns) in under 30 seconds. The parallel execution within stages means that the total time is roughly the sum of the longest agent in each stage, not the sum of all agents. With 50 agents across 7 stages, the effective parallelism ratio is about 7x — meaning the pipeline runs 7 times faster than sequential execution would.
But the real result isn't speed — it's depth. In 30 seconds, a user gets anomaly detection, forecasting, causal inference, clustering, regression, code generation, and a narrative report. That's the power of multi-agent orchestration: not one model trying to do everything, but 50 experts working together.