Language Models Solve a Classic Theory-of-Mind Task Using Domain-General Mechanisms for Divergence Detection

Idil Karen Sahin, Taylor Whittington Webb, Steven M FranklandNeurIPS 2026

TL;DR

When Large Language Models (LLMs) ace classic "Theory of Mind" tests—figuring out that a story character holds a false belief—are they using specialized social-reasoning circuitry, or just reciting memorized story templates? Neither, it turns out: they solve these puzzles using a reusable, domain-general state-tracking mechanism. Remarkably, the exact same internal attention heads that track whether a character’s belief is outdated also fire to track outdated photographs and copied versus aliased variables in Python code.

What Problem Does This Paper Address?

In humans, reasoning about other people’s mental states (Theory of Mind, or ToM) relies on dedicated brain regions, like the right temporoparietal junction, which light up specifically for mental states rather than non-mental representations like outdated maps or photos.

Today’s LLMs routinely pass classic false-belief tests (e.g., Sally puts a marble in a basket and leaves; Anne moves it to a box; where will Sally look?). Yet behavioral accuracy alone can’t tell us how they do it. Because these stories are ubiquitous in training data, models might just be matching superficial text templates—an idea bolstered by how easily LLMs fail when stories are slightly tweaked. Conversely, they could have developed specialized "mentalizing" circuits, or they might rely on general-purpose state-tracking machinery. The authors crack open the black box to find out which hypothesis holds up.

Methods

Focusing primarily on Qwen2.5-14B-Instruct (with key replications in Gemma-2-27B-it), the authors use causal mediation analysis (activation patching). By running the model on carefully matched pairs of prompts and swapping the output of individual attention heads from a source prompt into a target prompt, they measure each head's exact causal contribution to shifting the model's final answer. Averaging these effects across every attention head creates a condition "fingerprint."

Beyond passive observation and single-head patching, they use activation steering—injecting mean-difference vectors from one domain (like Python code) into another (like belief stories) to test if causal signals transfer across domains—and Representational Similarity Analysis (RSA) to inspect the geometry of what these heads actually encode.

Figure 1: Mechanism. Alice looks away (blue) or keeps looking (orange); the dashed outline marks the move she misses in the blue case. At the query token, mid-layer divergence heads signal whether her belief has diverged from the world. Later re- trieval heads attend to the original or the updated location.

Datasets

Rather than relying on off-the-shelf benchmarks where variables are easily confounded, the authors built a controlled suite of matched prompt pairs across three structurally parallel domains:

  • Beliefs: Scenarios (food truck, hair styling, library book) where an agent either sees an update or misses it.
  • Photographs: Non-mental stories where a photo is taken either before or after the world changes.
  • Python Code: Programs manipulating lists where a variable is either copied (b = a.copy(), keeping the old value) or aliased (b = a, updating with the change).

Prompts were paired to isolate three conditions: changing only whether the representation diverged from reality (divergence-change), changing only the final answer (answer-change), or changing both (dual-change), alongside a belief-free state-only control (48 experimental cells total, with 129–198 valid pairs per cell).

Figure 2: (a) Experiment domains. Each prompt forms a representation, changes the world and queries the representation. (b) The three condition types, shown on the belief example. For each attention head, its output on the source prompt replaces its output on the target prompt; if the head carries the relevant property, this moves the model’s answer to the causal answer in the black box.

Key Insights and Ideas

  • Divide, Conquer, and Compose: False-belief reasoning splits cleanly into two sequential, modular stages. Mid-layer "divergence heads" detect whether a representation is out of sync with the current world, while late-layer "retrieval heads" fetch the actual answer token. Their effects are cleanly additive.
  • Mentalizing is Treated Like Variable Aliasing: Unlike the human brain's specialized social circuitry, the LLM’s divergence detector is completely indifferent to what is diverging. Checking if Alice missed a moving truck uses the exact same circuitry as checking b = a.copy() in Python.
  • Abstract Pointers via Indirection: Divergence heads don't store the answer, nor do they hardcode a specific token index. Instead, they write an abstract role signal ("fetch the stored value" vs. "fetch the current value") into the residual stream, which steers where downstream retrieval heads pay attention.

Key Results

  • Distinct, Additive Circuits: In Qwen2.5-14B, divergence heads cluster in layers 29–35 and retrieval heads in layers 36–46, with minimal overlap ($r = 0.209$ raw correlation). Summing the single-change fingerprints predicts the dual-change fingerprint with $r = 0.980$ in Qwen (and $r = 0.986$ in Gemma).
Causal mediation heatmaps across layers and heads showing distinct clusters
  • Cross-Domain Overlap & Steering: Divergence fingerprints correlate strongly across belief, photo, and code tasks ($r = 0.76$ to $0.90$). Steering the 22 belief-divergence heads on belief prompts using directions extracted from photographs shifts the answer margin by $+23.2$ logits, and Python code directions shift it by $+15.6$ logits—rivaling the $+20.9$ logit shift from belief-derived directions themselves.
  • Attention Redirection & RSA: Injecting or subtracting the divergence vector right before the retrieval layers flips where retrieval heads attend—for instance, shifting attention on false-belief prompts away from the old location ($11.5\% \rightarrow 7.3\%$) toward the current one ($3.5\% \rightarrow 9.6\%$). RSA on Python prompts confirms divergence heads match an abstract copy-vs.-alias model (Spearman $r = 0.85$), while retrieval heads match answer identity ($r = 0.46$).

Limitations and Future Work

  • Simple Task Topologies: The study only examines single-update, first-order false beliefs across simple templates. It doesn't test desires, intentions, repeated updates, nested beliefs ("Alice thinks Bob thinks..."), or complex adversarial stories where LLMs often break down.
  • Two-Candidate Ambiguity: Because prompts only feature two candidate locations, an "abstract pointer" is hard to strictly separate from a simple binary query bias. Future work will need 3+ locations or multi-agent bindings to tease these apart.
  • Model Scope: Experiments were limited to two mid-sized, instruction-tuned models; whether these circuits emerge during pretraining or post-training, and how they scale, remains open. Finally, finding a shared domain-general circuit doesn't prove that no belief-specific circuits exist elsewhere in the network.

Summary updated

Abstract

Large Language Models (LLMs) successfully solve tasks that require reasoning about the truth or falsity of an agent's beliefs, classically used to assess whether a system has theory of mind. However, how LLMs solve these tasks remains unclear. Do they deploy circuitry specialized for reasoning about other minds, memorize common false-belief vignette structures and outputs, or rely on more domain-general computations? We investigate this question primarily in Qwen2.5-14B-Instruct, with selected analyses in Gemma-2-27B-it, using causal mediation and representational similarity analyses across matched prompt sets. A population of mid-layer attention heads tracks divergence between a representation and the current state of the world. A distinct population of later-layer heads retrieves the answer token, and the two populations combine compositionally to determine the output. Notably, this signature holds across structurally similar tasks that differ heavily in content: tasks that require no perspective-taking (true vs. false photographs) and tasks that neither describe situations nor use natural language (aliasing vs. copying variables in python code). These findings show the importance of domain-general contributions to classic false-belief performance in LLMs, while leaving open additional belief-specific computations.
BibTeX
@inproceedings{sahin2026language,
  author = {Idil Karen Sahin and Taylor Whittington Webb and Steven M Frankland},
  title = {{Language Models Solve a Classic Theory-of-Mind Task Using Domain-General Mechanisms for Divergence Detection}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=z3sn6b2Hk3},
}
Figure