A crowd in one chat

The chat's own model answers, then each other member in order, then the order runs
backwards asking each whether it disagrees, ending at the main model, which either
closes or sends them round again. Design and reasoning: LLeMbas.wiki/Crowd-chats.

THE SPEAKER SEAM, WHICH IS ALSO A BUG FIX

`chat_service.speaker_for` makes the *message* name the answering model and the
chat only the default. That closes a live half-wired feature -- `wake_chat` takes a
model override and `schedule/runner` passes one, and it reached the row and never
the request, so a schedule naming another model got the chat's model wearing the
other one's name.

The seam is wider than `build_request`: `{{model_name}}`, the authored prompt's
model layer, `vision` (where a wrong answer makes the endpoint reject the whole
request), the effort vocabulary (which raises inside the model's own chat template,
and whose refusal narrows every Model row sharing the id), `resolve_tools`,
`context_length` -> `_too_big`, and `ToolContext.model_id`. `resolve_endpoint` may
now only write back `chat.connection_id` when the speaker *is* the chat's model.

WHY N CHAINED REPLIES

`Generation` is one reply's state and `_follow` streams per message, so one
generation cannot stream into nine bubbles and `ensure` would not know which of the
nine it was after a restart. A subagent per speaker cannot work either: its answer
comes back as a tool result and tool results are never replayed, so speaker 3 could
not see speaker 2 -- which is the whole point. Chained, exactly one incomplete row
exists at a time, and `tests/test_crowd_chain.py` asserts that at every
observation.

The round lives on `Message.crowd_json`, not on the chat: the row is the authority,
and chat-level state would describe turns a rewind or a restart had removed.
`crowd.next_turn` is pure, so all eight refusals are tested with no endpoint.

THREE RULES, EACH A BUG WRITTEN THE OTHER WAY ROUND

- `if not _advance_crowd(g): _drain(g)` -- advancing must *suppress* draining, or a
  queued human turn puts a second incomplete row beside the next speaker's.
- `_advance_crowd` refuses unless the finishing row is the newest, or regenerating
  member 2 creates a second member 3 and two chains race down one turn.
- an error skips one speaker and two in a row end the round: the usual failure is a
  small member's window overflowing, and `_drain`'s stop-on-error would kill every
  crowd at whichever member is smallest.

Each other speaker's turn is relabelled as attributed user content, which is both
how a model can disagree with words it did not write and how the history keeps
alternating. The per-speaker instruction is payload-only -- as a row it could be
dropped from the request by a `created_at` tie, and every later speaker would answer
it. Compaction, titling and the notification are gated to once per turn; `_inject`
is off during a round; the way back gets no tools and a member is treated as
unattended.

Membership stores the model as text with no foreign key: "Test & refresh" deletes
and recreates Model rows, and a cascade would empty the crowd out of every chat.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-26 13:38:52 +00:00
co-authored by Claude Opus 5
parent ac51dd46cc
commit da0797ccad
27 changed files with 3018 additions and 59 deletions
+33
View File
@@ -16,6 +16,39 @@ for 1.0.0 have something to be assembled from.
## Unreleased
## 1.6.0
- **A chat can have a crowd.** Switch it on under Admin → Agents, and each chat's
settings panel offers the other models. The chat's own model answers first, then
each of the others in turn; then the order runs **backwards**, each one asked
whether it disagrees with anything said; and it ends back at the first model,
which either writes the final answer or sends them round again. Every
contribution is its own bubble with its own avatar, its own metrics and a chip
saying which speaker it is and which pass it belongs to.
What it costs is stated where you turn it on and again where you pick the
models, because it is easy to underestimate: one turn is **models × rounds ×
2 − 1** replies, so four models over two rounds is fifteen. On a single local
endpoint every change of speaker also loads a different model. Your own warning
is built into the defaults — larger crowds start going round in circles — so the
round limit is two, and it is a limit ordinary work will reach rather than a
runaway backstop.
Details worth knowing: each model sees the others' answers **quoted and
attributed**, never as its own words, so it can actually disagree with them; a
member you can no longer reach is skipped and said so rather than silently
dropped; a member whose endpoint fails is skipped, and two failures in a row end
the round; **Stop ends the round**, not just the model writing at the time; and
a message typed during a round waits for the round rather than interleaving with
it. Every sentence a crowd sends is editable under Admin → Prompts.
- Fixed: **a schedule that named its own model was ignored.** It was written on
the reply and never sent, so the bubble showed the model you chose while the
answer came from the chat's model. The same fix makes the crowd possible: the
reply itself now says which model is answering, rather than the conversation
deciding for all of them. Regenerating somebody's turn in a crowd keeps that
model rather than silently switching to the chat's.
## 1.5.0
- **A model's personality is now yours, not the instance's.** Each account gets