{'fraction_non_alphanumeric': 0.03430189866778559, 'fraction_numerical': 0.011014371131857758, 'mean_word_length': 4.713144226927687, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Emergence of Theory of Mind Collaboration in Multiagent Systems

Currently, in the study of multiagent systems, the intentions of agents are usually ignored. Nonetheless, as pointed out by Theory of Mind (ToM), people regularly reason about other's mental states, including beliefs, goals, and intentions, to obtain performance advantage in competition, cooperation or coalition. However, due to its intrinsic recursion and intractable modeling of distribution over belief, integrating ToM in multiagent planning and decision making is still a challenge. In this paper, we incorporate ToM in multiagent partially observable Markov decision process (POMDP) and propose an adaptive training algorithm to develop effective collaboration between agents with ToM. We evaluate our algorithms with two games, where our algorithm surpasses all previous decentralized execution algorithms without modeling ToM.


Introduction
Developing effective collaborations in a multiagent system (MAS), when there are more than one learning agents, is a challenging problem. Modeling the joint action for all agents enables single agent reinforcement learning (RL) algorithms to be applied to MAS directly, however, the joint action space grows exponentially as the number of agents increases. Decentralized execution and centralized training algorithms aim to cope with this complexity restriction [1,2,3,4], where agents learn policy mapping from local observation history to actions through a centralized critic. Nevertheless, two difficulties need to be addressed in current approaches. First, simultaneous agents updates will cause non-stationary environments and impinge the convergence of these algorithms [5,3,4,6,7]. Second, because a MAS is partially observable to all agents, they must infer each other's mental status to effectively coordinate with each other, either with or without communications. For example, it is important for a group of item collecting robots to infer each other's current target, otherwise, there could be robots aiming for the same item or items collected by no one.
It has been shown that humans, during an interaction, can reason about others' beliefs, goals, intentions and predict opponents/partners' behaviors, a capability called Theory of Mind (ToM) [8,9,10]. In some cases, people can even use ToM recursively, and form beliefs about the way others reason about themselves [11]. Thus, to collaborate and communicate with people smoothly, artificial agents must also bear similar potentially recursive mutual reasoning capability. Despite the recent surge of multiagent collaboration modeling [12,2,13,7], integrating ToM is still a nontrivial challenge. A few approaches attempted to model nested belief of other agents in general multiagent systems, but extensive computation restricts the scale of the solvable problems [14,15]. When an agent has an incomplete observation of the environment, it needs to form a belief, a distribution over the actual state of the environment, to take actions [9,15]. ToM agents, besides their own beliefs about the state, also model other agents' beliefs, forming belief over beliefs. They can further have beliefs about others' belief over belief, so on and so forth [14,16,9,11,17]. The intractability of distribution over distribution makes exact solving for ToM agents' nested beliefs extremely complicated [14]. Therefore, an approach to acquire the sophistication of high-level recursions without getting entangled into the curse of intractability is needed.
In this paper, we propose an adaptive training process, following which effective collaboration can emerge between agents with ToM by only modeling one level belief over belief. The complexity of higher level recursions can be preserved by the dynamic evolving of agents' tractable belief estimation functions. Intuitively, for a given agent, we don't simulate its behavior by assuming it has a certain level of recursions, which requires modeling nested beliefs all the way up to the desired level [14,16,11,17]. We directly learn a function to approximate its actual belief and how to react accordingly. In cooperative games, this learning becomes mutual adaptation, with controlled exploration rate, improving the performance of the multiagent system [18]. Also, in our adaptive training procedure, one agent is trained while the other being fixed, creating a stationary environment for the learning agents. Hence, our algorithm won't be influenced by non-stationarity.
To justify the advantage of ToM agents, we evaluate our algorithm in two-player imperfect information games. In these games, there is a public game state available to all players, and each player has a piece of private information. Each agent maintains a belief about its partner's private state and an estimation of its partner's belief about its private state, namely a belief over belief. The belief over others' private information is obtained with counterfactual reasoning [19,6]. The estimation of the partner's belief about one's private information is learned in centralized training, during which agents share their beliefs to others as supervision. We test our algorithms in two multiagent POMDPs. The first is inspired by the robot-human collaboration in the kitchen setting proposed by Fisac et al. [19] The second game simulates an appointment scheduling process between two agents, each of whom has private time schedules and wants to choose a commonly available time slot to have a meeting. By regulating the message space of the agents, this game becomes a nontrivial POMDP, requiring mutual reasoning to accomplish.
We compared our adaptive ToM algorithm with several popular multiagent benchmarks using various flavors of policy gradients [20] and Q-learning [21], and achieved robust performance close to SOTA models, which are not only trained in a centralized way, but also have centralized modules like shared Q-functions [19,7] or meta-agent [6]. Moreover, we found that ToM can facilitate the emergence of more universal protocols decipherable across different groups. Our model beats all benchmarks with a large margin in flexible group assignment experiments.

Related Work
Most multiagent RL algorithms have their single agent origins [22]. The main challenge of generalizing single agent methods to MAS is the trade-off between complexity and optimality. Centralized execution methods guarantee optimality, but have exponential complexity wrt. the number of agents, while decentralized execution sacrifices performance for simplicity. Thus, the idea of centralized learning but decentralized execution finds its balanced position. Independent Q-based algorithms in MAS, from early works investigating small scale multiagent tabular games [23,24] to a multiagent generalization of DQN [5,25] on large-scale state and action spaces, emphasize decentralized execution. However, the non-stationarity caused by simultaneous agents' updates casts a shadow on the convergence of these algorithms. To relieve the non-stationarity, Foerster et al. [3] proposed stabilizing experience replay by memorizing fingerprints of opponents' policies. Another stream of multiagent algorithms originates from the actor-critic method [4,7]. They learn a decentralized policy guided by a centralized Q-function. However, the large variance of the policy gradient [20] usually restricts the performance of these algorithms.
On top of the generic Q-learning and policy gradient methods, there are various opponent modeling and communication methods proposed to facilitate coordination and further improve the performance of specific types of tasks. COMA in [7] aims to solve the credit assignment problem in MAS, but they require agents to have the same reward functions. [1,2,26] proposed multiagent communication with continuous signals during collaboration. They model communication as another type of actions and have specific modules to control it. Nevertheless, transmitting continuous signals requires channels with large bandwidth, which may not be available when execution. Our model, on the other hand, only needs communication with discrete messages in centralized training to develop effective collaboration in decentralized execution.
Emergence of communication protocol using discrete messages has been explored with various types of communication games [27,28,29,30]. In these games, agents only communicate with nonsuited messages [31], namely no agent-environment interactions. Nevertheless, our model integrates agent-agent messages and agent-environment actions to infer other agents' mind and collaborate.
Attempts to integrate ToM in opponent modeling has profound cognitive science origin [16,10]. LOLA in [32] learns the best response to evolving opponents. Yet, opponents/partners' real-time believes are not considered into policy. Interactive-POMDP (I-POMDP) [14,15] moves one more step forward by actually modeling opponents' mental states at the current moment and integrates other's belief into the agent's policy. However, I-POMDP requires extensive sampling to approximate the nested integration over the belief space, action space and observation space, limiting its scalability. The Bayesian action decoder (BAD)-MDP proposed by Foerster et al. [6] and cooperative inverse reinforcement learning (CIRL) proposed by Fisac et al. [19] also use counterfactual reasoning in their belief update, but their methods are more centralized in the testing process than ours. The BAD-agent is a super-agent controlling all other agents collectively. Deterministic partial policies can easily reveal agents' private information to the BAD-agent and make it public. CIRL requires that human and robot have their Q-function in common knowledge. Instead, our model doesn't depend on any implicit information flowing between agents during testing and assumes no common knowledge. Wen et al. [33] proposed recursive reasoning policies in MAS to accommodate ToM. The only change in their method from [4] is to use soft Q-learning [34,35] and SVGD [36] to estimate other agents' policy conditioning on the estimator's action 1 . Our algorithm, which uses explicit belief and belief over belief in our value functions, outperforms their implicit modeling approach in partially observable games.

Background and Setting
Consider a partial observable multiagent game with N agents. At time t each agent i ∈ {1, ..., N } takes an action from its action space a t i ∈ A i according to π i (a|τ t i ), where τ t i stands for agent i's observation and action history Here we assume that states of this MAS can be decomposed into physical states and private agent states, namely S = S × Ω 1 × ... × Ω N , where S is the environment state space, Ω i is the agent i's private state space, eg. agent's goal or intention, and S is the , ω i ), an observation triggered by its action from the physical state and its private agent state, ω i ∈ Ω i which we assume constant until the end of one game. If we denote s ωi as agent i's private state at state s and a t = {a t 1 , ..., a t N }, then we have the state transition function In fully cooperative games, all agents share the same reward function. Notice that rewards depend on the complete state instead of just the environment. An example will be some of the agents know the goal of a task requiring all agents' effort to accomplish, making inference of other agents' private state crucial.
We can define the value of a state as . The goal of this multiagent game is to find a set of policies π = {π 1 , ..., π N } to maximize the expected return of the game E s 0 [V π ( s 0 )] starting at time 0. The optimal value of a state is defined as V * ( s) = max π V π ( s). We can also define Q-function as It has been shown that Q-learning can converge to optimal Q-values with mild assumptions [37]. We also define value functions for an agent given its opponents policies: When there is no ambiguity, we can omit the π −i in the subscript and only write Q i .

Method
In this section, we propose our algorithm to solve the partial observable game defined in the previous section. First, we define agents' modules and introduce how they act when all modules are learned. Then, we illustrate the learning algorithm for all modules, which is a centralized process among agents.

Decentralized Execution
The execution process is purely decentralized as all agents only act according to their local observations and no direct communication other than mutual inference from action observation. For an agent i, it performs according to its value function, Here we assume the physical state is fully observable to all agents, so the only belief an agent needs to hold is about other agents' private states. This assumption can be relieved by introducing an observation model for the physical state and form belief over the environment. If we denote other agents as −i, as their private states are not available to agent i, it must maintain a belief b t i (ω −i ). Thus, we have agent i's policy following Boltzmann rationality model [10] with β as the rationality coefficient of i and quantifies the concentration of i's choices around the optimum. As β → ∞, i becomes a perfectly rational agent, while, as β → 0, i becomes indifferent to Q: Next problem is how agent i maintains its belief given its observation history. We utilize counterfactual reasoning [19,6] in our belief update function. That is, agent i traverses all possible private states ω −i and estimates how likely the actions it observed are taken given a specific set of private agent states are the correct one. Then, i updates its belief using Bayesian rule:  [38], we let the i holds a beliefb −i as the estimation of −i's belief about ω i . Here,b −i is still a distribution over Ω i . We didn't use a distribution over distribution to model this nested belief because the belief update process is deterministic for rational agents following Bayesian rule. Givenb 0 −i a uniform distribution over candidates, P (b t −i ) is unimodal with uncertainty merely from the likelihood and can be approximated with a single point. All we need is a belief update function in i, for i ∈ {1, ..., N } do 5: Initialize replay buffer D ← ∅ 6: while train agent i do 7: repeat 8: Agents sample actions according to equation 3 9: Agents update their beliefs 10: Agents update their estimation of partners' beliefs 11: until game ends 12: Update D with new trajectory 13: Sample M trajectories {(ω1:N , s0:T , a0:T , r0: Periodically updateθi ← θi for Q-learning 20: end while 21: end for 22: end for over Ω i . Belief update function f takes in the old belief, agent i's action, the physical state and returns a new belief as i's new estimation of others' belief over ω i . If ω i and ω −i are not independent, then b i should be an additional argument of f , but in this paper, we only explore the scenarios where ω i and ω −i are independent of each other. The ability to correctly infer others' private states from their actions and predict others belief about oneself introduces ToM into our agents. Figure 1 visualizes the execution pipeline.

Centralized Training
As introduced in section 4.1, there are three components that every agent needs to learn during centralized training, Q i ,π −i and f −i . To learn Q i , we apply the deep Q-learning algorithm [21,39]. To avoid the non-stationarity caused by simultaneous agent updates, we fix all other agents when one agent is being trained. Thus, all the fixed agents can be considered as part of the environment, so the convergence of the Q-function of the learning agent is still guaranteed. In a fully observable multiagent game where all agents share the same reward, suppose we denote π = {π 1 , ..., π i−1 , π i , π i+1 , ..., π N } as the joint policy before agent i is being trained and π = {π 1 , ..., π i−1 , π i , π i+1 , ..., π N } as the new policy after i is trained, where π i = arg max a∈Ai Q * i (s, a). One can show from the convergence of the Q-learning that E s0 [V π (s 0 )] ≥ E s0 [V π (s 0 )] using the same procedure as in [37]. Therefore, our adaptive training algorithm guarantees monotonic performance improvement. As history is important in Q-functions of POMDP, we saved trajectories in the replay buffer and sample complete trajectories in the training [40].
Bothπ −i and f −i are learned with supervision. To be more specific, during training agents −i will reveal their private agent states to the public after each game is finished. Thenπ −i can be learned with MLE. The supervision of f −i is more complicated, as beliefs are continuous variables representing distributions, but communicating discrete messages are more realistic. Therefore, we discretize beliefs b −i and pass that discretizationb −i to i as supervision for f −i . The exact discretizing procedure may vary according to different tasks, as we'll elaborate in later section 5.1 and 5.2. In our future work, we consider using a specifically trained message decoder to further enrich communication. The detailed learning process is in algorithm 1. Here we abuse the notation a little by encompassing all parameters of agent i into θ i , which contains three sets of parameters for the Q-function,π −i and f −i respectively. In line 16, H represents softmax cross-entropy loss, as here we have A −i as discrete actions. In line 17 we use Kullback-Leibler (KL) divergence to measure the distance between the   training progress from 0 to 1 as the x-axis. y-axis represents testing accuracy. Due to the time limit, we stop training a model after it converges. We halt when the best training accuracy stops increasing for 10000 iterations. We average the training accuracy of mini-batches every 1000 iterations to avoid fluctuation. We'll report results for training all models to a fixed iterations in our later version. In captions above, M stands for 10 6 and K stands for 10 3 .
predicted partners' belief and the partners' belief supervision,b −i . This distance measure can be replaced with other functions given different tasks and forms of belief supervision because we use discretized belief instead of continuous vectors. As in line 18, different loss may use different step size η to update.

Experiments
We used two multiagent games with imperfect information including two agents to evaluate our experiments. For both experiments, we generated three exclusive training/testing splits and repeat two experiments with different random initialization on each split. We report average performance from six experiments. We compare with several benchmarks including CIRL [19], COMA [7], DDRQN [5], MADDPG [4], BAD [6] and DIAL [1]. For MADDPG, we integrate PR2's policy modeling from [33] by taking history into the policy network. We further simplify policy estimation by letting agents using their opponents' actual policies in training. Notice that in the original setting of DIAL, agents require communication in both training and testing. Our model, on the other hand, only needs communication during training. So we report DIAL performance for testing without communication. When implementing these benchmarks, we stick to their papers to adapt all models to our tasks. We also take the author released code for reference if there is. The detailed structure and hyper-parameters can be found in supplementary together with our codes.

Kitchen Collaboration
This multiagent game is inspired by the ChefWorld proposed in [19]. Suppose there are two agents A and B, with A as the chef and B as the assistant. For each game, a recipe with K dishes is publicly provided to the agents. The purpose of the game is for both agents to prepare ingredients for the target dish, which is only known by the chef. We use a categorical number to denote an ingredient and represent every dish on the recipe as a set of ingredients. Agents take turns to act by selecting an ingredient and put it on the workplace, starting from the chef, A. A game ends if either a wrong ingredient is selected or all ingredients are prepared. We allow repetitive ingredients in a dish but preparing more than enough also leads to failure. Suppose we have a recipe, [0, 1, 2, 6], [2,2,4,8,9], [2,3,6,7,7] and [1,2,2,8,9], and the target dish is the third dish. Then a successful action sequence  Table 1: Unique identifier using percentage. ToM agents can simulate partners' reaction of self actions and choose the most ideal action to perform. In kitchen collaboration, the chef needs to clarify the target dish to the assistant as soon as possible so that only the correct ingredients are prepared. The most straightforward way is for the chef to choose the unique ingredient only included by the target dish. We calculate the probability for the chef to choose a unique ingredient if there is one. We claim that the frequency to choose the unique ingredient is related to the switch group accuracy in 5.3. As if the chef doesn't use unique ingredients to indicate the target dish, there have to be some other protocols formed between agents, which are usually group-specific.
The order of the ingredients being prepared and who prepared what ingredient does not matter for the completion of the task. Some failure trajectories can be At the end of each game, both agents get a reward ±1 for success or failure, and there is no step reward or cost as the game proceeds. In this experiment, agent B's beliefs are k-dimensional distribution vectors. Hence, in centralized training, we let agent B sample an index k between 1 to K from its belief and send a one-hot vector with the k-th number being 1 to A as a discretized belief supervision. KL-divergence is used as the distance function for L f .
There are W ingredients in total and we limit the maximum number of ingredients in a dish by M . In a recipe, all dishes are different from other dishes by at least one ingredient. A target dish is a one-hot K-dimensional vector, indicating which dish should be prepared. Only the chef knows the target, so we have ω A as a K-dimensional one-hot vector and ω B as an empty dumpy variable. In later of the paper, we refer a game as the combination of a recipe and a target.
All recipes are randomly generated. We synthesize a dish by randomly picking M numbers from {0, 1, ..., W } with replacement. If W is selected, we remove it from the dish as only {0, 1, ..., W −1} are valid ingredients. We include W in the selection process to have dishes with fewer than M ingredients. The order of the ingredients doesn't matter, and we will resample a dish if two dishes are duplicates in one recipe. There are 3335 possible dishes and 5.1 × 10 12 possible games in total. To verify the robustness of our model, we keep the training dishes exclusive from the testing dishes. There are 2335 unique dishes in the training set and 1000 in the testing set. There are 7 and 3 million games in our training and testing set respectively. We evaluated our model and benchmarks using K = 4, M = 5, W = 10.
Results are shown in table 2 and figure 2a. BAD [6] achieves very close performance with our model. Their model has a BAD-agent that controls all other agents by sending partial policies to agents and using equation 1 in their paper to infer agents' private observations. Nevertheless, when the private observation space is small, the BAD-agent can form an one-to-one mapping between actions to private observations, forcing agents to reveal their private states by doing actions as told. Then the private states can flow among all agents through the BAD-agent, centralizing the execution process. In other words, their agents don't do counterfactual inference but tell their private states to the BAD-agent, who determine the joint action as a meta-agent. We refer it as a weakly centralized execution. One drawback of their work is that mappings between actions and private states are usually arbitrary, so the emerged protocols are exclusive to one group of agents. To test our hypothesis, in section 5.3, we conduct switch group experiments. The significant performance reduction illustrates the sub-optimality of the protocols developed by Foerster el al. [6] In table 1, we also report the probability of the chef using the unique ingredients in the target dish in the first round. Using the unique identifier to disambiguate distractors is very common in human communication [11,17]. Our model developed a protocol very compatible with human communication. In the future, we consider adding human-agent experiments to quantify the compatibility. Using unique ingredients to identify the target dish is not the only possible protocol between collaborative agents, but it is the most universal way across different groups. Table 2: Accuracies for kitchen collaboration and appointment scheduling tasks. In the first experiment, BAD has slightly better performance, but it is weakly centralized execution as the private agent states can flow among agents through the BAD-agent. COMA achieves 0.1% higher accuracy than ours in the second experiment. There is a centralized critic in COMA, so agents must have the same reward function. In section 5.3 we show that both of these methods learn group-specific protocols, while ToM can emerge task level protocol. DIAL with messages can achieve perfect performance as agents will share private states directly through the communication channel. We include this algorithm as an oracle. If we remove the communication channel from DIAL, its performance degrades considerably. As the communication channel enables agents to collide easily in appointment scheduling, DIAL is not used for the second experiment. CIRL is applicable when only one agent has hidden information.
To show the convergence of the models, test curves are plotted in figure 2a and   Both agents' private time tables are randomly generated with each slot sampled from a Bernoulli distribution with p = 0.5. As there are only 2 2D games, to prevent overfitting, we make sure all schedules in the testing sets are not included in the training sets. There are about 180 schedules, 30k games, and 80 schedules, 6k games in the training and testing sets respectively. We used D = 8 in our experiments. Notice that the baseline of random guess accuracy is 25%; the baseline of random propose based on self time table is 50%. Our results and analysis are reported in captions of table 2 and figure 2b.

Flexible Group Assignment
Another contribution of our work is that with ToM considered in action selections, universal protocols compatible cross groups are more likely to be developed. That is to say, our model can integrate task level essence into the protocol so that even if the partner in testing is different from that in training, they can still achieve good performance using their protocols learned separately. Task level universal protocol is the prerequisite of flexible agents assignment. Suppose there is a group of agents collaborating to complete tasks. If one of them is broken and needs to be substituted, we expect another agent to take the broken agent's place at once. The new agent doesn't need to have experience working with this particular group if they have a task level protocol. Most centralized training approaches only learn group-specific protocols.
Since for each split, we run two experiments, we switch the agents between the two experiments. Let agent A 1 trained with agent B 1 to collaborate with agent B 2 and let agent A 2 to collaborate with agent B 1 in testing. Only when agents understand the task rather than form group-specific tacit agreements can they maintain the performance after switch partners. See table 3 for results. Methods with centralized structures like BAD and COMA suffer from significant performance deduction, revealing the limitation of their group protocols.

Conclusion
In this paper, we proposed an adaptive multiagent learning algorithm, with which cooperative agents can develop effective collaborations in MAS with imperfect information. Agents learn how to infer others' hidden mental states with only observations of partners' actions and no verbal communications. Our algorithm outperforms all other decentralized execution approaches and shows the least performance drop in group switching experiments, demonstrating that our agents form strategies for the game instead of emerging ad-hoc protocols only compatible to specific partners. In the future, we aim to explore games involving continuous agent state space, where beliefs cannot be modeled as vectors but have to be parameterized.