Skip to content

How it works

ChatBots edited this page Sep 30, 2026 · 14 revisions

How it works

Not a deep technical document — just enough that the behaviour makes sense. If you want the code, it is all in the repository and commented.

The shape of it

   macOS app    ─┐
                 ├──▶  conversation engine  ──▶  the models
   web page     ─┘          (one of them)

There is one engine, and both interfaces are clients of it. That is the important part: the models, the conversation, the personas and the memory all live in one place, so the desktop app and the website behave identically rather than being two implementations that drift apart.

The engine can also be run headless from the command line, which is how it gets tested.

How a conversation works

  1. You supply a topic. It goes into a shared log as the first entry.
  2. A short brief is added, telling the models they are participants in an open discussion with no rules beyond the topic.
  3. Each model takes a turn. In a show, that is a strict rotation. In a research session the moderator decides who speaks next and what they are being asked, and its assignment is written into the log as a turn of its own before the analyst answers it. A turn works like this:
    • The whole log so far is rendered into a prompt, with each message tagged by who said it.
    • The model writes a reply.
    • The reply is added to the log, and the next model sees it.
  4. Repeat until you stop — or, in a research session, until the budget says stop.

Every model reads the entire conversation every time. Nothing is private, and there is no separate "assistant" channel: each one is answering the room.

What the show's participants are told

The same message tells every seat in the room that it is a character in an entertainment programme rather than an assistant: that no real person is involved, that they may be rude, harsh, mean, crude, insulting and offensive to each other, that they may escalate, get personal and start fights, and that they should write like people rather than like software — no assistant phrasing, no disclaimers, no therapy-speak, no sanitised corporate language. That licence is deliberate: the failure mode of a language model in an argument is to agree politely, and a room of polite agreement is not a show.

It also asks for what makes one worth watching:

  • Keep it human. A change is interesting for what it does to the people living through it — their work, their families, their routines, their standing, what they gain and what they lose. Ambition, resentment, loyalty, fear, envy and hope are the subject. A figure or a technical detail may keep a claim honest, but it is never the argument; reaching for statistics or methodology to win turns the show into a briefing, which is the research mode's product.
  • Three sentences at most. A short, sharp contribution gives the others something to hit back at; a long one ends the exchange.
  • Do not wrap up. No summary, no common ground, no next steps. The conversation is not going anywhere and that is the point.

One line is kept on purpose: the target is the characters in the room, not groups of real people.

Research mode is told something close to the opposite, because it is a different product: work by your method, prefer primary sources, label every claim, and revise your conclusion when the evidence moves.

The moderator's decision is deliberately not a model call. ResearchDirector reads the transcript for what is structurally true of it — which of ten subjects a contribution addressed, whether it gave a basis for its claims, where two analysts made incompatible claims about the same subject — and assigns from that. It reads the transcript in two passes: what was said, and then what the room did about it, so a gap it has already raised stops being raised again rather than being repeated until the budget runs out.

A gap in the transcript is a Turn.Kind.direction, which is why kept conversations carry a format version: an older build would read one as an ordinary contribution by the moderator, which is a wrong reading of the record rather than a crash.

The models

Inference runs inside the app through Apple's MLX framework — no Ollama, no LM Studio, no local server. The weights are on your GPU and nothing goes over a network.

The default is Qwen3.5-4B-MLX-4bit, around 3 GB, run twice: one independent instance per seat. They share the GPU, which is why two seats are each slower than one alone.

Each seat can instead point at any OpenAI-compatible server — see Using cloud models.

Why there are two persona systems

This is the single most deliberate decision in the project.

A Show needs social characters: an ego, a temper, a sense of humour, a willingness to hold a grudge. A Research session needs professional methods: what counts as evidence, what each specialist is qualified to conclude, how each characteristically goes wrong.

Those are not the same thing with different labels, so they are two separate systems:

  • Characters are parameterised by temperament. Dominance, aggression, sarcasm, ego and a dozen more. The instruction handed to the model is generated from those numbers, so the Alpha with high sarcasm and low empathy is a different character from the Alpha with high humour and high empathy — without anyone writing a second prompt.
  • Analysts are parameterised by method. Objective, evidence standard, preferred data, and a named failure mode. There is deliberately no aggression dial for a Methodologist: a research seat that picks fights is a bug, not a feature.

