Lesson 6 of 6·11 min read

Production Multi-Agent System

Theory is important — but now let's build a complete multi-agent system. In this chapter, you'll create a research-analyze-report pipeline with quality gates, human review, and everything needed for production.

The Pipeline Overview

Trigger (Webhook/Schedule)
    │
    ▼
┌──────────────┐     ┌──────────────┐     ┌──────────────┐
│  Research     │────▶│  Analyze     │────▶│  Report      │
│  Agent        │     │  Agent       │     │  Agent       │
└──────────────┘     └──────────────┘     └──────────────┘
    │                     │                     │
    ▼                     ▼                     ▼
Quality Gate 1       Quality Gate 2       Quality Gate 3
(≥ 3 sources?)       (Confidence ≥ 80?)    (Score ≥ 85?)
    │                     │                     │
    ▼                     ▼                     ▼
  Pass/Retry           Pass/Retry         Pass/Human Review

Step 1: Research Agent

The Research Agent collects information from multiple sources.

n8n Workflow Configuration

NodeTypeConfiguration
TriggerWebhookPOST /pipeline/start
Research PromptSet NodeSystem prompt + topic from trigger
LLM CallOpenAI / Anthropicmodel: gpt-4o, max_tokens: 2000
Parse OutputFunctionJSON validation + schema check
Quality GateIF Nodefindings.length ≥ 3 AND confidence ≥ 70
Save StatePostgreSQLINSERT INTO agent_state

Quality Gate 1: Research Completeness

{
  "conditions": {
    "all": [
      { "field": "findings_count", "operator": "gte", "value": 3 },
      { "field": "confidence", "operator": "gte", "value": 70 },
      { "field": "knowledge_gaps", "operator": "lte_length", "value": 2 }
    ]
  },
  "on_fail": "retry_with_expanded_scope",
  "max_retries": 2
}

Step 2: Analyze Agent

The Analyze Agent processes research results and extracts key insights.

Prompt Structure

System: You are an analysis specialist. Based on the research data:
1. Identify the 3-5 most important findings
2. Evaluate trends and patterns
3. Create a SWOT analysis if applicable
4. Provide action recommendations with priority (high/medium/low)

Input: {{ $json.research_findings }}
Output format: JSON with { insights: [], trends: [], recommendations: [] }

Quality Gate 2: Analysis Depth

CriterionThresholdAction on Failure
Insights found≥ 3Retry with hint
Confidence score≥ 80Retry with more context
Recommendations≥ 1 per insightRetry with explicit instruction
JSON validationValid schemaImmediate retry

Step 3: Report Agent

The Report Agent creates the final report from research and analysis.

Template Integration

# {{ topic }} — Analysis Report

**Created:** {{ date }}
**Confidence:** {{ overall_confidence }}%
**Sources:** {{ sources_count }}

## Executive Summary
{{ executive_summary }}

## Key Insights
{{ insights_formatted }}

## Action Recommendations
{{ recommendations_table }}

## Appendix: Source List
{{ sources_list }}

Human Review Integration

Not every report should be auto-published:

Report Agent Output
    │
    ▼
┌──────────────┐
│ Quality Gate  │
│ Score ≥ 85?   │
└──────┬───────┘
       │
  ┌────┴────┐
  ▼         ▼
 YES        NO
  │         │
  ▼         ▼
Auto-      Slack message
Publish    to reviewer
           │
           ▼
        Human Review
        (Approve/Edit/Reject)

Slack Integration for Review

ActionWorkflow
ApproveReport is published
EditReport goes back to Report Agent with feedback
RejectPipeline is stopped, DLQ entry

Production Checklist

Before taking your multi-agent pipeline live:

AreaChecklist
Error HandlingRetries configured, Fallback agents defined, Circuit breaker active
MonitoringExecution logging, Latency metrics, Cost tracking
Quality GatesAt least 1 gate per agent, Human review for final output
SecurityAPI keys in credentials (not in workflow), Rate limits set
ScalingConcurrency limits per agent, Queue for load spikes
DocumentationAgent roles documented, Input/output contracts defined

Practical tip: Build the pipeline incrementally: First only the Research Agent with quality gate. Then add the Analyze Agent. Then the Report Agent. Each stage is tested and verified individually before the next one is added. Plan 2 weeks for a robust production deploy.

📝

Quiz

Question 1 of 3

Was ist der Zweck von Quality Gates in einer Multi-Agent-Pipeline?