Beyond Single Prompts
Every chapter so far has focused on getting the most out of a single AI interaction. This chapter is about something fundamentally different: chaining AI agents together so that the output of one becomes the input of the next, automating entire development workflows.
This is where vibe coding starts to look less like "AI-assisted development" and more like "directing an AI development team."
---
What Is a Multi-Agent Workflow?
A multi-agent workflow is a pipeline where multiple AI calls — each potentially with different models, different tools, and different roles — execute in sequence or in parallel, with each step building on the previous.
Example: A 4-agent code review pipeline:
- Analyst Agent reads your diff and identifies what changed
- Security Agent checks the changes for vulnerabilities
- Performance Agent checks for N+1 queries, missing indexes
- Synthesis Agent combines all findings into a structured report
---
Designing an Agent Pipeline
Before writing any code, define your pipeline as a flow diagram:
Key design decisions:
- Sequential vs parallel? Agents that depend on each other run sequentially. Agents that are independent can run in parallel with
Promise.all. - What does each agent produce? Define the output schema of each agent before writing prompts. Structured JSON outputs make chaining reliable.
- What context does each agent need? Each agent should receive only the context it needs, not the full conversation history.
Implementation: A Code Review Pipeline
```javascript // agent-pipeline.js import OpenAI from 'openai'; const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
async function callAgent(systemPrompt, userContent, model = 'gpt-4o') { const response = await client.chat.completions.create({ model, messages: [
Get advanced blueprint resources
Enter your email to receive technical blueprints, checklists, and visual configurations accompanying this chapter.
No spam. Unsubscribe any time.
{ role: 'system', content: systemPrompt }, { role: 'user', content: userContent } ], response_format: { type: 'json_object' }, }); return JSON.parse(response.choices[0].message.content); }
async function runCodeReviewPipeline(codeDiff) { // Step 1: Analyst — understand what changed const analysis = await callAgent( 'You are a code analyst. Analyze this diff and output JSON: { summary: string, files_changed: string[], change_type: "feature" | "bugfix" | "refactor" | "security" }', codeDiff );
// Steps 2 & 3: Run security and performance checks in parallel
const [securityReport, performanceReport] = await Promise.all([
callAgent(
'You are a security engineer. Review this code change for security vulnerabilities. Output JSON: { issues: [{ severity: "critical"|"high"|"medium"|"low", description: string, line_reference: string, recommendation: string }] }',
Change summary: ${analysis.summary}
Full diff:
${codeDiff}
),
callAgent(
'You are a performance engineer. Review this code change for performance problems. Output JSON: { issues: [{ type: string, impact: "high"|"medium"|"low", description: string, recommendation: string }] }',
Change summary: ${analysis.summary}
Full diff: ${codeDiff} ) ]);
// Step 4: Synthesis — combine all findings
const finalReport = await callAgent(
'You are a senior engineering lead. Synthesize these review findings into a clear, actionable code review. Output JSON: { overall_verdict: "approve"|"request_changes"|"needs_discussion", key_findings: string[], must_fix: string[], nice_to_fix: string[], approved_as_is: boolean }',
Analysis: ${JSON.stringify(analysis)}
Security: ${JSON.stringify(securityReport)}
Performance: ${JSON.stringify(performanceReport)}
);
return { analysis, securityReport, performanceReport, finalReport }; }
User story → [Spec Agent: write technical spec] → [Schema Agent: design DB schema] → [Build Agent: implement feature] → [Test Agent: write tests] Bug description + relevant code → [Diagnose Agent: identify root cause] → [Fix Agent: implement fix] → [Verify Agent: check fix doesn't break other things] Blog post URL → [Extract Agent: summarise key points] → [LinkedIn Agent: write LinkedIn post] → [Twitter Agent: write thread] → [SEO Agent: suggest internal links] ```---
Cost Management for Agent Pipelines
Multi-agent pipelines multiply your token usage. Use a tiered model strategy:
- Simple extraction/classification agents: Gemini Flash ($0.60/1M output) — fast, cheap, capable
- Medium complexity analysis agents: Claude Haiku or GPT-4o Mini
- Complex reasoning agents (synthesis, architecture): Claude Fable 5 or GPT-5.6 Sol