2. The 5-Layer Multi-Agent AI Pipeline
In-depth breakdown of the 5-layer manufacturing process, prompt engineering v2.1.0, and 6Cs automated quality auditing.
Asynchronous Pipeline Lifecycle
How background jobs are scheduled, executed, checkpointed, and streamed to the client without timing out.
Requirements generation is an intensive process requiring 60–180 seconds of multi-agent reasoning. SRA orchestrates this using an asynchronous event-driven model:
- Job Dispatch:
queueService.jscomputes an MD5 hash of the input for idempotency, creates anAnalysisrecord with statusPENDING, and publishes the job to Upstash QStash. - Worker Ingestion: QStash delivers the webhook to
POST /api/worker/process.workerController.jsatomically transitions the record toIN_PROGRESSviaupdateManyto guarantee that duplicate webhook deliveries are safely ignored. - Live SSE Streaming: The client connects to
GET /api/analyze/:id/stream. Progress events (stage transitions, agent thoughts, section completions) are published to Redis Pub/Sub and pushed to the browser via Server-Sent Events (SSE). - Serverless Budget Checkpointing (`pipelineBudget.js`): On serverless environments (e.g. Vercel 300s limit), the pipeline checks execution budgets before heavy stages. If time runs low, it checkpoints intermediate state to PostgreSQL and re-enqueues itself to continue seamlessly without data loss.
The 5 Sequential Layers
| Layer | Name | Primary Responsibility | Agent / Service |
|---|---|---|---|
| Layer 1 | Intake Mapping | Translates unstructured vision into canonical JSON draft schema | ProductOwnerAgent |
| Layer 2 | Multi-Agent System | Parallel business value modeling, architecture design, and document synthesis | ProductOwner, Architect, Developer |
| Layer 3 | Objective Review | Automated 6Cs quality audit and RAG faithfulness scoring | ReviewerAgent, CriticAgent, evalService |
| Layer 4 | Refinement Hub | Human-in-the-loop chat iterations, version branching, and self-healing diagrams | ChatAgent, DiagramRepair |
| Layer 5 | Knowledge Indexing | Semantic shredding and vector embedding into pgvector for reuse | ragService, embeddingService |
Layer 2: Multi-Agent System (MAS v2.1.0)
Coordinated role separation between Product Owner, Systems Architect, and Developer Agents using the v2.1.0 Gold Standard prompt registry.
Role-Based Agent Choreography
Rather than asking a single LLM to write an entire specification, SRA utilizes specialized agents with distinct domain responsibilities:
1. Product Owner Agent
- Decomposes business goals, identifies primary/secondary user classes, defines operating environments, and establishes boundary constraints.
- Formulates feature candidate lists and stimulus/response sequences.
2. Systems Architect Agent
- Determines external interface requirements (User Interfaces, Hardware Interfaces, Software APIs, and Communication Protocols).
- Generates Mermaid architecture diagrams (Sequence Diagrams, Flowcharts, Entity-Relationship Models).
- Injects relevant historical design patterns retrieved from the vector knowledge base.
3. Developer Agent
- Synthesizes the formal normative requirement statements ("The system shall...").
- Formats each section according to the target standard's exact schema descriptor with intentional rate-limit cooldown throttles.
Layer 3: Objective Review & 6Cs Quality Audit
Algorithmic grading against the 6Cs quality standard and LLM-as-a-judge faithfulness scoring.
The 6Cs Quality Standard
Every generated specification is audited by the CriticAgent against six core software engineering metrics:
- Clarity: Unambiguous phrasing free of vague qualifiers ("fast", "user-friendly", "robust").
- Completeness: Compulsory coverage of all required sections, external interfaces, and non-functional constraints.
- Conciseness: High information density without fluff or duplicate requirement definitions.
- Consistency: Zero internal contradictions between functional rules, database entities, and user roles.
- Correctness: Valid Mermaid diagram syntax, proper RFC 2119 normative verbs ("SHALL", "SHOULD"), and accurate schema types.
- Context: Alignment with user-provided domain knowledge and historical organizational standards.
Reflection & Surgical Repair Loop:
- If the aggregate quality score falls below 85/100, the
ReviewerAgentflags specific deficient sections. - The pipeline enters a reflection pass (maximum 2 passes) where the Developer Agent performs surgical refinement only on the flagged sections, preserving the rest of the document intact.
Help us improve the SRA enterprise documentation.