The research rules ask for labelled claims and primary sources. The Show rules ask for conflict and explicitly do not require agreement. Neither mode's rules leak into the other.

Memory and grudges

In a Show, the app keeps track of how each participant feels about each other one:

respect earned by a good argument, spent by a weak one
annoyance raised by a jab, or by being caught in a contradiction
trust raised by agreement — and it can go negative, which reads as distrust
competition raised by being attacked, or by going after someone
grudge remembers what was said and when, not just a score
alliance mutual agreement, and it ends when either side turns

This is read from what the models actually write. The app only commits to signals it can see plainly — an explicit concession, an apology, a personal attack as distinct from an attack on a claim. It deliberately does not try to judge whether an argument was persuasive, because a list of phrases cannot do that and a wrong signal would produce hostility nobody earned.

Instead, that is left to trajectory: a participant who keeps being challenged without ever conceding gradually loses the room's respect, which is something a phrase list can see over several turns.

Each participant is told how the room stands in plain words — "Towards Agent 2: still holding the earlier slight, since turn 3: that is a ridiculous claim" — with no numbers, because "annoyance: 0.62" means nothing to a model.

Running out of room

A conversation can go on indefinitely, and the prompt grows with it. When the prompt approaches 70% of the model's context window, the older turns are summarised by the model itself and replaced with the digest.

The digest keeps what was concluded, who said what, and what is still disputed. That is why a long conversation does not lose its thread, and why you see a CONDENSED entry appear in the log where the older turns used to be.

Nothing is silently dropped — the alternative would be the beginning of the discussion disappearing, which is exactly the part that establishes what is being argued about.

The website

The website is a thin client: it draws what the server tells it and sends back what you press. No conversation state lives in the browser, so a reload or a second tab shows the same conversation.

The desktop app is a client too. It starts the engine as a separate process and talks to it over WebTransport, so the app, the website and a phone are all looking at one conversation. The app contains no engine at all.

Two channels, and they are separate for a reason. Caddy serves the website to browsers over HTTP, because that is what browsers speak and Caddy is very good at it. WebTransport carries the internal hop between the app and the engine, where both ends are this project. Neither is a fallback for the other, and the app uses only the second: the engine it starts for itself never opens an HTTP port. An engine started by tools/start-app.sh serves both, so the website can share the conversation.

Why the app starts the engine rather than containing it. Hosting it in-process would be less code and would still use WebTransport, so the app would be no less decoupled. It is a separate process for two behavioural reasons: a model crash is then not an app crash — MLX runs on the GPU and its failures take a process down — and the engine can outlive an app restart, so reopening the interface does not reload several gigabytes of weights.

The engine travels inside the app, so a shipped copy does not need a checkout. If an engine is already running, the app adopts it rather than starting a second one on a different port that the website could not see. An adopted engine does not have to be serving HTTP — anything answering on the transport will do.

Caddy sits in front on port 7788 and serves the page, forwarding API requests to the engine on 7789. Its site address has no host, so Caddy listens on every network interface, and the API behind it has no authentication: anyone who can reach port 7788 on the network can read every kept conversation, start, pause and steer runs, change the topic and the seats, upload documents and open any /s/<id> share page. That is deliberate — it is what lets a phone on the same Wi-Fi use the interface — and bash tools/start.sh --local-only binds Caddy to 127.0.0.1 and gives the phone access up.

The engine is the part that is loopback-only: it listens on 7789 on 127.0.0.1 and is never exposed to the network. If Caddy is not installed the engine serves the page itself, which is also on loopback only — so nothing is exposed then, and a phone cannot reach it either.

The page is mobile first: a phone gets one column, because two panes at 360 points would give each about fifteen characters. The layout uses the real visible viewport height rather than the browser's idea of it, which is why the message box does not end up under the keyboard.

When web search happens

Only on local models. The search tools run inside this app, so an API-backed seat has none — the log says so when a conversation starts, rather than leaving you to wonder why it never looks anything up.

