Country specialists, a coordinator and a reviewer in one script

A common ambition with today's coding and agent tools is a small organisation of AI workers: ten agents each specialised in a country or market, one pipeline agent that collects and merges their output, and one quality assurance agent that checks the result. People attempting this in agent interfaces quickly ask how to see all those agents in one place, how to stop them stepping on each other and how to keep costs and limits under control.
This guide shows a code-first answer. Instead of juggling many terminal sessions, you define agents as data, run them through one orchestrator with controlled concurrency and record every step in a log you can read or turn into a simple dashboard. The example runs on the free keyless endpoint on this site, which is independent and not affiliated with Anthropic, and the same structure works with any OpenAI-compatible provider.
Frequently asked questions
What is an orchestrator in a multi-agent system?
The code that decides which agent runs when, passes inputs between them and collects results. It can be a simple script or a framework, but it is ordinary software, not another model.
How does a pipeline agent differ from a QA agent?
A pipeline agent combines outputs into one product, such as merging ten market briefs into a report. A QA agent reviews that product against criteria and either approves it or lists problems to fix.
Do agents need to talk to each other directly?
Usually not. Passing structured outputs through the orchestrator is simpler and easier to debug than free-form agent conversations, which tend to wander and waste tokens.
Which is better, one large agent or many small ones?
Specialised agents with narrow prompts are easier to test and improve. A single agent with a huge prompt is simpler to start but harder to control as the scope grows.
How many agents can run at once on the free endpoint?
Two requests in parallel per IP, at one request per second with bursts of three. An orchestrator should queue the rest rather than fire everything at once.
Can agents share memory?
Only through what your orchestrator stores and passes along. The API is stateless, so each call must include all the context the agent needs.
What model do the agents use here?
free-ai, an independent open-weight model of about 35B parameters. It is not Claude. For demanding reasoning, a stronger commercial model may be worth assigning to the QA role.
Step by step
- Define agents as records — List each agent with a name, role prompt, model and required output format in a list or configuration file.
- Write the orchestrator — Run market agents through a semaphore and pacer that respect parallel and per-second limits, then call the pipeline and QA agents in order.
- Log every event — Write one JSON line per agent call with run ID, agent, timing, size and status, and store full outputs in separate files.
- Set hard caps — Limit output tokens per role, revision rounds and total calls per run so loops cannot run away.
- Add human review — Pause before final delivery and show the report, QA verdict and raw agent outputs to a person for approval.
Agents as data, not as windows
The instinct to open one interface session per agent comes from how chat tools are built. It does not scale: twelve windows are hard to watch, impossible to coordinate and expensive to keep alive. A better mental model treats each agent as a record with a name, a role description, a model and an output format.
Once agents are data, everything else becomes easier. You can list them in a table, run them in any order, swap a model for one agent without touching the rest and add an eleventh market with one new entry.
A role is a system prompt plus a contract
Each agent needs instructions and a defined output shape, such as JSON with specific keys. The contract is what lets the pipeline agent combine results reliably.
Keep specialisation real
A country agent should receive country-specific context: local regulations to mention, currency, language conventions. Without it, ten agents produce ten copies of the same generic answer.
The shape of the pipeline
The design here has three stages. First, all market agents run on the same brief and produce structured findings. Second, the pipeline agent receives every finding and writes a combined report. Third, the QA agent reviews the report against a checklist and returns either an approval or specific issues.
If QA finds problems, the orchestrator can send the issues back to the pipeline agent for a revision, with a limit on how many rounds are allowed. A cap of one or two rounds avoids endless loops.
Write down the data contract between stages before writing prompts. When the market agents' JSON keys are fixed, the pipeline agent's prompt can rely on them, and a broken agent shows up as a validation error instead of a confusing report.
- Stage 1: ten market agents in parallel, under the concurrency limit
- Stage 2: one pipeline agent merges structured findings
- Stage 3: one QA agent checks against an explicit checklist
- Optional: one revision round if QA reports issues

