TAI BUI
Back to curriculum
BuildPython

Theory of Mind and Emergent Coordination

Li et al. (arXiv:2310.10701) showed that LLM agents in a cooperative text game exhibit **emergent high-order Theory of Mind** (ToM): they reason about what one agent believes about a third agent's beliefs. They still fail on long-horizon planning because of context management and hallucination. Riedl (arXiv:2510.05174) measured higher-order synergy across a population and found that **only** the ToM-prompt condition produces identity-linked differentiation and goal-directed complementarity, while lower-capacity LLMs show only spurious emergence. Coordination emergence is prompt-conditional and model-dependent, not free. This lesson implements a minimal ToM-aware agent, runs a cooperative task with and without ToM, and measures the coordination delta in the spirit of the Riedl 2025 protocol.

TIME: ~75 minutesPREREQUISITES: Phase 16 · 07 (Society of Mind and Debate), Phase 16 · 17 (Generative Agents)

Learning Objectives

  • Distinguish zeroth-, first- and second-order Theory of Mind for LLM agents and say what each one lets an agent predict about its peers.
  • Explain why long-horizon ToM degrades (context loss and hallucination) and name the three mitigations.
  • Describe Riedl's three coordination metrics and why they separate real coordination from prompt-dressed illusion.
  • Run main.py, read the duplications and turns for zeroth-order versus first-order agents, and explain why the preference prime drives the delta.
  • Apply the Ship It checklist (control condition, p < 0.05, complementarity, failure log) to audit a claim of emergent coordination.

Problem

Multi-agent coordination often looks magical: agents divide labor, anticipate each other, avoid redundancy. Usually that "emergence" is an artifact of prompt engineering. Someone told the agents to "coordinate," and when you remove the prompt, the coordination goes with it.

Riedl's 2025 finding is stricter. Under controlled conditions, coordination emerged only when agents were prompted to reason about other agents' minds (ToM). Without the ToM prompt, the coordination patterns even strong models showed did not survive statistical controls. This matters in production, because teams ship "multi-agent coordination" features that are prompt-dependent and brittle.

Here I treat ToM as a specific capability (reasoning about beliefs about beliefs), build a minimal ToM-aware agent, and measure what real coordination looks like next to what prompt dressing looks like.

Warm-up0/3
1. In a Generative Agents style simulation, how does one agent come to act on what another agent did?Warm-up
A memory stream of four timestamped observations for an agent, with an arrow down to a dashed box asking how the agent acts on this.
Illustrative observations, typed.
2. In a multi-agent debate (Society of Mind), why does letting each agent read its peers' answers help?Warm-up
Three agents, each with a draft numeric answer, joined by dashed lines showing each can read the other two drafts, with a dashed box below asking whether reading peers helps.
Illustrative draft answers, typed.
3. Why does an experiment that tests a change include a control group that does not get the change?Warm-up
Group A receives a new change, group B receives no change and acts as a control. Both point down to a dashed box asking for the outcome.
Typed sketch, illustrative.
Check: Problem0/1
1. A write-up claims emergent coordination because agents split the work cleanly in the 3 best of 30 runs, and the system prompt says 'work together.' Which two sources of the coordination illusion apply?Analyze
A system prompt that says work together, and a write-up that shows only the best 3 of 30 runs. A dashed box asks which illusion sources apply.
Typed sketch, illustrative.

Concept

What ToM means

Developmental psychology gives the ladder. A 3-year-old thinks anyone's inner world matches theirs. A 5-year-old understands that others hold different beliefs. A 7-year-old can reason about beliefs about beliefs ("she thinks that I think the ball is under the cup"). Those are zeroth-, first-, and second-order ToM.

For LLM agents, the orders map to:

  • Zeroth-order: no model of others. The agent acts on its own observations only.
  • First-order: the agent has a model of each other agent's beliefs. "Alice believes X."
  • Second-order: the agent models recursive beliefs. "Alice believes that Bob believes X."

