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

TCG Pocket Responds: A Much-Needed Pace Shift for Pokémon Fans
Games
PolygonOct 16

TCG Pocket Responds: A Much-Needed Pace Shift for Pokémon Fans

Pokémon TCG Pocket is rolling out a major update for its second anniversary, primarily addressing player concerns about overwhelming content releases by shifting to a six-week set schedule. This aims to curb player decline and improve overall engagement by giving trainers more time to collect and strategize. The update also adds new collection methods, improved deck-building features, and enhanced trading functionality.

Ditch Merge & Center: The Better Way to Align Text in Excel
How To
How-To GeekOct 16

Ditch Merge & Center: The Better Way to Align Text in Excel

Learn to use Excel's "Center Across Selection" to align text across cells without merging, avoiding common data manipulation issues. This guide provides steps to utilize this newly accessible feature and add it to your Quick Access Toolbar.

Ars Technica's Rocket Report: Your Essential Space Industry Briefing
Review
Ars TechnicaOct 16

Ars Technica's Rocket Report: Your Essential Space Industry Briefing

Quick Verdict Ars Technica's Rocket Report, presented by veteran space reporter Stephen Clark, offers an invaluable and meticulously organized weekly (or similar frequency, implied by "Edition 9.15") digest of the most

AI's Confidence vs. Formal Methods' Rigor: Design Flaws & Verification
Programming
Stack Overflow BlogOct 16

AI's Confidence vs. Formal Methods' Rigor: Design Flaws & Verification

While AI accelerates code generation, formal methods remain critical for ensuring system correctness. Languages like TLA+ and tools like Quint enable developers to model and verify system designs before coding, catching subtle flaws. Quint makes formal methods more accessible with developer-friendly syntax and executability. This approach is vital for verifying AI-generated code through trace validation and model-based testing, ensuring reliability against real-world data.

Amazon Prime Video Launches AI-Powered Prime 360 for NBA Coverage
Tech
GeekWireOct 16

Amazon Prime Video Launches AI-Powered Prime 360 for NBA Coverage

Amazon Prime Video is elevating its NBA coverage with the introduction of Prime 360, an AI-powered replay system offering immersive, 'fly through' views of the action. Kicking off its second season, Prime Video also adds Yahoo fantasy integration and gains exclusive Eastern Conference Finals rights, expanding its tech-driven sports broadcast. The new features aim to deliver a unique and interactive viewing experience for basketball fans.

Kojima Compares Divisive New Film 'Digger' to MGS2's Prescient Vision
Games
KotakuOct 15

Kojima Compares Divisive New Film 'Digger' to MGS2's Prescient Vision

Gaming icon Hideo Kojima has praised the divisive 2026 film *Digger*, drawing intriguing parallels to his own prophetic game, *Metal Gear Solid 2*. Both works, he explains, uniquely explore the dangers of misinformation and a fragmented digital reality, anxieties he shares with *Digger*'s director, Alejandro González Iñárritu.

Back to Newsroom

Stay ahead of the curve

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