News Froggy
newsfroggy
HomeTechReviewProgrammingGamesHow ToAboutContacts
newsfroggy

Your daily source for the latest technology news, startup insights, and innovation trends.

More

  • About Us
  • Contact
  • Privacy Policy
  • Terms of Service

Categories

  • Tech
  • Review
  • Programming
  • Games
  • How To

© 2026 News Froggy. All rights reserved.

TwitterFacebook
Programming

Build Your First Multi-Agent AI System with Python and LangGraph

Building Multi-Agent AI Systems: Plain Python vs. LangGraph As developers, we often tackle complex tasks by breaking them down into smaller, manageable pieces. This principle applies equally to AI systems, especially

PublishedJuly 15, 2026
Reading Time11 min
Build Your First Multi-Agent AI System with Python and LangGraph

Building Multi-Agent AI Systems: Plain Python vs. LangGraph

As developers, we often tackle complex tasks by breaking them down into smaller, manageable pieces. This principle applies equally to AI systems, especially when working with Large Language Models (LLMs). While a single, sophisticated prompt can sometimes achieve remarkable results, it can quickly become unwieldy, difficult to maintain, and challenging for smaller, locally run models to execute reliably. This is where multi-agent AI systems shine.

In this article, we'll explore how to construct a multi-agent system in Python, first using a minimalist, framework-free approach, and then by leveraging the LangGraph library. Our goal is to illustrate the core concepts and highlight the advantages an orchestration framework like LangGraph brings for more intricate workflows, all while running our agents locally with Ollama and Qwen to avoid API costs.

What is a Multi-Agent System?

At its core, a multi-agent AI system is a collection of specialized AI agents that collaborate to accomplish a larger objective. Instead of burdening a single LLM with a broad, complex prompt, the workload is distributed among several agents. Each agent is designed with:

  • A focused, specific responsibility.
  • Its own tailored prompt and set of instructions.
  • A defined position within the overall workflow.

This division of labor allows each agent to have a simpler, more precise objective, making its prompt easier for the underlying LLM to follow consistently. Multi-agent systems are particularly effective when a task naturally segregates into distinct roles or sequential steps, such as planning, drafting, reviewing, or applying different specialized prompts to various parts of a process. If a single agent can handle a task efficiently and reliably with a clear prompt, adding more agents might introduce unnecessary complexity or latency.

Our Use Case: A Study Guide Generator

To demonstrate these concepts, we'll build a simple AI-powered study guide generator. Given a topic, our system will produce a structured study guide complete with an outline, detailed notes, and review questions. A single-agent approach might use a prompt like this:

plaintext Create a beginner-friendly study guide for this topic: {topic} The output should have exactly these sections:

  1. Outline
  • Break the topic into 3 short study sections
  1. Notes
  • Write short, clear study notes for each section
  • Keep the explanations concise and easy to understand
  1. Review Questions
  • Write 3 short review questions based on the notes Return the result in clean Markdown.

This monolithic prompt places a significant cognitive load on a smaller local model. Our multi-agent solution, however, will split this into three specialized agents:

  1. Planner: Breaks the given topic into logical study sections.
  2. Teacher: Crafts concise study notes for each section.
  3. Quiz Writer: Generates relevant review questions based on the notes.

We'll implement this workflow in two ways: first using standard Python for explicit coordination, and then with LangGraph, which models the workflow as a directed graph with nodes, edges, and shared state.

Getting Started: Installation

To follow along, you'll need Ollama installed and a Qwen model pulled. Ollama enables running LLMs locally, eliminating API costs.

First, pull the model:

bash ollama pull qwen3.5:4b

Next, set up your Python environment and install the necessary libraries:

bash pthon3 -m venv venv source venv/bin/activate pip install langchain-ollama langgraph

Simple Python Implementation

Our first approach uses plain Python functions to coordinate the LLM calls. Each agent is simply a dedicated function with a focused system prompt. The build_study_guide function orchestrates these calls sequentially, passing the output of one agent as input to the next.

python import time from langchain_ollama import ChatOllama

Local Ollama model used by all three agents.

MODEL = ChatOllama(model="qwen3.5:4b", temperature=0)

def ask(system: str, user: str) -> str: """Run one LLM call with a system prompt and user input.""" response = MODEL.invoke([ {"role": "system", "content": system}, {"role": "user", "content": user}, ]) return response.content

def run_agent(name: str, system: str, user: str) -> str: """Helper that logs how long each agent takes.""" print(f"Calling agent {name}...") start = time.time() result = ask(system, user) print(f"Finished {name} in {time.time() - start:.1f}s") return result

Agent 1: create a short outline

def planner_agent(topic: str) -> str: return run_agent( "planner_agent", "Break this topic into 3 short study sections.", topic, )