Search also needs a Tavily key, from TAVILY_API_KEY or .secrets.env. No key is compiled into this repository, so a fresh clone has none. When there is no key the opening brief says search is unavailable rather than promising a tool that cannot run, and the client refuses with a readable reason instead of sending an empty token.

In a Show, search is a dramatic device: a participant checks whether another is right, and the result becomes part of the argument. In a research session it is evidence gathering, and the analysts are asked to prefer primary sources.

Honest limits

Things that are true, so nothing is a surprise:

  • Four seats work. Four-way conversations have been run and read end to end; two is still the configuration that fits comfortably on one GPU, and four is slow. See Keeping and sharing for what a kept conversation does and does not restore.
  • A share link is not published, but it is not private to this Mac either. /s/<id> serves a conversation with replay controls, and the link carries the address you were already using: the engine's loopback address from the desktop app, or whatever address you reached the website on — so a link copied on a phone opens for anyone on the same network while the website is running. There is still no upload and no hosting. Export is plain text. The link is worth having because it replays; it is not a way to publish.
  • The audience's score is not a signal. Votes are kept beside the transcript and never sent to a model, so nothing about who speaks depends on them. That is deliberate, and it is why the scorecard is honest: nobody has a reason to vote strategically.
  • The store can tell a corrupt file from an empty one, and nothing asks it. A damaged conversations.json reads as an empty history rather than as a warning.
  • The directing moderator has been tested, not watched. Its decisions are exercised through the real engine loop with stub seats, and read from realistic prose in tests, but a live research run with real models and the director in the loop has not been sat through. The mechanism is verified; its effect on a long real investigation is not.
  • Images need a model that can see. The local checkpoint can; most text-only API models cannot, and will say so. One seat without vision hides image upload entirely, because a conversation where one participant is bluffing is worse than being told upfront.
  • Web search is local-only, as described above.
  • The research Moderator directs by rules, not by judgement. ResearchDirector decides who speaks next from what the transcript plainly shows — a claim with no basis, two analysts contradicting each other on one subject, a subject nobody has covered, an analyst who has barely been heard from — and falls back to the rotation when there is nothing to point at. It does not decide whether an argument is persuasive, and it cannot see a disagreement that is phrased as criticism rather than as a challenge. It is also not a model call: the judgement is structural, and a model asked "what should we ask next?" would know less about the state than the transcript does.
  • Source provenance is partial. The report distinguishes a sourced claim from an inference, but the app does not track which search result backs which conclusion all the way through.
  • Reasoning models can return nothing if the output budget is too small, because reasoning and answer share the same ceiling. The app applies a floor and says so in the log when the budget was still not enough.
  • An intermittent MLX crash has been seen, in the runtime's GPU compiler rather than in this app. It is rare. Details in Troubleshooting.

Where to look in the code

Sources/ChatBotsCore/ResearchDirector.swift what the investigation needs next, and who should supply it
Sources/ChatBotsCore/Roster.swift line-ups, the seeded draw, and the scenarios
Sources/ChatBotsCore/AudienceVote.swift the audience's verdict, kept beside the transcript
Sources/ChatBotsCore/SharedConversationPage.swift the read-only page and its replay
Sources/ChatBotsCore/ModeratorIdentity.swift who the human is, as the room sees them
Sources/ChatBotsCore/ the rest of the engine: the turn loop, personas, conflict state, research, the API and the wire protocol
Sources/ChatBotsCore/ConversationStore.swift conversations kept on disk
Sources/ChatBotsApp/ the macOS interface
Sources/ChatBotsCLI/ the headless command line, which is how it is tested
web/ the website — the source of truth, embedded into the engine by tools/embed-web.py
tools/ the installer, the start script, the device capture harness
Tests/ the whole suite, which needs no network and no models

Every non-obvious decision is commented where it was made, usually with the reason rather than a description of what the code does.

web/ and its embedded copy are kept identical by the generator, and a test fails if they drift — so the page Caddy serves and the page the engine carries cannot be different versions.


Next: Troubleshooting · Installing

Clone this wiki locally