tinyhivemind
Hive mind mechanics for agents
Quorum sensing, cross-inhibition, stigmergy, salience decay and response
thresholds, implemented as integer folds over a transcript your application
already owns. Hosts expose episode tools through their own tool interface.
Wiki ·
Quick start ·
Benchmarks ·
Architecture
[!NOTE]
A note from @senamakel.
This is one of my best works so far and one of the most important libraries that I have worked on: tinyhivemind takes inspiration and learnings from real life biology and my experience building harnesses, coordinating with agents, and building agents that can solve large, complex problems.
This concept was initially built inside of OpenCompany but had to be later on moved into it's own standalone repo as it was too important to be left inside of OpenCompany and it had to be well-defined, researched, tested, and simulated thoroughly.
I'm excited to share this with you all as an open-source contribution and if you like my work, give me a follow over at https://github.com/senamakel/ 🙌
Most hive minds are just fan-out
Publish a task, wake N agents, collect the replies, average them somehow. That
is a thread pool with a prompt attached. It has no notion of who is convinced,
no way to register a grounded objection, no reason to stop other than running
out of members, and no answer when somebody asks afterwards why the group chose
what it chose.
Actual collective decisions do not work that way, and the mechanisms that make
them work have been studied for decades in colonies that have no leader, no
shared memory, and far less bandwidth than five language models sharing a
channel. tinyhivemind implements those mechanisms.
The shape of it is a loop, and your application holds both ends:
your application tinyhivemind
┌───────────────────────────────┐
│ session log (you own it) │
│ 1 planner !propose #stage … │ ─── transcript ──┐
│ 2 scout !propose #ship … │ roster │
│ 3 critic !support #stage … │ desks ▼
│ │ ┌─────────────────────────┐
│ │ │ step(state, …) │
│ 4 planner !object >3 … │ │ -> HiveStep │
│ ▲ │ │ a pure fold. no IO. │
└──┼────────────────────────────┘ └────────────┬────────────┘
│ │
└──── one message, one round ◀── Speak { turns } ┤
│
Converged · Deadlocked · Exhausted · Idle ◀────┘
Speak { turns } above is shorthand for Speak { turns, next_state }, kept
off the diagram to stay narrow, not because it stopped mattering. The step
fold reads what you hand it and returns what should happen next. The host owns
the transcript and exposes the tools seats call.
The mechanics
Stigmergy. Work leaves a trace
in a shared medium, and the trace is the stimulus for the next piece of work.
No agent addresses another and nothing dispatches anything. The transcript is
the medium, and a marker line is a deposit in it.
!propose #stage Stage the rollout across three regions.
!support #stage ^1 Staging bounds the blast radius if the migration is wrong.
!object >3 The regions are not independent, so this bounds nothing.
!commit #stage
Pheromone decay.
A trace's pull on the room's attention decays
exponentially with distance
in the transcript. Without it, whoever spoke first holds the floor forever,
which is the failure ant trails avoid only because pheromone evaporates.
one !support trace, rescored as the room talks past it
distance recency term salience
0 ████████████████ 1000 3000
10 ████████████ 750 2875
20 ████████ 500 2750
40 ████ 250 2625
80 █ 62 2531
The floor under the bars is standing importance: an old proposal can outrank a
fresh question, while recency is the term that moves.
Quorum sensing. An option
carries when some number of distinct participants have grounded support for it
inside a window. Not a majority of anything, not a score to beat. The count is
local, order independent and idempotent, so an agent that catches up late folds
to exactly the same standing as one that watched live. This is how
honeybee swarms
settle a nest site.
With a typed model, standings_with_evaluations uses fixed-point Choice × Score after a Noul gate; see the quorum module.
1 planner !propose #stage Stage the rollout.
2 scout !propose #ship Ship it all at once.
3 critic !support #stage ^1 Staging bounds the blast radius.
#stage supporters ["planner", "critic"] -> carries at threshold 2
#ship supporters ["scout"]
4 auditor !support #stage I agree. <- no citation, counts for nothing
Cross-inhibition. An
objection names a message, and removes that message's author from the
supporter set of whatever they were advocating. It does not debit the option.
Subtracting from a score cannot break a tie between two equally supported
options; silencing an advocate can, and that asymmetry is the entire reason it
is shaped this way. Honeybees do this too, with stop signals.
both options carry, so the room is deadlocked
#stage supporters ["planner", "critic", "auditor"]
#ship supporters ["scout", "auditor"]
7 planner !object >6 ^1 The regions are not independent.
#stage supporters ["planner", "critic", "auditor"]
#ship supporters ["scout"] silenced ["auditor"] -> #stage carries
The objection travels through the message to the author, and only then to the
option — never straight at the option:
!object >6 authored by advocate for
planner ─────▶ msg 6 ────────────▶ auditor ──────────────▶ #ship
│
└── removed from #ship's supporters,
still counted for #stage
Response thresholds.
Every member computes an urge from the salience field and its own affinity, and
whoever bids highest takes the floor. A member whose urge never clears its
threshold does not bid at all. This is the response-threshold model of division
of labour, and it is also Pandemonium's
decision demon, which is the same idea arrived at from the AI side.
planner urge 10312 Addressed <- somebody cited its message
scout urge 8312 Salience
critic urge 8312 Salience
auditor -- <- threshold never cleared, does not bid
floor = planner
Every one of those is fixed-point integer
arithmetic. Every payload derives Eq, and every episode replays byte for byte
from the same transcript.
The floor is a substrate, not a broadcast
The mechanics need a room to run in, so tinyhivemind owns that too, and it is
the part most systems get wrong first. Five agents in one channel read each
other's replies as their own words, miss what a peer said between their own two
turns, and stampede on a single @everyone.
Who is here? A roster of agents, and the people signed in alongside them.
What is a desk, and who is on it? A declared room merged with the
operator's runtime additions, retirements and ordering.
Who does a name address? A mention grammar resolved against the live
roster and desks, where only a direct agent mention can start a turn.
What does one participant see? An attributed, thread-aware projection of a
multi-speaker transcript into one viewer's history, so agent B never reads
agent A's words as its own.
the shared transcript what agent B is handed
┌───────────────────────────┐ ┌────────────────────────────┐
│ 1 ana (person) │ │ user ana: … │
│ 2 agent A │ ─────▶ │ user agent A: … │
│ 3 agent B │ │ assistant … │ ← its own
│ 4 ana (person) │ │ user ana: … │
└───────────────────────────┘ └────────────────────────────┘
─────▶ what agent A is handed
┌────────────────────────────┐
│ user ana: … │
│ assistant … │ ← its own
│ user agent B: … │
│ user ana: … │
└────────────────────────────┘
One log, one sequence numbering, two histories. Every line a viewer did not
write arrives as somebody else's, named.
A desk is a correlation boundary, so a question can leave it
One room can pool what its members separately know. A company of rooms cannot,
and that is not an inconvenience — it is the thing that decides the answer.
Members of one desk read the same transcript, work the same part of the system,
and are wrong about the same things. Averaging correlated error does not remove
it, so no amount of deliberating inside a channel cancels a mistake every member
of it shares.
A referral is the one mechanism here that leaves a conversation: at most one
turn, which may run on another desk, and one answer carried back to the
conversation that asked. @#platform is not a broadcast — it resolves to
exactly one agent before the decision leaves the fold — and a round trip is two
hops, so it cannot ring.
Three desks, each confidently wrong about a different option, deciding one
question: deliberating inside the channels gets it right 0.2% of the time,
and every desk converges anyway, on three incompatible answers. Putting all
twelve members in one room instead — removing the boundary rather than crossing
it — gets 10.5%, because a bigger room with three factions never reaches
quorum. Crossing it gets 77.5%, which matches what the same information is
worth when handed over for free.
It is off by default, and at desks with no blind spot of their own it changes
no answer and costs twice the turns. That is the honest case for leaving it off.
Keep a short working view
That projection is bounded — about thirty messages — and the log behind it is
not. The obvious fix is to show more, and it is the wrong one:
Lost in the Middle finds a fact in the
middle of a long context is used less reliably than the same fact at the edge
of a short one, so a bigger window mostly relocates the problem into its own
middle. It also charges every participant on every turn.
Pin what must not be lost. !pin folds out of the transcript, not into a
second store, and the board rides into every turn.
State the budget. The briefing tells an agent what a message costs the room
it is written into. Reported, never enforced: nothing here rewrites what
somebody said.
An episode ends for a reason you can name
Every step walks the same ladder in the same order, and the first rung that
answers is the answer:
step(state, transcript, roster, desks, policy)
│
├─ budget spent? ─────────────────────────▶ Exhausted { spent, standings, visibility }
├─ quorum, and phase = Commit? ───────────▶ Converged { topic, .. }
├─ quorum, and phase = Deliberate? ───────▶ Speak { turns, next_state }
│ one commit turn; phase flips
├─ two topics carry, nobody to break it ──▶ Deadlocked { topics }
│
└─ highest bid clears its threshold? ─────▶ Speak { turns, next_state }
otherwise ▶ Idle
The phase only ever moves one way, and the room gets exactly one chance to say
out loud what it settled on:
┌─────────────┐ quorum reached ┌──────────┐ still holds
│ Deliberate │ ─────────────────▶ │ Commit │ ───────────────▶ Converged
└─────────────┘ emit !commit └──────────┘
Converged, deadlocked, exhausted, or idle. A room that could not decide says
so, instead of emitting an answer nobody actually supported. The turn budget is
finite, so termination is guaranteed rather than hoped for, and the standing
that carried is returned alongside the outcome.
One synthetic decision task
Five agents choosing between four options, 5000 seeded rooms, on one core:
| arm |
what it is |
turns |
correct |
ladder |
one responder answers alone, which is how most systems work today |
1.00 |
57.6% |