DEV Community

Bishwadeep Talukdar
Bishwadeep Talukdar

Posted on

Building a Multi-Agent AI System with Self-Healing Error Recovery

Building single-prompt LLM pipelines often hits a ceiling when dealing with complex, multi-step workflows. When handling large-scale data gathering, verification, dynamic extraction, and visualization, breaking down the problem into a specialized multi-agent architecture is the key to reliability and accuracy.

In this post, I’ll walk through an autonomous multi-agent framework led by a Master Orchestrator that coordinates sub-agents, manages fallbacks, and continuously learns from failure paths.

Architecture Overview
Instead of relying on a single large prompt, the system divides responsibilities among dedicated specialized agents, supervised by a Central Master Agent.
┌───────────────────────────────┐
│ MASTER ORCHESTRATOR │
│ (State, Looping, Recovery) │
└───────────────┬───────────────┘

┌──────────────┬────────────┼────────────┬──────────────┐
▼ ▼ ▼ ▼ ▼
┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────┐
│ Agent 1 │ │ Agent 2 │ │ Agent 3 │ │ Agent 4 │ │ Agent 5 │
│ Research │─►│ Verify & │─►│ Extract │─►│ Structure │─►│ Visualise │
│ Data │ │ Collect │ │ KPIs │ │ & Audit │ │ Output │
└───────────┘ └───────────┘ └─────┬─────┘ └───────────┘ └───────────┘

┌────────────┴────────────┐
▼ ▼
┌─────────────┐ ┌─────────────┐
│ Sub-Agent A │ │ Sub-Agent B │
│ (PDF/Text) │ │ (Data/Table)│
└─────────────┘ └─────────────┘
Detailed Agent Breakdown

  1. Research & Discovery Agent (Agent 1) Role: Initial intelligence gathering.

Task: Searches web sources, registries, and public data to pull background context and identify core information about the target organization.

  1. Verification & Document Retrieval Agent (Agent 2) Role: Fact-checking & sourcing.

Task: Validates the initial findings from Agent 1 and locates the required primary documents, filings, and public reports needed for deeper downstream extraction.

  1. Extraction & KPI Processor (Agent 3 + Sub-Agents) Role: Multi-format data extraction.

Task: Parses dense reports to collect specific metrics, targets, and KPIs.

Sub-Agent Network: Handles different document formats dynamically:

Unstructured Text Sub-Agents: Process narrative reports, PDFs, and disclosures.

Structured/Tabular Sub-Agents: Handle spreadsheets, structured tables, and numerical disclosures using format-specific algorithms.

  1. Structuring & Reconciliation Agent (Agent 4) Role: Data audit & alignment.

Task: Aggregates inputs from all extraction sub-agents, cleans and normalizes the schema, and cross-verifies output values against the raw report metrics to prevent hallucination.

  1. Visualization & Reporting Agent (Agent 5) Role: Final presentation layer.

Task: Transforms structured data into visual dashboards, key summary charts, and human-readable output reports.

The Core Engine: Master Orchestrator Logic
The backbone of this system is the Master Agent, which operates as a state machine managing control flow, retry loops, and fault tolerance.

Self-Healing Logic Implementation
Here is a simplified Python representation of how the Master Orchestrator bypasses blocked tasks, logs error paths, and applies learned resolution pathways:

Python
class MasterOrchestrator:
def init(self):
self.solution_memory = {} # Failure signature -> Recovery Strategy

def execute_pipeline(self, tasks):
    results = {}
    for task in tasks:
        try:
            # Attempt execution
            results[task.id] = task.agent.run(task.input_data)
        except Exception as error:
            print(f"[ALERT] Task {task.id} failed: {error}")

            # Check if a known pathway exists in memory
            failure_sig = f"{task.agent.name}:{type(error).__name__}"
            if failure_sig in self.solution_memory:
                print(f"[RECOVERY] Applying known fix for {failure_sig}")
                recovery_fn = self.solution_memory[failure_sig]
                results[task.id] = recovery_fn(task)
            else:
                # Ping log, bypass non-critical task, and store new recovery path
                print(f"[BYPASS] Bypassing non-critical task {task.id} to complete pipeline.")
                self.learn_solution_pathway(failure_sig, task)
                results[task.id] = None  # Or partial fallback data

    return results

def learn_solution_pathway(self, failure_sig, task):
    # Store resolution pattern for future pipeline runs
    self.solution_memory[failure_sig] = lambda t: t.agent.run_fallback(t.input_data)
Enter fullscreen mode Exit fullscreen mode

Key Lessons & Takeaways
Specialization Beats Generalization: Smaller, highly specialized prompts and agents produce significantly higher accuracy than a single monolithic agent.

Format-Specific Handlers: Using dedicated sub-agents tailored to specific file types (PDF vs. CSV/JSON) dramatically improves extraction accuracy for complex KPIs.

Resilience by Design: Building self-healing, non-blocking fallback mechanisms ensures the system can run autonomously at scale without getting stuck on single-point edge cases.

What Do You Think?

Top comments (0)