Running agents under rate limits
Ten agents launched simultaneously will collide with any rate limit. The free endpoint allows two parallel requests per IP and one request per second with short bursts, so the orchestrator must pace calls. A semaphore caps concurrency and a small pacer spaces out start times.
The script below implements the full pipeline with Python's asyncio and the async OpenAI client. Market agents run two at a time, then the pipeline and QA agents run in sequence.
Why a pacer and a semaphore
The semaphore limits how many calls are in flight; the pacer limits how fast new ones start. Together they keep the orchestrator below both the parallel and the per-second limits.
Handle 429 and 503 anyway
Even with pacing, a busy server may return 503. Wrap the call with a retry that waits a few seconds, as shown in handling overloaded errors.
import asyncio
import json
import time
from openai import AsyncOpenAI
client = AsyncOpenAI(base_url="https://api.anthropickeyfreeapi.com/v1", api_key="none")
MARKETS = ["Germany", "France", "Spain", "Italy", "Poland", "Netherlands", "Sweden", "Brazil", "Japan", "Canada"]
BRIEF = "A subscription app for learning to cook with seasonal vegetables."
sem = asyncio.Semaphore(2)
_lock = asyncio.Lock()
_next_start = 0.0
async def pace(interval=1.1):
global _next_start
async with _lock:
now = time.monotonic()
wait = max(0.0, _next_start - now)
_next_start = max(now, _next_start) + interval
await asyncio.sleep(wait)
async def ask(name, system, user, max_tokens=700):
async with sem:
await pace()
r = await client.chat.completions.create(
model="free-ai", max_tokens=max_tokens,
messages=[{"role": "system", "content": system}, {"role": "user", "content": user}],
)
text = r.choices[0].message.content
print(json.dumps({"agent": name, "chars": len(text)}), flush=True)
return text
async def main():
market_sys = "You are a market analyst for {m}. Reply in JSON with keys: fit, risks, local_tips (lists of short strings)."
findings = await asyncio.gather(*[
ask(m, market_sys.format(m=m), BRIEF) for m in MARKETS
])
merged = "\n\n".join(f"## {m}\n{f}" for m, f in zip(MARKETS, findings))
report = await ask("pipeline", "Merge the market findings into one concise launch report with a ranked shortlist.", merged, 1500)
review = await ask("qa", "Check the report: every market mentioned, no contradictions, clear ranking. Reply APPROVED or a list of issues.", report, 400)
print(report)
print("QA:", review)
asyncio.run(main())Seeing every agent in one place
The wish for one interface showing all agents is really a wish for observability. The orchestrator already knows everything: which agent started when, how long it took, what it returned and whether it failed. Write that to a structured log, one JSON line per event, and you can follow the run in a terminal or load the file into any dashboard tool.
Even a simple HTML page that reads the log and shows a row per agent with its status gives you the overview that a dozen windows never could.
Log inputs and outputs by reference
Store full prompts and replies in files named by run and agent, and keep only paths, sizes and timings in the event log. The log stays small and readable.
Give every run an ID
A run identifier on every log line lets you compare today's results with yesterday's and trace a bad report back to the agent that caused it.

Writing prompts for specialised roles
Each role prompt should state the agent's perspective, the inputs it will receive and the exact output format. Market agents need local context and a fixed JSON shape. The pipeline agent needs to know how to rank and how long the report should be. The QA agent needs an explicit checklist rather than a vague request to check quality.
Resist giving agents personalities or long backstories. They add tokens without improving results. A clear task and format do more.
Checklists make QA useful
A reviewer told to look for problems finds generic ones. A reviewer told to verify that every market appears, that no two recommendations contradict and that the ranking has reasons gives actionable feedback.
Choosing models per role
Not every role needs the same model. Market agents doing structured extraction work well on a mid-sized model. The pipeline agent, which must synthesise and rank, benefits from stronger reasoning. The QA agent is a good place to spend on a capable model because its judgement gates the result.
Since all roles use the same chat format, assigning a different provider to one role is a configuration change. Many teams prototype the whole system on a free model, then upgrade only the roles where quality visibly falls short. See small vs large models for how to decide.
Upgrade one role at a time
Change the model for a single role, rerun the same brief and compare. Changing several roles at once makes it impossible to tell which change helped.

Controlling cost and runaway loops
Multi-agent systems multiply tokens: ten market agents means ten calls before anything is merged, and every revision round adds more. Set limits explicitly. Cap output tokens per role, cap revision rounds and cap total calls per run. If a cap is reached, stop and report rather than continuing.
Log token usage from each response and sum it per run. That figure, multiplied by a paid model's current rate, tells you what the system would cost in production. The ledger approach in tracking API spend applies directly.
Budget the daily allowance
On the free endpoint, each IP has 10,000 requests or 10 million tokens per day, reset at 00:00 UTC. A twelve-call run uses a tiny fraction, but a loop gone wrong could use far more.
Fail fast on bad structure
If a market agent returns invalid JSON twice, record the failure and continue with the others. One broken agent should not block the whole run.
Keeping humans in the loop
Agents can produce confident nonsense, and a QA agent made of the same kind of model will not catch all of it. For anything that leaves your team, such as a launch recommendation or a client report, add a human review step after QA. The orchestrator can pause and wait for approval before final delivery.
Make that review easy: show the report, the QA verdict and links to each market agent's raw output. A reviewer who can trace a claim to its source in seconds will actually check it.
Know the model's boundaries
free-ai refuses far less than commercial assistants but has two hard rules: no sexual content involving minors and no operational instructions for mass-casualty weapons. Business analysis is far from either, but your own policies still apply.

From script to service
Once the script produces useful results, turning it into a service is incremental. Move agent definitions into a configuration file, store run logs in a database, add a small web page to start runs and view results, and schedule recurring runs if the analysis should refresh regularly.
If agents need tools, such as looking up live data, expose those tools through a shared server so every agent uses the same implementation; building a minimal MCP server shows how. Because the API is stateless and text only, any memory or file handling lives in your service, which is exactly where you want control.
Send a prompt to the keyless free-ai endpoint from the home page and see how it handles your own task, no signup needed.
Read also
- Can you recreate skills and tool use from Claude apps through an API?
- Small fast models vs large ones: which fits high-volume AI work?
- Can you run a chat subscription inside third-party AI agents?
- How do you keep track of AI API spend across several providers?
- Why do AI coding agents burn through so many tokens so quickly?