Agent 2: turn the outline into notes

def teacher_agent(topic: str, outline: str) -> str: return run_agent( "teacher_agent", "Write short beginner-friendly notes using the outline. Keep it concise.", f"Topic: {topic} Outline: {outline}", )

Agent 3: write review questions from the notes

def quiz_agent(topic: str, notes: str) -> str: return run_agent( "quiz_agent", "Write 3 short review questions based on the notes.", f"Topic: {topic} Notes: {notes}", )

def build_study_guide(topic: str) -> str: """Run all three agents in sequence and combine their output.""" outline = planner_agent(topic) notes = teacher_agent(topic, outline) quiz = quiz_agent(topic, notes) return ( f"# Study Guide: {topic} " f"## Outline {outline} " f"## Notes {notes} " f"## Review Questions {quiz} " )

if name == "main": print("Warming up model...") MODEL.invoke("Say ready.") print("Model ready. ") topic = input("Enter a study topic: ").strip() print(" " + build_study_guide(topic))

To run this, save it as study_guide_v1.py and execute:

bash python study_guide_v1.py

This version demonstrates that a multi-agent system can be remarkably simple, requiring no external frameworks for basic sequential orchestration.

LangGraph Version: Nodes and Edges

For more complex workflows involving shared state, conditional branching, or loops, an orchestration framework becomes invaluable. LangGraph allows us to define our multi-agent system as a graph, where:

  • Each specialized agent becomes a node.
  • Data shared between agents is managed in a graph state.
  • The execution order is explicitly defined by edges.

python from typing import TypedDict import time from langchain_ollama import ChatOllama from langgraph.graph import StateGraph, START, END

Local Ollama model used by all nodes.

MODEL = ChatOllama(model="qwen3.5:4b", temperature=0)

Shared state passed between nodes.

class StudyState(TypedDict): topic: str outline: str notes: str quiz: str

def ask(system: str, user: str) -> str: response = MODEL.invoke([ {"role": "system", "content": system}, {"role": "user", "content": user}, ]) return response.content

def run_node(name: str, system: str, user: str) -> str: print(f"Calling node {name}...") start = time.time() result = ask(system, user) print(f"Finished {name} in {time.time() - start:.1f}s") return result

Node 1: create the outline

def planner(state: StudyState) -> dict: return { "outline": run_node( "planner", "Break this topic into 3 short study sections.", state["topic"], ) }

Node 2: write notes from the outline

def teacher(state: StudyState) -> dict: return { "notes": run_node( "teacher", "Write short beginner-friendly notes using the outline. Keep it concise.", f"Topic: {state['topic']} Outline: {state['outline']}", ) }

Node 3: write review questions from the notes

def quiz_writer(state: StudyState) -> dict: return { "quiz": run_node( "quiz_writer", "Write 3 short review questions based on the notes.", f"Topic: {state['topic']} Notes: {state['notes']}", ) }

def build_graph(): graph = StateGraph(StudyState) # Add the nodes graph.add_node("planner", planner) graph.add_node("teacher", teacher) graph.add_node("quiz_writer", quiz_writer) # Define the order of execution graph.add_edge(START, "planner") graph.add_edge("planner", "teacher") graph.add_edge("teacher", "quiz_writer") graph.add_edge("quiz_writer", END) return graph.compile()

