The example is deliberately small: three roles (researcher, writer, reviewer) share one task
board, and a coordinator model decides which open task goes to which role. What each role would
do with an assigned task is out of scope; a role agent would use whatever pattern in this manual
fits its own job. What this example isolates is only the part specific
to an organization: the shared board, and an assignment step the model does not fully control.
examples/organizations_swarms/run.py · lines 71–114
def coordinate(board: Board, model: Model, tracer: Tracer) -> list[dict]:
"""One coordination round. Returns the assignments actually made — which can be fewer than
the coordinator asked for, since every proposed assignment is checked against the board and
the budget before it counts.
The budget is per round and refills here, at the start of each one. Claims are not: a task
claimed in an earlier round is still claimed, because the board persists and the counters do
not. Both facts have to be tested, and testing the second one needs a round that still has
an open task to offer -- otherwise the round returns before the model is ever called and the
test passes without checking anything.
"""
board.assigned_count = {r: 0 for r in ROLES} # the budget is per round, so it starts full
if not any(t.status == "open" for t in board.tasks):
return []
messages = [Message(role="system", content=SYSTEM), Message(role="user", content=_digest(board))]
completion = model.complete(messages, tools=[ASSIGN_TOOL], max_tokens=200)
proposed = list(completion.tool_calls)
desc = ", ".join(f"assign({c.arguments.get('task_id')}, {c.arguments.get('role')})" for c in proposed) or "no assignments proposed"
tracer.record(
kind="model", decided_by="model", title="Coordinator assigns open tasks to roles",
detail=desc, tokens_in=completion.tokens_in, tokens_out=completion.tokens_out, ms=completion.ms,
)
made: list[dict] = []
for call in proposed:
task_id = str(call.arguments.get("task_id", ""))
role = str(call.arguments.get("role", ""))
task = board.get(task_id)
if task is None or task.status != "open":
tracer.record(kind="code", decided_by="code", title="Refuse: task is not open", detail=f"{task_id} (already claimed, or does not exist)")
continue
if role not in ROLES:
tracer.record(kind="code", decided_by="code", title="Refuse: no such role", detail=f"{role} for {task_id} (roles are fixed in code, not named by the coordinator)")
continue
if board.assigned_count[role] >= BUDGET_PER_ROLE:
tracer.record(kind="code", decided_by="code", title="Refuse: role is over budget", detail=f"{role} for {task_id}")
continue
task.status = "claimed"
task.assigned_to = role
board.assigned_count[role] += 1
tracer.record(kind="code", decided_by="code", title="Claim the task for the role", detail=f"{task_id} -> {role}")
made.append({"task": task_id, "role": role})
return made
One coordinator call runs per round, and that single call is the round’s only
decided_by: "model" step however many assignments it proposes; the diagram above draws each
proposal as its own dashed edge and says so under its tally.
BUDGET_PER_ROLE is a fixed cap the coordinator cannot raise by asking; a role that has already
been assigned two tasks this round gets no more, whatever the coordinator’s output requests next.
Claiming is checked against the board itself, not against what the coordinator believes is true:
task.status != "open" refuses an assignment outright, so if the coordinator’s own single call
proposes the same task to two different roles (nothing stops a model from repeating itself), only
the first proposal is ever honored. The second reads the board
fresh, sees the task is no longer open, and is refused, not silently overwritten and not queued
to run later. That check is what the shared board is actually for: a coordinator’s plan is a
proposal against it, not an instruction the board has to accept.
MetaGPT’s own paper describes a fuller version of the same idea, fixed procedure rather than a
per-round budget: it “utilizes an assembly line paradigm to assign diverse roles to various
agents, efficiently breaking down complex tasks into subtasks involving many agents working
together” and encodes “Standardized Operating Procedures (SOPs) into prompt sequences for more
streamlined workflows”[2]. The paper’s claim for that design is scoped: “On
collaborative software engineering benchmarks, MetaGPT generates more coherent solutions than
previous chat-based multi-agent systems”[2]. That is the authors’ result on those
benchmarks, against the systems they chose to compare with, and not a result this site has
measured.
A different line of research reaches for coordination without any fixed roster at all. Park et
al.’s Generative Agents paper populated a sandbox (twenty-five agents in a small town, no shared
board and no fixed roles, just memory, planning and reflection) and reports
that “starting with only a single user-specified notion that one agent wants to throw a
Valentine’s Day party, the agents autonomously spread invitations to the party over the next two
days, make new acquaintances, ask each other out on dates to the party, and coordinate to show up
for the party together at the right time”[1]. The paper’s subject is believable human
behavior in a simulation, not work getting done: read it for the mechanism, which is that
coordination can emerge without a coordinator role, and not as evidence that a roster of agents
will organize itself around a real task.
The two rules look alike and behave differently, which is worth testing separately: the budget is
spent per round and refills at the start of the next one, while a claim is permanent until the
task is done. tests/test_example_organizations_swarms.py scripts a coordinator that over-assigns
one role, one that proposes the same task twice in a single call, and one that tries to re-claim
a task in a later round: that last test keeps a second task open on purpose, because a round with
nothing open returns before the model is ever called and would otherwise pass without checking
anything. Run it yourself:
examples/organizations_swarms/README.md · lines 12–12
python -m examples.organizations_swarms --model stub:scripted