Create a Multi‑Agent Pipeline
Multi‑agent systems are one of the most exciting frontiers in modern AI. Instead of relying on a single model to
do everything, you orchestrate multiple specialized agents — each with its own role, strengths, and perspective.
This mirrors the approach used in early autonomous frameworks like
AutoGPT and
BabyAGI, as well as more recent
research into LLM‑as‑Agents.
In this step, you’ll build a simple but powerful 3‑agent workflow:
- Researcher — gathers clear, factual information
- Writer — transforms research into structured prose
- Editor — improves clarity, tone, and readability
Each agent is just a function that calls your local model with a different system prompt — but together, they form
a coordinated pipeline capable of producing high‑quality output.
1. Create multi.js
touch multi.js
Add the following code:
import ollama from "ollama";
async function callAgent(systemPrompt, userPrompt) {
const response = await ollama.chat({
model: "llama3",
messages: [
{ role: "system", content: systemPrompt },
{ role: "user", content: userPrompt }
],
stream: false
});
return response.message.content;
}
// Agents
async function researcher(topic) {
return await callAgent(
"You are a research agent. Gather clear, factual information.",
`Research this topic: ${topic}`
);
}
async function writer(research) {
return await callAgent(
"You are a writing agent. Turn research into a well-written article.",
research
);
}
async function editor(draft) {
return await callAgent(
"You are an editing agent. Improve clarity, tone, and flow.",
draft
);
}
// Pipeline
async function runPipeline(topic) {
console.log("Researching...");
const research = await researcher(topic);
console.log("\\nWriting...");
const draft = await writer(research);
console.log("\\nEditing...");
const final = await editor(draft);
console.log("\\n--- Final Output ---\\n");
console.log(final);
}
runPipeline("How solar panels work");
This pipeline demonstrates a core principle of multi‑agent systems: specialization. Each agent focuses on a single
task, and the quality of the final output improves dramatically as a result.
2. Run the Pipeline
node multi.js
You’ll see output like:
Researching...
Writing...
Editing...
--- Final Output ---
[polished article]
You now have a functioning multi‑agent system running entirely on your machine — no cloud, no API keys, and no
external dependencies.
3. Customize Your Agents
Multi‑agent pipelines become far more powerful when you tailor each agent’s personality and role. Try modifying
the system prompts:
- Make the writer more creative or more technical
- Make the editor more strict or more conversational
- Add a “fact‑checker” agent to verify claims
- Add a “summarizer” agent to condense long research
With just a few lines of code, you can build research studios, writing teams, coding assistants, analysis
pipelines, and more — all powered by local models.
4. Add Tools to Agents
When you combine multi‑agent workflows with your tool system, your agents can:
- read files and documents
- write reports or summaries
- organize folders or rename files
- analyze logs or datasets
- generate drafts and refine them
This is the foundation of real agentic software — systems that can reason, act, and collaborate to achieve
complex goals.
Troubleshooting
Agents produce repetitive output
- Strengthen or clarify the system prompts
- Try a different model (Qwen and Mistral often produce more structured output)
Pipeline feels slow
- Use smaller models like
phi or qwen
- Reduce prompt length or intermediate output
Output is inconsistent
- Provide more structure in system prompts
- Break tasks into smaller, more explicit steps
You’ve completed the Starter Path.
Back to Starter Path →