Part of the project Theory of mind for robots with behaviour trees · code

Written in November 2026, looking back at a course project our team completed in spring 2024 at Carnegie Mellon University Africa. The post is dated to when the work was done.

When you hand someone a tool, you don’t wait to be asked. You notice where they’re looking, guess what they’re about to do, and adjust. Psychologists call this ability to reason about other people’s beliefs, goals and feelings theory of mind. Robots, for the most part, don’t have it. They follow their programme and react to what is directly in front of them.

In spring 2024, Hubert Apana, Ibrahim Olaide Jimoh and I asked how far we could push one of robotics’ most practical control tools in that direction. This post is the sequel to our earlier project on ethically responsible robots, where one of the open questions was exactly this: a robot should understand what a person means before it decides how to act.

Why behaviour trees

Behaviour trees are a way of organising what a robot does. Small actions (“go to this spot”, “look for the cup”) are arranged in a tree, and control nodes decide which branch runs: a sequence runs its children in order, a fallback tries alternatives until one works. They became popular in video games and are now widely used in robotics because they are modular, readable and easy to debug (Colledanchise & Ögren).

Their weakness is that the tree is usually fixed. It reacts to the world, but it has no notion of the person in it: what they want, whether they’re in a hurry, whether they’ve noticed the robot at all.

What we designed

Diagram of a behaviour tree with four search branches, a belief-update step, and a proposed theory-of-mind layer that infers a person's state and re-weights branches

Our idea was to give the tree a model of the person, drawing on early work on theory of mind for humanoid robots by Brian Scassellati and on research into robots and humans adapting to each other:

  1. Read cues. Gaze, gestures, tone of voice, words and movement.
  2. Infer a state. Use Bayesian inference to keep a running estimate of the person’s likely goal, attention, emotion and next move.
  3. Adapt the tree. Re-weight which branch the tree prefers based on that estimate: wait, give way, offer help, explain, or carry on.
  4. Learn. Use reinforcement learning to tune those adjustments over many interactions, then test them with people against a fixed tree.

What we actually built

In the time we had, we built the first, simpler layer: a tree that updates its own beliefs as it learns about the world. Using ROS and the Gazebo simulator, building on Sebastian Castro’s open TurtleBot3 behaviour-tree demos, a small robot searched a set of rooms for objects. A fallback node chose between four search branches. After the robot found the first object, it updated its beliefs about where the others were likely to be and re-ordered its search, which got it to the remaining objects faster.

Screenshot: the behaviour tree in Groot above the Gazebo world and RViz map as the robot approaches the first object
The live behaviour tree (top) with the Gazebo world and the robot's map (bottom) as it approaches the first object.

We also ran a small preliminary comparison across five scenarios, from a static box to a crowded room, with one run each. The adaptive tree completed all five; a fixed tree completed two, colliding with a moving person and freezing in the crowd. The adaptive tree was slower on average when both succeeded (21.6 s against 16.5 s), largely because it took more cautious routes. With one run per scenario, that is an encouraging sign, not evidence.

Screenshot: the behaviour tree and Gazebo simulation as the robot approaches the third object

The code is on GitHub, maintained by Hubert.

What we learned

  • The plumbing is the hard part. Getting a tree to update itself cleanly inside ROS took most of our time. The theory-of-mind layer, the part that models the human, stayed on paper.
  • “Social” needs a social scenario. A robot searching empty rooms can show belief updating, but not theory of mind. You need a simulated person with a hidden goal for the robot to infer.
  • Faster isn’t the only measure. A robot that slows down around people may be doing exactly the right thing. Metrics need to include safety and how comfortable people feel, not just time.
  • Small tests flatter. Five scenarios with one run each can’t separate a good design from a lucky run.

What it would take to make this real

  1. Add a person to the simulation. A simulated human with a hidden goal, such as walking to one of several doors, so the robot has a mind to model.
  2. Build the inference step. Estimate the person’s goal from their path and heading, and let that estimate change which branch the tree runs: wait, give way, or move ahead.
  3. Test it properly. Many randomised runs per scenario, with a fixed tree, a belief-updating tree and the full theory-of-mind tree compared side by side, measuring success, time, collisions and distance kept from people.
  4. Ask people. Show short videos of each robot and ask viewers which one seemed more aware and comfortable to be around.
  5. Move to a real robot. Run it on a physical platform, such as the Pepper robot we originally had in mind, with real participants.

I’m interested in picking this up again, especially for robots that work alongside people in African settings, where crowded, shared spaces are the norm. If you work on social robotics or human-robot collaboration, I’d love to compare notes.


Team: Isaac Thani, Hubert Apana and Ibrahim Olaide Jimoh, Carnegie Mellon University Africa.

Code: hubiverse/bt-robot, built on sea-bass/turtlebot3_behavior_demos.

Further reading: Colledanchise & Ögren, Behavior Trees in Robotics and AI · Scassellati, Theory of Mind for a Humanoid Robot · Nikolaidis et al., Formalizing human-robot mutual adaptation (HRI 2016).


Views here are my own and do not represent Carnegie Mellon University Africa, my collaborators or funders. Posts on health topics are for general information, not medical advice.

Cite this post

Thani, I. (2024, April 30). Robots that keep a model of the people around them. Isaac Thani. https://zikt.github.io/research/2024/04/30/robots-that-model-the-people-around-them/

@misc{thani2024robotsthatmodelthepeoplearoundt,
  author       = {Thani, Isaac},
  title        = {Robots that keep a model of the people around them},
  year         = {2024},
  month        = {apr},
  howpublished = {\url{https://zikt.github.io/research/2024/04/30/robots-that-model-the-people-around-them/}},
  note         = {Blog post}
}
Share