Li et al. 2023 found that first- and second-order ToM emerge in LLM agents in cooperative games, but degrade over long horizons and with unreliable communication.

The Sally-Anne test, in brief

A 1985 false-belief test: Sally puts a marble in basket A and leaves. Anne moves it to basket B. Where will Sally look when she returns? A child with first-order ToM says basket A, because Sally's belief differs from reality. A child without it says basket B.

GPT-4-era LLMs pass Sally-Anne-style tests when the question is posed plainly. They fail when the narrative is long, the scene changes several times, or the question is phrased indirectly. That is the practical 2026 state of ToM in production LLMs.

Riedl's coordination measurement

Riedl (arXiv:2510.05174) built a population-scale test: N agents, a cooperative objective, variable prompt conditions. It measures three things:

  1. Identity-linked differentiation. Do agents develop stable role distinctions over time?
  2. Goal-directed complementarity. Do agents' actions complement each other (different subtasks) rather than duplicate?
  3. Higher-order synergy. A statistical measure of whether the group achieves what no subset could.

The result: all three metrics produce signal above baseline only under the ToM prompt condition. Without it, metrics hover near chance for moderate-capacity models. Large models show some coordination without explicit ToM prompting, but the effect is smaller than with it.

The coordination illusion

Without statistical controls, "emergent coordination" in demos usually traces back to one of these:

  • Prompt engineering that bakes in coordination (system prompts that say "work together").
  • Observer bias: we see the patterns we expect.
  • Post-hoc selection of successful runs.

Treat a production system that markets "emergent coordination" without a measurable signal as marketing. Measure before claiming.

A minimal ToM-aware agent

Structure:

agent state:
  own_beliefs:    {facts the agent believes}
  other_models:   {other_agent_id -> {beliefs_the_agent_attributes_to_them}}
  actions_last_N: [history of others' actions]

observation update:
  - update own_beliefs from direct observation
  - update other_models[agent_id] from their action + prior beliefs

action selection:
  - enumerate candidate actions
  - for each, predict what each other agent will do next given their modeled beliefs
  - pick action that maximizes joint outcome under those predictions

The other_models attribute is the ToM state. First-order ToM keeps one level. Second-order adds other_models[i][other_models_of_j], which is what I think agent i thinks agent j believes.

Why long-horizon hurts

Li et al. document that context limits make agents forget which belief belongs to whom, and hallucination adds false beliefs to other-agent models. Both produce "I thought he thought X" errors that compound over time.

Mitigations from the paper and from 2024-2026 follow-ups:

  • Explicit ToM state in the prompt. Use a structured format, {agent_id: belief_list}, so retrieval preserves the identity-belief binding.
  • Shorter reasoning chains. Fewer ToM updates per turn means less compounding hallucination.
  • External ToM store. Keep the model outside the LLM context and inject only the relevant parts each turn.

Where ToM fails in production

  • Adversarial settings. An agent with good ToM is easier to manipulate, because you can model what it models of you and exploit that.
  • Heterogeneous teams. When the models differ, a ToM model that works for one opponent does not generalize.
  • Ground-truth-dependent tasks. ToM is about beliefs. If correctness depends on facts, ToM can be a distraction.

The coordination you can actually measure

Three practical signals separate real coordination from the prompt-dressed kind:

  1. Complementarity over time. Over a multi-turn task, do agents' actions cover disjoint sub-tasks?
  2. Anticipation. Does agent A's action at turn T+1 depend on a prediction about B's action at T+2 that turned out correct?
  3. Correction. When A misreads B's belief at turn T, does A correct by turn T+2?

You can measure all three in a logged multi-agent system. They are the substantive version of the "coordination" narrative.

Check: Concept0/21
1. What does Theory of Mind mean for an LLM agent?Define
Agent A holds a box labeled model of a peer with unknown contents, next to a scale marked order 0, 1, 2 plus, and a line asking what the order of Theory of Mind is.
Typed sketch, illustrative.
2. What is the Sally-Anne test?Define
Two panels. First, Sally puts a marble in basket A and leaves. Second, Anne moves the marble to basket B while Sally is away. A dashed box asks where Sally will look.
Typed sketch, illustrative.
3. What is zeroth-order Theory of Mind?Define
Agent C faces three boxes with an arrow to them, a note that it keeps no record of the other two agents, and a note that it has no preference among the three boxes.
Typed, illustrative.
4. What does first-order ToM let an agent represent?Define
Agent A holds a box labeled model of Agent B containing the belief that B believes box 2 has the token. A note says this nested box goes one level, then stops.
Typed, illustrative.
5. What does second-order ToM model that first-order ToM does not?Define
Agent A holds a box for its model of Agent B, and inside that box sits a second box for B's model of Agent C, holding the belief that C believes box 0 has the token.
Typed, illustrative.
6. What does Riedl's identity-linked differentiation metric ask?Define
A grid of three agents by five turns, every cell a dashed question mark, asking whether each agent keeps one role or changes turn by turn.
Typed sketch, illustrative.
7. What does goal-directed complementarity measure?Define
Three agents, each with a dashed row reading targets question mark, and a line asking whether they repeat the same sub-task or spread across three different ones.
Typed sketch, illustrative.
8. What is higher-order synergy in Riedl's measurement?Define
Three solid bars for agent A alone, agent B alone, and A plus B together, next to a dashed full-height bar marked question mark for the full three-agent group, with a line asking whether the group statistically beats every subset.
Typed sketch, illustrative.
9. What is the coordination illusion?Define
A demo box where three agents split the work with no collisions, above three dashed boxes labeled cause 1, cause 2 and cause 3, and a line asking whether there is a measurable signal under controls or one of these causes.
Typed sketch, illustrative.
10. Which long-horizon mitigation keeps the ToM model outside the LLM context?Define
A context window box above three equally styled, dashed cards named explicit prompt state, shorter chains, and external ToM store. A line asks which one lives outside the context window.
Typed sketch, illustrative.
11. Agent A skips task 2 because it saw B working on it, and also skips task 3 because it expects B to assume A will take task 3. Which orders of Theory of Mind does A show?Explain
Three tasks in a row, with Agent B marked at task 2. Below, two dashed boxes ask what Agent A reasons about task 2 and about task 3, and a line says Agent A skips both.
Typed sketch, illustrative.
12. In the Sally-Anne test, a subject says Sally will look in basket A after Anne moved the marble to basket B. What does that answer show?Explain
Basket A is empty and basket B now holds the marble, after it was moved. A subject answers that Sally will look in basket A. A dashed box asks what that answer shows.
Typed sketch, illustrative.
13. In Riedl's population-scale test (arXiv:2510.05174), under which condition do all three coordination metrics show signal above baseline?Explain
A table with two condition rows, no ToM prompt and ToM prompt, and three metric columns all holding question marks.
Typed sketch, illustrative.
14. What causes ToM performance to degrade as a multi-agent task gets longer?Explain
A turn axis marked turn 2, turn 15 and turn 30, with a dashed box below asking what happens to ToM performance as the task runs longer.
Typed sketch, illustrative.
15. Why do Riedl's three metrics separate real coordination from prompt-dressed coordination?Explain
Three gauges, differentiation, complementarity and synergy, each with a dashed line and a reading marked question mark versus the line. A line asks what sets the line and when a reading counts as signal.
Typed sketch, illustrative.
16. Why does a structured ToM state such as {agent_id: belief_list} help on long tasks?Explain
A dashed box listing three beliefs about boxes with no agent names attached, and a line asking which agent holds which belief.
Typed sketch, illustrative.
17. Which of these is NOT one of the three practical signals for measuring real coordination in a logged system?Explain
Four candidate log measurements in dashed rows: complementarity over sub-tasks, anticipation of a peer's move, correction of a misread belief, and total tokens spent per agent. A line asks which one does not show real coordination.
Typed sketch, illustrative.
18. Why can strong ToM be a liability in an adversarial setting?Explain
Agent A models Opponent X well in an adversarial setting, with a dashed box below asking what Opponent X can do with that fact.
Typed sketch, illustrative.
19. An agent's model of its opponent predicts well in tests, but after the team swaps in different base models its predictions of peers fail. Which listed failure is this?Analyze
Agent A's model of Opponent X predicts well in testing. Below, the team swaps in Opponent Y, a different base model, and a dashed box asks what happens next.
Typed sketch, illustrative.
20. You have logs from a 5-agent system and must show its coordination is not prompt dressing. Which measurements do you compute?Design
Six candidate log measurements in a two-column grid: final success rate, average tokens per agent, run-to-run latency, action overlap across agents, prediction of a peer's next move, and fix after a misread belief. A line asks which three show real coordination.
Typed sketch, illustrative.
21. You are building a 6-agent negotiation over 30 turns, and the agents keep mixing up who believes what. Which design uses the lesson's mitigations?Design
Four candidate designs in dashed rows: paste full history into every prompt, external structured store with per-turn injection, second-order ToM for every pair, and dropping ToM entirely. A line asks which design fixes agents mixing up who believes what.
Typed sketch, illustrative.

Build It

code/main.py implements:

  • ToMAgent (the Agent dataclass in the file), which tracks a list of observations of the other agents.
  • A cooperative task: three agents must collect three tokens from three boxes, and each box holds one token. Agents cannot communicate. They infer intent from each other's actions.
  • Two configurations: zeroth_order (no ToM, picks uniformly among remaining boxes) and first_order (ToM, avoids boxes it saw others target recently).
  • Measurement over 200 randomized trials with a 10-turn budget: full completions, duplications per trial (extra agents targeting a box someone else also targeted), and average turns to completion.

Run:

python3 code/main.py

On my run, the zeroth-order agents averaged 0.96 duplications per trial and 1.85 turns, and the first-order ToM agents averaged 0.00 duplications and 1.00 turns. Both configurations completed 200 of 200 trials inside the budget, so completion rate does not separate them here. Duplications and turns do, and that gap is the measurable coordination effect.

Check: Build It0/7
1. main.py runs 200 trials per configuration, and the zeroth-order agents average 0.96 duplications per trial. About how many duplications is that in total?Apply
A line reading zeroth-order agents 0.96 duplications per trial, times 200 trials, with a dashed box asking for the total.
Mean duplications per trial from running main.py (200 trials).
2. In main.py with 3 agents and 3 boxes, each ToM agent is told every other agent j prefers box j % 3. Which box does agent-1 target on turn 0?Apply
The priming rule, agent j prefers box j mod 3. Agent-0 is given box 0 and agent-2 is given box 2. A dashed box asks which box agent-1 targets.
Priming rule from main.py's run_trial.
3. On one turn the commitments are agent-0 to box 2, agent-1 to box 2 and agent-2 to box 2. What does the collision code do?Apply
Agent-0, agent-1 and agent-2 all commit to box 2 on the same turn. A dashed box asks how many duplications this adds and who collects the box.
Scenario from the question.
4. On one turn the commitments are agent-0 to box 1, agent-1 to box 1 and agent-2 to box 0. After resolution, how many agents have collected and what was added to duplications?Apply
Agent-0 and agent-1 both commit to box 1, while agent-2 commits to box 0. A dashed box asks who collects and how many duplications this adds.
Scenario from the question.
5. If you comment out the loop in run_trial that primes ToM agents, what does a ToM agent do on turn 0?Apply
The priming loop in run_trial commented out and marked disabled. A dashed box asks what a ToM agent's turn-0 choice becomes.
Code structure from main.py's run_trial.
6. Why does the first-order delta in main.py say little about reasoning ability?Analyze
run_trial starts and a dashed box asks what happens before turn 0. Below, the two benchmark results are listed, and a line asks whether the gap comes from reasoning.
Benchmark numbers from running main.py.
7. A reviewer says: 'Both agent types completed 200 of 200 trials, so ToM changed nothing in this experiment.' What is wrong with that reading?Analyze
Zeroth-order and first-order ToM both show full-completion 200 of 200. A reviewer claims this means ToM changed nothing. A dashed box asks what the claim misses.
Completion counts from running main.py.

Use It

outputs/skill-tom-auditor.md is a skill that audits a multi-agent system's claim of "emergent coordination." It checks for prompt dressing, statistical significance against a control, and measured complementarity.

Ship It

Coordination claims checklist:

  • Control condition. Run a version of your system without the coordination prompt and measure both.
  • Statistical test. Is the difference between system and control significant at p < 0.05 on your metric?
  • Complementarity measure. Track action-disjointness over time, not just final success.
  • Failure-case log. When agents miscoordinate, what does the ToM state look like?
  • Model-capacity disclosure. If the effect vanishes on smaller models, say so.
Check: Ship It0/2
1. Why does the Ship It checklist ask you to disclose model capacity?Explain
The five-item Ship It checklist with the last item, model-capacity disclosure, drawn dashed, and a line asking why it is required.
Typed sketch, illustrative.
2. A vendor demo shows three agents splitting a task cleanly and calls it 'emergent coordination.' Using the Ship It checklist, what should you ask for first?Design
A vendor demo where three agents split a task, called emergent coordination, next to the five dashed Ship It checklist items. A line asks which to ask for first.
Typed sketch, illustrative.
Author's Note

I'd run main.py first and read the two result lines before the theory. Zeroth-order agents show 0.96 duplications per trial and 1.85 average turns, first-order agents show 0.00 and 1.00, and both finish 200 of 200 trials. Since completion is identical, the whole effect lives in duplications and turns. That is why I'd log those two instead of a success rate on a task this small.

The part I'd look at hardest is the prime. In run_trial, each ToM agent is handed the other agents' preferred boxes before turn 0, and with three agents and three boxes that is enough for each one to leave exactly one box open for itself. Comment that loop out and a ToM agent's first turn is a uniform draw, the same as the zeroth-order agent's. So the delta here comes from information the ToM agents were given, not from reasoning they did.

I'd also keep the scope honest. These agents are a few lines of rules with no LLM and no prompt condition, so this demonstrates the shape of a control-versus-treatment measurement and nothing about whether Riedl's result holds for your model. To learn that, you need the same comparison run on real agents, with the statistical test from the Ship It checklist on top.

Exercises

  1. Run code/main.py. Confirm first-order ToM cuts duplications per trial from 0.96 to 0.00 and average turns from 1.85 to 1.00. Does the gap persist when you scale to 5 agents and 5 boxes?
  2. Implement second-order ToM (agent A models what B thinks about C). Does it improve over first-order? On what tasks?
  3. Inject a hallucination into the ToM state: randomly flip one belief per turn. How much does this degrade first-order performance?
  4. Read Li et al. (arXiv:2310.10701). Reproduce the "long-horizon degradation" finding: as turns grow from 10 to 30, how does your first-order ToM performance change?
  5. Read Riedl 2025 (arXiv:2510.05174). Implement the higher-order synergy statistic on your simulation logs. Is the effect present without the ToM prompt condition?

Key Terms

TermWhat people sayWhat it actually means
Theory of Mind"Understanding others' minds"The capacity to model another agent's beliefs. Graded by order (0, 1, 2+).
Sally-Anne test"The false-belief test"1985 developmental psychology; LLMs pass plain versions, fail complex ones.
First-order ToM"A believes X"Modeling one other's beliefs about facts.
Second-order ToM"A believes B believes X"Recursive modeling one level deeper.
Identity-linked differentiation"Stable roles over time"Riedl's metric: roles persist, not random.
Goal-directed complementarity"Disjoint actions"Agents target different subtasks, not the same one.
Higher-order synergy"Group exceeds any subset"Riedl's statistical measure for real coordination.
Coordination illusion"It looks coordinated"Prompt-dressed appearance of coordination without measurable signal.

Further Reading

Code

Ships With