if name == "main": print("Warming up model...") MODEL.invoke("Say ready.") print("Model ready. ") app = build_graph() topic = input("Enter a study topic: ").strip() result = app.invoke({ "topic": topic, "outline": "", "notes": "", "quiz": "", }) print( f"

Study Guide: {topic}

" f"## Outline {result['outline']} " f"## Notes {result['notes']} " f"## Review Questions {result['quiz']} " )

Save this as study_guide_v2.py and run:

bash python study_guide_v2.py

The LangGraph version achieves the same outcome but provides a structured, visualizable representation of the workflow. Each node updates the shared StudyState dictionary, and the graph defines how this state flows from one node to the next.

Comparison and Tradeoffs

Both implementations generate a study guide using a multi-agent approach. The simple Python version is ideal for straightforward, linear workflows where explicit function calls are sufficient. It offers minimal overhead and maximum control, often being the most practical starting point.

LangGraph, however, excels when the workflow complexity increases. Its explicit graph structure, shared state management, and ability to define conditional edges and loops make it a superior choice for dynamic and sophisticated agent coordination. While introducing a framework adds a layer of abstraction, it significantly enhances maintainability and scalability for evolving multi-agent systems.

Common Multi-Agent Patterns

Beyond the sequential pipeline demonstrated here, several other multi-agent patterns are common:

  • Parallel Specialists: Multiple agents independently process the same input, and their outputs are subsequently merged. Ideal for non-dependent subtasks.
  • Orchestrator–Subagent: A high-level agent decomposes a task, delegates parts to specialized subagents, and then integrates their results. Useful for coordinating many specialized agents.
  • Supervisor / Router: An agent determines which specialist should handle an incoming request, based on input type or context.
  • Human-in-the-loop: An agent drafts content or performs an action, but human review or approval is required before the workflow proceeds. Crucial for sensitive or user-facing applications.
  • Review / Refinement loop: One agent produces an output, and another agent (or the same one recursively) checks or improves it, enhancing quality at the cost of potential latency.

Conclusion

Building multi-agent AI systems, even simple ones, significantly improves the manageability and output quality of LLM applications, particularly with smaller, locally hosted models. By breaking down complex prompts into focused agent responsibilities, we create more robust and adaptable systems.

Whether you opt for the simplicity of plain Python or the structured power of LangGraph depends on your workflow's complexity. For a fixed, linear sequence, Python is often best. For dynamic flows, shared state, and advanced coordination, LangGraph provides the necessary tools. Experiment by extending this example—perhaps add a 'rewriter' node for simpler language, a 'reviewer' to validate quiz questions, or conditional logic for different topic complexities. Happy tinkering!

FAQ

Q: When should I choose plain Python over LangGraph for a multi-agent system?

A: Plain Python is ideal for lightweight, fixed-sequence, linear workflows where each agent's output directly feeds into the next, and explicit function calls offer sufficient coordination. It provides simplicity and avoids framework overhead.

Q: What are the key components of a multi-agent system built with LangGraph?

A: In LangGraph, the key components are Nodes (representing individual agents or steps), a StateGraph (which defines the shared state passed between nodes), and Edges (which define the flow and order of execution between nodes).

Q: How do agents communicate or share information between steps in the provided examples?

A: In the simple Python version, agents communicate by directly passing return values from one function (agent) as arguments to the next function. In the LangGraph version, agents communicate by reading from and writing to a shared StudyState dictionary, which is passed between nodes.

#programming#freeCodeCamp#AI#multi-agent#ollama#ai agentsMore

Related articles

Google Play's New Stance on 501(c)(6) Donations: AnkiDroid's Challenge
Programming
Hacker NewsSep 1

Google Play's New Stance on 501(c)(6) Donations: AnkiDroid's Challenge

For developers deeply embedded in the open-source ecosystem, the challenge of sustainable funding is ever-present. Many projects rely on community donations, often facilitated by fiscal hosts that simplify legal and

Cold Cases & Data Integrity: Lessons from a Decades-Old Verdict
Programming
Hacker NewsSep 1

Cold Cases & Data Integrity: Lessons from a Decades-Old Verdict

As software developers, we often deal with complex systems, legacy codebases, and the relentless pursuit of bugs that have evaded detection for years. The recent conviction in the 1996 murder of rapper Tupac Shakur

Kalshi Bans George Santos for Life Over Investigation Non-Compliance
Tech
Washington Post TechnologySep 1

Kalshi Bans George Santos for Life Over Investigation Non-Compliance

Prediction market platform Kalshi has issued its first-ever lifetime ban to former Republican congressman George Santos. The move, announced Monday, comes after Santos reportedly failed to cooperate with an internal company investigation. This adds another chapter to the controversies surrounding the former House member, who was expelled from Congress in 2023.

Android 17 QPR2 Beta 4: Status Bar Refresh - A Welcome, If Late
Review
Android AuthorityAug 31

Android 17 QPR2 Beta 4: Status Bar Refresh - A Welcome, If Late

The Android 17 QPR2 Beta 4 introduces new, long-awaited status bar customization options, allowing users to hide system and notification icons. While not groundbreaking compared to other Android OEMs, this feature significantly enhances the user experience for Pixel device owners by providing a cleaner, more personalized interface.

ai: Musk’s faster path to more gas turbines comes with pollution
Tech
TechCrunch AIAug 30

ai: Musk’s faster path to more gas turbines comes with pollution

Elon Musk's SpaceX is building a secret Texas foundry to produce gas turbine blades, aiming to accelerate AI data center power by 18 months. This addresses a critical energy bottleneck, but faces environmental backlash over pollution and health risks from gas turbines.

Caterpillar Leverages Mining Automation Expertise for AI Deployment
Tech
TechCrunch AIAug 30

Caterpillar Leverages Mining Automation Expertise for AI Deployment

Industrial giant Caterpillar is pioneering a pragmatic approach to artificial intelligence deployment, drawing upon decades of experience automating challenging physical environments like mining sites. The company's

Back to Newsroom

Stay ahead of the curve

Get the latest technology insights delivered to your inbox every morning.