Lesson 12: Multi-Agent Workflows
"Collaboration beats solo performance."
⚠️ Correction: an earlier version of this lesson claimed this workflow is orchestrated by LangGraph. It is not. The functions below (
run_analysis_agent,run_reply_agent,run_reviewer_agent) are called as plain sequential Python function calls fromrouters/agents.py'srun_multi_agent_email_workflowendpoint — there is noStateGraph, no conditional routing, no LangGraph import anywhere inservices/multi_agent_email_service.py. The only LangGraph usage in this backend is the Corrective RAG pipeline — see Lesson 08e and Lesson 17.
Email Workflow
Multi-agent system: Analysis → Tasks → Reply → Review
Flow
Analysis Agent
def run_analysis_agent(email_text: str) -> dict:
return analyze_email(email_text)Output: summary, intent, priority, deadline, action_items
Task Agent
for item in analysis["action_items"]:
task = Task(title=item, priority=analysis["priority"])
db.add(task)Reply Agent
def run_reply_agent(email_text: str, analysis: dict) -> str:
prompt = f"Write reply for: {analysis['intent']}"
return openai_call(prompt)Reviewer Agent
def run_reviewer_agent(email, analysis, reply, tasks) -> dict:
return {
"approved": True/False,
"quality_score": 0.0-1.0,
"issues": [...],
"recommendation": "..."
}State Management
Each step tracked in database:
workflow_run = WorkflowRun(workflow_name="email_workflow")
workflow_run.steps.append(
WorkflowStep(step_name="analysis", status="success")
)Error Handling
If any step fails, entire workflow logged:
try:
analysis = run_analysis_agent(email)
reply = run_reply_agent(email, analysis)
review = run_reviewer_agent(...)
except Exception as e:
workflow_run.status = "failed"
workflow_run.error_message = str(e)Key Takeaways
🎯 Multi-agent workflows enable complex operations
🎯 Each agent specializes in one task
🎯 State tracked in WorkflowRun and WorkflowStep rows, not in a LangGraph state object
🎯 Orchestration here is sequential Python — analysis → tasks → reply → review, no branching. Contrast with the actual LangGraph-based, branching Corrective RAG pipeline in Lesson 08e
Module 4 · API & Business Logic