Skip to content
Module 4 · API & Business LogicIntermediate2 min read · 311 words

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 from routers/agents.py's run_multi_agent_email_workflow endpoint — there is no StateGraph, no conditional routing, no LangGraph import anywhere in services/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

Rendering diagram…

Analysis Agent

python
def run_analysis_agent(email_text: str) -> dict:
    return analyze_email(email_text)

Output: summary, intent, priority, deadline, action_items

Task Agent

python
for item in analysis["action_items"]:
    task = Task(title=item, priority=analysis["priority"])
    db.add(task)

Reply Agent

python
def run_reply_agent(email_text: str, analysis: dict) -> str:
    prompt = f"Write reply for: {analysis['intent']}"
    return openai_call(prompt)

Reviewer Agent

python
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:

python
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:

python
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

👉 Lesson 13: AI Agents →

Module 4 · API & Business Logic