
Artificial intelligence is moving beyond simple chatbots. Modern AI applications can use multiple specialized agents that collaborate to solve complex problems, analyze information, write code, and automate workflows.
Instead of asking a single AI model to handle every task, you can create a system in which different agents have different responsibilities.
For example, one AI agent can research a problem, another can analyze the findings, and a third can prepare a final response.
But what if you want to build this system without depending on cloud AI services?
In this tutorial, you will learn how to build a multi-agent AI system that runs locally using Node.js, Ollama, and LangGraph. We will create specialized AI agents that work together to analyze a task and generate a final answer using a locally running language model.
This project is useful for developers interested in AI agents, local LLMs, workflow automation, and building private AI applications.
What Is a Multi-Agent AI System?
A multi-agent AI system consists of multiple AI agents that collaborate to complete a task.
Each agent can have a specific role, instructions, and access to particular tools or information.
For example, imagine building an AI system that analyzes a software project.
You could create three agents:
Research Agent: Identifies the problem and gathers relevant information from the supplied input.
Analysis Agent: Evaluates the information and suggests solutions.
Writer Agent: Organizes the findings into a clear final report.
Each agent performs a different step, and the output of one agent can become the input for another.
Single-Agent AI vs Multi-Agent AI
A single-agent system uses one AI workflow to handle a task. A multi-agent system separates the task into specialized steps.
Feature | Single-Agent AI | Multi-Agent AI |
|---|---|---|
Number of specialized agents | Usually one | Two or more |
Task handling | One workflow handles the task | Responsibilities can be divided |
Workflow complexity | Usually simpler | Usually more complex |
Coordination | Limited | Agents may exchange outputs |
Resource usage | Often lower | May require more model calls |
Best use case | Simple questions and tasks | Complex, multi-step workflows |
A multi-agent system is not automatically better. For straightforward tasks, one well-designed agent may be faster, cheaper, and easier to maintain.
Multi-agent architectures become useful when a task benefits from clearly separated responsibilities.
Why Run Multi-Agent AI Locally?
Many AI agent frameworks use cloud-based language models. However, you can also create agent workflows using a local model.
Running a multi-agent system locally provides several advantages.
1. Greater Data Control
When agents use a locally running model, prompts and supplied context can be processed on your own computer instead of being sent to a cloud inference provider.
This can be helpful when experimenting with private documents or source code.
However, local inference alone does not guarantee complete privacy. Your application must also avoid transmitting data through external APIs, logging services, or other integrations.
2. Reduced Cloud Inference Costs
A local model can avoid per-request cloud inference charges.
You still need suitable hardware, electricity, and storage, and you may incur costs if you use external services.
3. Offline Operation
Once the model, dependencies, and required resources are downloaded, the core AI workflow can operate without an internet connection.
4. Customization
You can customize each agent's instructions, workflow, model settings, and responsibilities.
5. A Practical Way to Learn AI Agents
Building a local multi-agent system helps you understand how language models, agent roles, workflow orchestration, and application backends work together.
Technologies We Will Use
We will use the following technologies to build our project.
Technology | Purpose |
|---|---|
Node.js | Runs the application |
JavaScript | Implements the agent workflow |
Ollama | Runs the language model locally |
LangChain | Connects the application to the local model |
LangGraph | Coordinates the multi-agent workflow |
npm | Manages project dependencies |
Ollama will run the model, while LangGraph will coordinate the agents and determine the order in which they execute.
Official resources:
Ollama: https://ollama.com/
LangChain.js: https://js.langchain.com/
LangGraph.js: https://docs.langchain.com/oss/javascript/langgraph/overview
How Our Multi-Agent System Will Work
We will build a system with three agents:
Research Agent
Analysis Agent
Report Agent
The system will accept a task, pass it through the three agents, and return a final response.
For example, the user might submit:
"Analyze the benefits and challenges of using local AI models for Node.js development."
The agents will process this request in sequence.
User Task
|
v
+-------------------+
| Research Agent |
+-------------------+
|
v
+-------------------+
| Analysis Agent |
+-------------------+
|
v
+-------------------+
| Report Agent |
+-------------------+
|
v
Final ResponseThis is a sequential multi-agent workflow. The agents have different responsibilities, but they do not independently communicate with one another outside the workflow we define.
Each agent receives the task and relevant output from the previous step.
Step 1: Install Node.js
First, make sure Node.js is installed on your computer.
Download it from the official website:
Check your installation by running:
node -v
npm -vIf both commands display version numbers, you are ready to create the project.
Use a supported Node.js version compatible with the dependencies you install.
Step 2: Install Ollama
Download and install Ollama:
Ollama allows you to run supported language models locally.
After installation, check whether the command is available:
ollama --versionNext, download a model.
For this tutorial, we will use a small model as an example:
ollama pull qwen2.5:3bThis command downloads the three-billion-parameter Qwen2.5 model.
You can choose a different compatible model if it better fits your hardware or quality requirements. Check the model's availability and requirements before downloading it.
Test the model:
ollama run qwen2.5:3bAsk a simple question:
Explain what an AI agent is in simple words.If the model generates a response, it is ready to use.
Exit the interactive session after testing.
Important: You need an internet connection to download the model initially. Once the model is installed, it can run locally.
Step 3: Create the Project
Create a new Node.js project:
mkdir local-multi-agent-ai
cd local-multi-agent-ai
npm init -yInstall the required dependencies:
npm install @langchain/core @langchain/ollama @langchain/langgraphThese packages provide the model integration and graph-based workflow orchestration used in our example.
If npm reports a compatibility issue, check the current package documentation and your Node.js version rather than forcing incompatible dependency versions.
Create the following project structure:
local-multi-agent-ai/
│
├── src/
│ ├── agents.js
│ └── index.js
│
└── package.jsonThe agents.js file will define our specialized agents.
The index.js file will coordinate the workflow and execute the task.
Step 4: Configure the Local AI Model
Open package.json and add a start script.
For example:
{
"scripts": {
"start": "node src/index.js"
}
}Keep the other fields generated by npm.
We will use the Ollama integration provided by LangChain to connect the application to the local model.
The model name in your code must match the model you downloaded.
Step 5: Create the AI Agents
Create a file named src/agents.js.
Add the following code:
const { ChatOllama } = require("@langchain/ollama");
const model = new ChatOllama({
model: "qwen2.5:3b",
temperature: 0.2,
maxRetries: 2,
baseUrl: "http://127.0.0.1:11434",
});
async function researchAgent(task) {
const response = await model.invoke([
{
role: "system",
content: `
You are a research agent.
Your responsibility is to identify the main aspects of a task
and organize relevant information supplied by the user.
Do not invent facts or claim to have browsed the internet.
Clearly identify uncertainty.
Return concise, structured findings.
`,
},
{
role: "user",
content: task,
},
]);
return response.content;
}
async function analysisAgent(task, research) {
const response = await model.invoke([
{
role: "system",
content: `
You are an analysis agent.
Evaluate the research findings.
Identify important insights, trade-offs, limitations,
and practical recommendations.
Do not treat unsupported claims as verified facts.
`,
},
{
role: "user",
content: `
Original task:
${task}
Research findings:
${research}
Analyze the information and return structured conclusions.
`,
},
]);
return response.content;
}
async function reportAgent(task, research, analysis) {
const response = await model.invoke([
{
role: "system",
content: `
You are a report-writing agent.
Create a clear final response based on the supplied research
and analysis.
Use headings and practical recommendations when appropriate.
Do not introduce unsupported claims.
`,
},
{
role: "user",
content: `
Original task:
${task}
Research findings:
${research}
Analysis:
${analysis}
Write the final report.
`,
},
]);
return response.content;
}
module.exports = {
researchAgent,
analysisAgent,
reportAgent,
};Understanding the Agent Code
We create a local model using ChatOllama.
const { ChatOllama } = require("@langchain/ollama");
const model = new ChatOllama({
model: "qwen2.5:3b",
temperature: 0.2,
});The model is configured to use Ollama running on the same computer.
Next, we define three functions:
Research Agent
The research agent examines the original task and generates structured findings.
In this simple implementation, it uses the supplied task and the model's existing knowledge. It does not search external websites or access local documents automatically.
Analysis Agent
The analysis agent receives the task and the research output. It evaluates the findings and produces conclusions.
Report Agent
The report agent combines the task, research, and analysis into a final response.
Each function uses the same local model, but each has a different system instruction.
This is an important distinction: specialized roles do not necessarily require separate AI models. You can use the same model for multiple agents and change the instructions for each role.
Step 6: Coordinate the Agents with LangGraph
Now we will use LangGraph to coordinate the workflow.
Create src/index.js.
Add the following code:
const { StateGraph, START, END } = require("@langchain/langgraph");
const {
researchAgent,
analysisAgent,
reportAgent,
} = require("./agents");
const workflow = new StateGraph({
channels: {
task: {
value: (_, next) => next,
default: () => "",
},
research: {
value: (_, next) => next,
default: () => "",
},
analysis: {
value: (_, next) => next,
default: () => "",
},
report: {
value: (_, next) => next,
default: () => "",
},
},
});
workflow.addNode("research", async (state) => {
console.log("\nResearch Agent is working...");
const research = await researchAgent(state.task);
return { research };
});
workflow.addNode("analysis", async (state) => {
console.log("Analysis Agent is working...");
const analysis = await analysisAgent(
state.task,
state.research
);
return { analysis };
});
workflow.addNode("report", async (state) => {
console.log("Report Agent is working...");
const report = await reportAgent(
state.task,
state.research,
state.analysis
);
return { report };
});
workflow.addEdge(START, "research");
workflow.addEdge("research", "analysis");
workflow.addEdge("analysis", "report");
workflow.addEdge("report", END);
const app = workflow.compile();
async function main() {
const task = process.argv.slice(2).join(" ").trim();
if (!task) {
console.log(
'Usage: npm start -- "Analyze local AI for Node.js development"'
);
process.exitCode = 1;
return;
}
try {
const result = await app.invoke({ task });
console.log("\n========== FINAL REPORT ==========\n");
console.log(result.report);
} catch (error) {
console.error("\nWorkflow failed:", error.message);
process.exitCode = 1;
}
}
main();How LangGraph Works
LangGraph represents the workflow as a graph of nodes and edges.
In our project:
Each node runs one agent.
Each edge determines which node executes next.
The shared state stores the original task and each agent's output.
The final node generates the completed report.
These lines define the execution order:
workflow.addEdge(START, "research");
workflow.addEdge("research", "analysis");
workflow.addEdge("analysis", "report");
workflow.addEdge("report", END);The workflow begins with the research agent, continues to the analysis agent, then runs the report agent before finishing.
This approach makes it easier to extend the application later with conditional branches, additional agents, and human approval steps.
Note: LangGraph's JavaScript API and package exports can change between releases. If your installed version reports an API or import error, consult the documentation for that specific version and adjust the graph definition accordingly.
Step 7: Run the Multi-Agent AI System
Before running the application, make sure Ollama is installed, the model has been downloaded, and the Ollama service is running.
Run the application:
npm start -- "Analyze the benefits and challenges of running AI models locally"The system will execute the agents in sequence.
You should see output similar to:
Research Agent is working...
Analysis Agent is working...
Report Agent is working...
========== FINAL REPORT ==========
[The generated report appears here]The actual report will depend on your model and the task you provide.
Try another task:
npm start -- "Explain how Node.js developers can use local AI models"You can also ask it to compare two technologies or analyze the advantages and disadvantages of a software architecture.
Step 8: Make the System Work Offline
To confirm that the system works without an internet connection, follow these steps:
Install Node.js and Ollama.
Install the npm dependencies.
Download the AI model.
Run the system while connected to the internet to verify that everything works.
Disconnect from the internet.
Run the same command again.
If the system works offline, the model, dependencies, and required resources are available locally.
For reliable offline operation, avoid adding cloud model providers, online search tools, or external services unless they are specifically required.
The local workflow sends requests to Ollama at 127.0.0.1:11434, so the model inference itself does not require an external AI API.
Step 9: How to Improve the Multi-Agent System
The example above demonstrates the basic architecture, but you can make it much more powerful.
1. Add a Coding Agent
Create a specialized agent that reviews code and suggests improvements.
For example, it could analyze a Node.js function for:
Potential bugs
Error handling
Performance problems
Readability
Security risks
Start with code analysis and suggested changes before giving the agent permission to modify files.
2. Add a Reviewer Agent
A reviewer agent can evaluate the report or code produced by another agent.
For example:
Writer Agent
|
v
Reviewer Agent
|
v
Final ResponseThe reviewer could identify missing requirements, unsupported claims, or unclear explanations.
You can also use conditional graph edges to decide whether the workflow should finish or repeat a step.
3. Add Local Document Search
You can connect the system to a local collection of documents.
A retrieval-augmented generation (RAG) workflow could retrieve relevant content and provide it to the research agent.
Possible components include:
Local document loaders
Embedding models
A vector database
A retrieval function
A local language model
This would let your agents answer questions based on your own documents rather than relying only on a model's existing knowledge.
4. Add Tool Access
Agents become more useful when they can interact with tools.
Examples include:
Reading selected project files
Searching a local knowledge base
Running approved tests
Calculating results
Checking structured data
However, tool access should be restricted. An agent should not receive unrestricted access to your filesystem, terminal, credentials, or production systems.
5. Run Agents in Parallel
Some tasks can be performed independently.
For example, separate agents might analyze security, performance, and maintainability at the same time.
A graph-based workflow can execute independent branches in parallel when configured appropriately.
Parallel execution may reduce total response time, but it can also increase resource consumption, particularly when several agents use the same local model simultaneously.
6. Add a Web Interface
You can create a frontend using React or Next.js and connect it to your Node.js backend.
Useful features include:
Task input
Agent execution status
Intermediate results
Final reports
Conversation history
Workflow logs
This would transform the command-line example into a more complete local AI application.
Advantages of Local Multi-Agent AI
Running a multi-agent system locally has several advantages.
Privacy and control: With a properly configured local workflow, prompts and supplied documents can remain on your computer.
Reduced cloud inference costs: Local inference can avoid per-request fees charged by cloud model providers.
Offline functionality: The workflow can continue operating without an internet connection after the required resources are installed.
Customization: Each agent can have a specific role, instructions, and access to approved tools.
Learning opportunities: You can explore AI orchestration, local models, workflow graphs, and application design in a practical project.
Limitations of Local Multi-Agent AI
Local multi-agent systems also have limitations.
Hardware Requirements
Every model call consumes computing resources. Multiple agents can increase the total workload.
Response Quality
A smaller local model may struggle with complex reasoning, long context, or specialized technical questions.
Increased Latency
In a sequential workflow, the system must wait for each agent to finish before moving to the next step.
Error Propagation
If the research agent produces incorrect information, the analysis and report agents may repeat or amplify those errors.
More Complex Debugging
Multi-agent systems are harder to debug than a simple chatbot because errors can originate from individual agents, state management, or workflow transitions.
Not Every Task Needs Multiple Agents
For straightforward questions, a single model call may be sufficient. Multi-agent workflows are most useful when separating responsibilities improves the result.
Frequently Asked Questions
Can I build a multi-agent AI system using Node.js?
Yes. Node.js can run a multi-agent workflow using libraries such as LangGraph.js and local model integrations such as LangChain's Ollama integration.
Can a multi-agent AI system run without the internet?
Yes. The core workflow can run offline if the model, dependencies, and required resources are installed locally and the application does not rely on external services.
Is Ollama suitable for multi-agent AI?
Ollama can serve local language models that your application uses for multiple agent steps. Performance depends on the model and your computer's hardware.
Do I need a separate model for every agent?
No. You can use the same model for several agents while giving each one different instructions. Separate models may be useful when tasks have different performance or quality requirements, but they are not necessary for a basic multi-agent system.
Is LangGraph necessary?
No. You can coordinate agents using ordinary JavaScript functions. LangGraph becomes useful when you need explicit workflow state, branching, parallel execution, retries, or more complex orchestration.
Can local AI agents edit files automatically?
Yes, if you build and grant them file-editing tools. However, file modifications introduce risks. Restrict the accessible directories, review changes, and require confirmation before destructive actions.
Is a multi-agent system better than a single AI agent?
Not always. Multiple agents can help divide complex tasks into specialized steps, but they also increase complexity, latency, and the number of model calls. Compare both approaches on your actual use case.
Conclusion
Building a multi-agent AI system locally is a useful way to explore the next stage of AI-assisted development.
By combining Node.js, Ollama, LangChain, and LangGraph, you can create a workflow in which specialized agents research a task, analyze the findings, and generate a final report without depending on a cloud AI model for inference.
In this tutorial, we created three agents and connected them through a sequential workflow.
You can extend the project by adding code review, local document search, tool access, parallel execution, and a web interface.
Start with a simple workflow, evaluate the output carefully, and add more agents only when they provide a clear benefit.
Technical author and software engineer at DevByte. Writing deep-dive tutorials on distributed systems, modern full-stack web architectures, and cloud deployments.


