Multi-Agent Pipeline → Structured Output
Validated by: BA Assistant | View App
Template
# Multi-Agent Pipeline Template
class MultiAgentPipeline:
def __init__(self, agents: List[Agent], orchestrator: Orchestrator):
self.agents = agents
self.orchestrator = orchestrator
def run(self, input: RawInput) -> StructuredOutput:
context = Context(input=input)
for agent in self.agents:
result = agent.execute(context)
context.add_result(agent.name, result)
return self.orchestrator.format(context)
# Agent Definition
class Agent:
name: str
prompt_template: str
output_schema: Schema
tools: List[Tool]
def execute(self, context: Context) -> Result:
# 1. Build prompt from template + context
# 2. Call LLM with structured output enforcement
# 3. Validate against schema
# 4. Return typed result
pass
# Orchestrator
class Orchestrator:
def format(self, context: Context) -> StructuredOutput:
# Combine all agent outputs into final format
# Generate Mermaid diagrams
# Export: Markdown, Confluence, Notion, JSON
pass
BA Assistant Agent Config
| Agent | Role | Output | Tools |
|---|---|---|---|
| 01 Requirements | Extract & categorise | Func/Non-func/Tech constraints | LLM + Schema validation |
| 02 Backlog | User stories + AC | Prioritised, estimated stories | LLM + Estimation heuristics |
| 03 Architecture | System design | Services, DB, Queue, APIs | LLM + Architecture patterns KB |
| 04 Risk | Risk assessment | Tech/Business/Compliance risks | LLM + Risk framework |
| 05 Diagram | Mermaid generation | 5 diagram types | LLM + Mermaid validator |
Key Implementation Details
- Context passing: Each agent receives full context from previous agents
- Structured output: Pydantic/JSON Schema enforcement on every agent
- Mermaid validation: Syntax check + render test before output
- Human-in-loop: Checkpoint after Agent 1 & 3 for review
- Streaming: Token-by-token UI updates via Streamlit callbacks
Future Apps Using This Pattern
📈 Stock Research Agent
Agents: Thesis Builder → Financial Analyst → Risk Assessor → Valuation → Diagram (charts) → Research Report
📋 Compliance Audit Generator
Agents: Regulation Parser → Control Mapper → Gap Analyzer → Evidence Collector → Diagram (control matrix) → Audit Report
🔄 Sprint Retrospective Synthesizer
Agents: Feedback Clusterer → Theme Extractor → Action Planner → Owner Assigner → Diagram (flow) → Retro Doc