Single-Agent vs Multi-Agent Systems
Compare single-agent and multi-agent AI architectures with practical examples, trade-offs, and a decision framework for real projects.
The problem: one agent or many?
You have a task that involves several steps: fetch data, clean it, analyze it, and summarize it. You could write a single agent that does all of that, or you could split it into multiple specialized agents that hand off work. Which approach actually works better in production?
This article compares single-agent and multi-agent systems with concrete code examples. You will see a minimal single-agent loop, then a multi-agent version with two agents, and we will discuss the trade-offs in latency, cost, and reliability. By the end, you will have a clear decision framework and a recommended starting point.
- Understand the core difference: one model loop vs multiple coordinated loops.
- See runnable Python examples for both architectures.
- Learn when to add complexity and when to keep it simple.
- Get a decision checklist to apply to your own use case.
Before you start
We will use Python and the OpenAI API for the examples. You need an API key and the openai package installed. If you prefer a different provider, the concepts translate directly.
pip install openai- Set your API key as an environment variable: export OPENAI_API_KEY=sk-...
- The examples use the gpt-4o-mini model, which is fast and cheap for demos.
Step 1: Define a task that both architectures will solve
We will use a simple but realistic task: given a list of recent news headlines, extract the top three trending topics and write a one-paragraph summary for each. This requires multiple steps: reading the headlines, identifying topics, and generating summaries.
In a single-agent system, one agent does all steps. In a multi-agent system, we can split it into a researcher agent that extracts topics and a writer agent that writes summaries.
Step 2: Build a minimal single-agent loop
A single-agent loop is a while loop that sends the full conversation history to the model and checks if the agent is done. We will implement a simple function that takes a task, runs the loop, and returns the final output.
The key is that the agent has access to tools, but in this minimal example we will only use the model's built-in reasoning. The agent decides when it is done by returning a special marker.
import os
from openai import OpenAI
client = OpenAI()
MODEL = "gpt-4o-mini"
def run_single_agent(task: str) -> str:
messages = [{"role": "system", "content": "You are a helpful assistant. Complete the task and respond with FINAL ANSWER when done."},
{"role": "user", "content": task}]
while True:
response = client.chat.completions.create(model=MODEL, messages=messages)
content = response.choices[0].message.content
if "FINAL ANSWER" in content:
return content.replace("FINAL ANSWER", "").strip()
messages.append({"role": "assistant", "content": content})
# In a real agent, you would call tools here and append tool results.
# For this demo, we just ask the model to continue.
messages.append({"role": "user", "content": "Continue."})- The loop appends the assistant response and a 'Continue.' prompt to force the model to produce more until it emits the marker.
- This is a simplified version; production agents use tool calls and structured outputs.
Step 3: Run the single-agent example
We will call the function with a sample list of headlines. The agent will produce a final answer containing the topics and summaries.
headlines = [
"AI startup raises $50M for new model",
"Open source community releases new framework",
"Cloud providers cut prices for GPUs",
"Researchers develop faster training method",
"Regulators propose new AI safety rules"
]
task = f"Extract the top 3 trending topics from these headlines and write a one-paragraph summary for each. Headlines: {headlines}"
result = run_single_agent(task)
print(result)1. AI Funding and Investment
AI startup raises $50M for new model, indicating strong investor confidence...
2. Open Source Innovation
...
3. AI Regulation and Policy
...Step 4: Build a multi-agent system with two agents
Now we will create a multi-agent system with a researcher agent and a writer agent. The researcher extracts topics, and the writer generates summaries. Each agent has a specific system prompt and runs a single completion, not a loop.
We will orchestrate them in a simple Python script. The researcher returns a JSON list of topics, which we pass to the writer.
import json
from openai import OpenAI
client = OpenAI()
MODEL = "gpt-4o-mini"
def researcher(headlines: list[str]) -> list[str]:
prompt = f"Extract the top 3 trending topics from these headlines. Return a JSON array of strings. Headlines: {headlines}"
response = client.chat.completions.create(
model=MODEL,
messages=[
{"role": "system", "content": "You are a research agent. Output only valid JSON."},
{"role": "user", "content": prompt}
]
)
return json.loads(response.choices[0].message.content)
def writer(topic: str) -> str:
prompt = f"Write a one-paragraph summary about the topic: {topic}"
response = client.chat.completions.create(
model=MODEL,
messages=[
{"role": "system", "content": "You are a writing agent. Produce clear, concise summaries."},
{"role": "user", "content": prompt}
]
)
return response.choices[0].message.content
def run_multi_agent(headlines: list[str]) -> dict:
topics = researcher(headlines)
summaries = {topic: writer(topic) for topic in topics}
return summaries- The researcher returns structured data (JSON), which makes the handoff explicit.
- The writer is called once per topic, so we can parallelize if needed.
Step 5: Run the multi-agent example and compare
Run the multi-agent function with the same headlines and compare the output with the single-agent result. You will notice that the multi-agent version is more predictable because each agent has a focused role.
result_multi = run_multi_agent(headlines)
print(json.dumps(result_multi, indent=2))Key differences: latency, cost, and reliability
The single-agent loop makes multiple sequential calls to the model until it decides it is done. In our example, it might take 3-5 calls. The multi-agent system makes exactly 1 call for research plus 3 calls for writing, total 4 calls, but they can be parallelized if needed.
Latency: single-agent is sequential, so it takes longer. Multi-agent can run writer calls in parallel, reducing wall-clock time.
Cost: both use the same model, so cost is proportional to the number of tokens. Multi-agent may use more tokens because each agent repeats context, but it can be cheaper if you use smaller models for subtasks.
Reliability: single-agent can go off track because it has to manage the whole task in one context. Multi-agent isolates concerns, so a failure in one step is easier to debug and retry.
- Single-agent: simpler code, but harder to debug and extend.
- Multi-agent: more moving parts, but better separation of concerns.
- For tasks with clear sub-steps, multi-agent often wins.
- For open-ended tasks, a single agent with tools may be more flexible.
Decision framework: which should you use?
Use this checklist to decide between single and multi-agent for your project.
- If the task is a single, well-defined operation (e.g., translate text, summarize a document), use a single agent.
- If the task has multiple distinct stages that require different expertise (e.g., research then write), consider multi-agent.
- If you need to parallelize independent sub-tasks, multi-agent allows concurrent execution.
- If you need fine-grained control over each step (e.g., human approval between steps), multi-agent gives you checkpoints.
- If you are prototyping quickly, start with a single agent and refactor to multi-agent only when you hit a specific need.
What I would do: recommended setup
For most production tasks, I recommend starting with a single agent with tools, and only splitting into multiple agents when you need to scale or specialize. Here is a minimal template for a single agent with a tool that you can extend.
from openai import OpenAI
import json
client = OpenAI()
MODEL = "gpt-4o-mini"
tools = [
{
"type": "function",
"function": {
"name": "search_web",
"description": "Search the web for current information",
"parameters": {
"type": "object",
"properties": {"query": {"type": "string"}},
"required": ["query"]
}
}
}
]
def search_web(query: str) -> str:
# Implement a real search API call here
return f"Results for {query}"
def run_agent_with_tool(user_input: str):
messages = [{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": user_input}]
while True:
response = client.chat.completions.create(model=MODEL, messages=messages, tools=tools)
msg = response.choices[0].message
if msg.tool_calls:
for tool_call in msg.tool_calls:
if tool_call.function.name == "search_web":
args = json.loads(tool_call.function.arguments)
result = search_web(args["query"])
messages.append({"role": "tool", "tool_call_id": tool_call.id, "content": result})
messages.append(msg) # assistant message with tool calls
else:
return msg.contentTroubleshooting common issues
If your agent loops forever, add a maximum iteration count. If the output is not structured, use JSON mode or function calling. If the multi-agent system fails, check the intermediate outputs.
- Always set a max iterations limit in single-agent loops.
- Use structured outputs (JSON schema) to make handoffs reliable.
- Log every call to understand token usage and debug failures.
- For multi-agent, add retry logic per agent, not just at the top level.
FAQ
- Q: Can I mix different models in a multi-agent system? A: Yes, you can use a cheaper model for simple sub-tasks and a stronger model for complex ones.
- Q: How do I handle errors in a multi-agent pipeline? A: Wrap each agent call in a try-except and return a structured error object.
- Q: Is multi-agent always slower? A: Not necessarily; you can parallelize independent agents, which can make it faster than a single sequential loop.
- Q: Do I need a framework like LangChain? A: No, you can build a simple orchestration with plain Python as shown, but frameworks provide utilities for memory and tool use.
Next step
Take the examples and run them with your own data. Try adding a third agent or a tool call. Measure the latency and cost of both approaches. Then decide based on your requirements.
Key takeaways
- Apply one concrete change from this post before collecting more reading.
- Prefer browser-side tools when the work involves secrets, tokens, or PII.
- Document the why next to the how so the next reviewer inherits context.
FAQ
- Who is this guide on ai-agents for?
- Working developers who need a practical take on single-agent vs multi-agent systems — not a marketing overview. Skim the sections, apply one tip, then come back when you hit an edge case.
- Do I need an account to use the related tools?
- No. code.live tools run in your browser with no signup. Nothing you paste is uploaded to a server for the client-side utilities linked from this post.
- How often is this article updated?
- This post was published November 17, 2026. Fundamentals stay stable; check linked tool pages and official docs when version-specific behavior matters.