Every week, I review code from aspiring AI engineers trying to automate complex business processes with a single massive prompt. They stuff web search instructions, data-formatting rules, writing guidelines, and quality checks into one LLM call and then wonder why the model hallucinates halfway through. If you want to build an AI workflow automation system using multiple agents, you must stop treating a Large Language Model like an all-knowing oracle and start treating it like a specialized team member.
In real-world production environments, reliable automation comes from breaking a complex problem into smaller, deterministic steps handled by specialized agents. Today, I will walk you through how to architect and code an end-to-end multi-agent workflow in Python using LangGraph, Ollama, and free open-source tools without spending a single rupee or dollar on paid APIs.
AI Workflow Automation System Using Multiple Agents
To make this practical, we’ll build an automated Market Intelligence & Report Generation System. When you give the system a technology topic, four specialized agents collaborate to produce a verified executive brief:
- Research Agent (Parallel Node 1): Connects to the live web using the free DuckDuckGo search tool to gather the latest industry news and trends.
- Data Analyst Agent (Parallel Node 2): Runs simultaneously alongside the Research Agent, extracting structured adoption metrics, benchmarks, and growth risks.
- Writer Agent: Consumes the combined findings from the shared state to draft a cohesive, executive-ready business report—and revises it if rejected by quality assurance.
- Quality Assurance (QA) Agent: Audits the draft for length, structure, and factual grounding. If the draft falls short, the QA agent routes it back to the Writer Agent with actionable feedback.
Here is how the orchestration mechanisms work under the hood:

Step-by-Step Implementation with Python
Step 1: Set Up Your Zero-Cost Local Environment
We will use Ollama to run llama3.2 locally and duckduckgo-search for free web retrieval. Open your terminal, pull the model, and install the required Python packages:
ollama pull llama3.2
pip install langgraph langchain-ollama langchain-community duckduckgo-search
Step 2: Define the Shared State and Free Web Tool
First, we define our WorkflowState schema and wrap DuckDuckGo search inside a resilient tool function that gracefully catches network timeouts:
from typing import TypedDict, Optional
from langchain_ollama import ChatOllama
from langchain_community.tools import DuckDuckGoSearchRun
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.memory import MemorySaver
# Initialize local LLM via Ollama (100% free, zero API keys)
llm = ChatOllama(model="llama3.2", temperature=0.2)
search_tool = DuckDuckGoSearchRun()
class WorkflowState(TypedDict):
topic: str
research_data: Optional[str]
analysis_metrics: Optional[str]
draft_report: Optional[str]
qa_feedback: Optional[str]
qa_passed: Optional[bool]
revision_count: int
human_approved: Optional[bool]
final_output: Optional[str]
def safe_web_search(query: str) -> str:
"""Executes free web search with built-in error handling."""
try:
return search_tool.invoke(query)
except Exception as e:
return f"Fallback context (Search unavailable: {str(e)}). Rely on core domain knowledge."Prepare for your first AI/ML Interview
Multi-agent workflows look great on GitHub, until an interviewer asks you to whiteboard failure modes live. Learn the exact frameworks to clear technical rounds without freezing in Cracking Your First AI/ML Interview.
Step 3: Build the Specialized Agent Nodes
Next, we create the four agent functions plus the final publishing node:
def research_agent(state: WorkflowState) -> dict:
print("-> [Research Agent] Gathering live market intelligence...")
raw_results = safe_web_search(f"{state['topic']} latest industry trends news 2026")
prompt = (
f"Summarize the top 3 industry trends for '{state['topic']}' "
f"using this search data:\n{raw_results}"
)
response = llm.invoke(prompt)
return {"research_data": response.content}
def data_analyst_agent(state: WorkflowState) -> dict:
print("-> [Data Analyst Agent] Extracting quantitative benchmarks...")
raw_stats = safe_web_search(f"{state['topic']} market adoption statistics ROI benchmarks")
prompt = (
f"Extract 3 concrete adoption metrics, ROI benchmarks, and key operational risks "
f"for '{state['topic']}' from this data:\n{raw_stats}"
)
response = llm.invoke(prompt)
return {"analysis_metrics": response.content}
def writer_agent(state: WorkflowState) -> dict:
revisions = state.get("revision_count", 0)
print(f"-> [Writer Agent] Drafting executive brief (Attempt #{revisions + 1})...")
feedback_note = f"\nFix this QA feedback: {state.get('qa_feedback')}" if state.get("qa_feedback") else ""
prompt = (
f"Write a structured Executive Business Brief on '{state['topic']}'.\n"
f"Include sections: Executive Summary, Key Trends, Quantitative Metrics, and Action Plan.\n"
f"Research Insights:\n{state.get('research_data')}\n"
f"Analytical Benchmarks:\n{state.get('analysis_metrics')}\n"
f"{feedback_note}"
)
response = llm.invoke(prompt)
return {"draft_report": response.content, "revision_count": revisions + 1}
def qa_agent(state: WorkflowState) -> dict:
print("-> [QA Agent] Auditing draft quality and completeness...")
draft = state.get("draft_report", "")
if len(draft.split()) < 80:
return {
"qa_passed": False,
"qa_feedback": "Draft is too brief. Expand the Quantitative Metrics and Action Plan sections."
}
eval_prompt = (
f"Review this business brief for clarity and factual structure. "
f"Reply with 'PASS' if it is executive-ready, or 'FAIL: <reason>' if it needs work:\n\n{draft}"
)
verdict = llm.invoke(eval_prompt).content.strip()
passed = "PASS" in verdict.upper()
return {"qa_passed": passed, "qa_feedback": verdict}
def final_publisher_node(state: WorkflowState) -> dict:
print("-> [Publisher Node] Generating final verified output...")
if not state.get("human_approved"):
return {"final_output": "Workflow terminated: Report rejected by human reviewer."}
banner = "=" * 55
final_doc = f"{banner}\nVERIFIED EXECUTIVE REPORT: {state['topic'].upper()}\n{banner}\n\n{state['draft_report']}\n"
with open("verified_business_report.md", "w", encoding="utf-8") as f:
f.write(final_doc)
return {"final_output": final_doc}Notice how research_agent and data_analyst_agent only return the specific keys they update, allowing LangGraph to run them in parallel without state collisions.
Step 4: Wire Task Delegation, Parallel Edges, and Human Approval
Now we connect our nodes inside a StateGraph, configure the conditional QA routing function, and attach a MemorySaver checkpointer to enable the human-in-the-loop pause:
def qa_router(state: WorkflowState) -> str:
if state.get("qa_passed") or state.get("revision_count", 0) >= 2:
return "final_publisher"
print(" [Router] QA check failed. Routing back to Writer Agent...")
return "writer_agent"
builder = StateGraph(WorkflowState)
# Register nodes
builder.add_node("research_agent", research_agent)
builder.add_node("data_analyst_agent", data_analyst_agent)
builder.add_node("writer_agent", writer_agent)
builder.add_node("qa_agent", qa_agent)
builder.add_node("final_publisher", final_publisher_node)
# Fan-out: Run Research and Data Analysis in parallel from START
builder.add_edge(START, "research_agent")
builder.add_edge(START, "data_analyst_agent")
# Fan-in: Wait for both parallel agents before triggering Writer Agent
builder.add_edge(["research_agent", "data_analyst_agent"], "writer_agent")
# Sequential handoff to QA and conditional self-correction loop
builder.add_edge("writer_agent", "qa_agent")
builder.add_conditional_edges("qa_agent", qa_router)
builder.add_edge("final_publisher", END)
# Compile with MemorySaver and pause before final_publisher for Human Approval
memory = MemorySaver()
workflow_app = builder.compile(
checkpointer=memory,
interrupt_before=["final_publisher"]
)Step 5: Execute the Workflow with Human-in-the-Loop Sign-Off
Finally, we run the graph, inspect the draft at the human checkpoint, and resume execution to publish the report:
if __name__ == "__main__":
thread_config = {"configurable": {"thread_id": "enterprise_workflow_01"}}
initial_state = {
"topic": "Small Language Models in Edge AI",
"revision_count": 0
}
# Phase 1: Autonomous execution up to the Human Approval checkpoint
for _ in workflow_app.stream(initial_state, thread_config, stream_mode="values"):
pass
snapshot = workflow_app.get_state(thread_config)
print("\n--- HUMAN APPROVAL CHECKPOINT ---")
print(f"QA Verdict: {snapshot.values.get('qa_feedback')}")
print(f"Draft Preview:\n{snapshot.values.get('draft_report')[:350]}...\n")
# Simulate human sign-off (change to input() for interactive CLI use)
decision = "y"
workflow_app.update_state(thread_config, {"human_approved": decision.lower() == "y"})
# Phase 2: Resume workflow to generate final output
for event in workflow_app.stream(None, thread_config, stream_mode="values"):
if event.get("final_output"):
print(event["final_output"])The Takeaway
The biggest shift you can make in your AI engineering career right now is moving from prompt engineering to systems engineering. Anyone can copy a clever prompt into a chat interface, but companies hire engineers who design resilient architectures that handle bad data, recover from tool failures, and keep humans in control of high-stakes decisions.
Run this code on your local machine today, experiment by adding a fifth agent, like a compliance checker or a SQL database tool, and focus on mastering the orchestration layer. That is where the real value in AI lies.
I hope you liked this article on how to build an AI workflow automation system using multiple agents. If you’d like more tips on AI and machine learning, you’re welcome to follow me on Instagram.





