Part VI: Distributed AI and Multi-Agent Systems
Chapter 28: Game-Theoretic Foundations for Multi-Agent AI

Cooperative Games and Coalitions

"We agreed to pool our payloads and split the proceeds. The argument was never about whether to cooperate; it was about who deserved what, and whether anyone could storm off and do better alone."

A Coalition Mid-Negotiation
Big Picture

When agents can sign binding agreements to act as a team, the central question stops being "what will each agent do?" and becomes "which teams form, and how is the shared value split so that no one wants to walk away?" The previous sections treated agents as rivals choosing actions independently. Cooperative game theory treats them as parties that can commit to joint plans and must then divide the spoils. Two ideas carry the whole subject: the core, the set of divisions stable enough that no subgroup can do better by breaking off, and the Shapley value, the unique division that pays each agent its average marginal contribution. These are not abstractions. They decide whether a fleet of robots will actually team up, and the Shapley value escaped game theory entirely to become the dominant method for explaining machine-learning predictions. This section builds both from a characteristic function and checks them in code.

In Section 28.3 we studied agents that choose actions independently and cannot make their promises binding; the Nash equilibrium told us where such non-cooperative play settles. Many multi-agent systems are not like that. A team of delivery robots can agree, in advance and enforceably, to pool their capacity and share the revenue. A set of data owners can commit to train a model together and split the credit. A group of compute providers can form a consortium and divide the bill. In all of these the agents can form a coalition, a subset that acts as one, and the binding contract changes the question we must answer. We no longer ask which single-agent action is a best response; we ask which coalitions form and how the value they jointly create is divided. That is the subject of cooperative, or coalitional, game theory.

1. The Characteristic Function: What Each Coalition Can Secure Beginner

A cooperative game with transferable utility is specified compactly. Let $N = \{1, 2, \dots, n\}$ be the set of agents. A coalition is any subset $S \subseteq N$, and the whole set $N$ is the grand coalition. The game is given by a single object, the characteristic function $v$, which assigns to every coalition $S$ a number $v(S)$, the total value that the members of $S$ can guarantee themselves by cooperating, regardless of what the agents outside $S$ do. By convention the empty coalition is worth nothing, $v(\emptyset) = 0$. Everything else, who should team up and who deserves what, is read off from this one function.

Cooperation is worthwhile precisely when teams are worth more than the sum of their parts, a property called superadditivity: for disjoint coalitions $S$ and $T$, $v(S \cup T) \ge v(S) + v(T)$. When this holds, merging never hurts, so the grand coalition $N$ creates the most total value and the interesting question is purely distributive: how do we split $v(N)$? The difficulty is that the agents are still self-interested. They will cooperate only if their slice of the joint value is at least as large as anything they could secure on their own or in a breakaway subgroup. A division that ignores this invites defection, and a coalition that is one defection away from collapse is not a coalition at all.

Key Insight: The Game Is the Value of Every Subset, Not the Actions of Every Agent

A non-cooperative game is defined by each agent's strategies and payoffs. A cooperative game throws those away and keeps only one thing: $v(S)$, the value each of the $2^n$ subsets can secure. This is a deliberate change of resolution. We stop modeling how a coalition achieves its value and model only that it can, which lets us reason cleanly about formation and fair division. The price is the exponential object: $n$ agents have $2^n$ coalitions, and that combinatorial blow-up is the computational thread running through the rest of this section.

To make this concrete we will carry one running example: three delivery robots, $A$, $B$, and $C$. Working alone, $A$ completes 10 deliveries an hour, while $B$ and $C$ manage only 4 each. Paired up they specialize and do far better, and the full trio does best of all. Figure 28.4.1 shows the lattice of all eight coalitions with the value each can secure, the raw material from which both stability and fairness are computed.

The coalition lattice: value v(S) each subset can secure {A, B, C} v = 42 {A, B} v = 32 {A, C} v = 26 {B, C} v = 14 {A} v = 10 {B} v = 4 {C} v = 4 { } → v = 0
Figure 28.4.1: The coalition lattice for three delivery robots. Each node is a coalition $S$ labeled with the value $v(S)$ it can secure on its own; lines connect each coalition to the smaller coalitions it extends. The pairs all beat the sum of their singletons (for instance $v(\{A,B\}) = 32 > 10 + 4$), so cooperation pays, and the grand coalition at the top is worth the most. The two questions of this section are which division of the top value 42 is fair, and which divisions are stable against a subset breaking away.

2. The Core: Divisions Nobody Can Improve On by Leaving Intermediate

Suppose the grand coalition forms and produces $v(N)$. A payoff vector $x = (x_1, \dots, x_n)$ proposes to give agent $i$ the amount $x_i$. For this to be a credible division of exactly what was created, it must be efficient, meaning it hands out the whole pie and no more:

$$\sum_{i \in N} x_i = v(N).$$

Efficiency alone is not enough. A coalition $S$ that is offered $\sum_{i \in S} x_i$ in total but could secure $v(S)$ for itself by walking out will walk out whenever $v(S)$ is larger. A division survives only if every coalition is offered at least what it could get alone. That condition, applied to all $2^n$ coalitions at once, defines the core: the set of efficient payoff vectors satisfying

$$\sum_{i \in S} x_i \;\ge\; v(S) \qquad \text{for every } S \subseteq N.$$

An allocation in the core is stable in a strong sense. No subset of agents, however clever, can point to a way of doing strictly better by seceding, so the grand coalition holds together with no further enforcement. This is exactly the property a system designer wants when the goal is to get self-interested machines to cooperate at all, a thread we picked up in Section 27.7 on the stability of cooperation in distributed AI: a value-sharing rule that lands outside the core is an invitation for the most valuable agents to defect.

The catch is that the core can be empty. Some games have no division that simultaneously satisfies every coalition; whatever you propose, some subgroup is always tempted to break away, and the grand coalition is inherently unstable. The classic example is three agents who each create value only in a pair, where any two can always profitably abandon the third. Emptiness is not a defect of the analysis; it is the analysis correctly reporting that no stable grand coalition exists, which is itself crucial information when designing a system that depends on agents staying together.

Fun Note: The Glove Market With One Lonely Left Glove

A favorite teaching game: some agents each own a left glove, others a right glove, and a matched pair is worth one dollar while a single glove is worth nothing. With two lefts and one right, the lone right-glove owner is in an enviable spot. Both left-glove owners compete to pair with the only right glove, and the core awards the entire dollar to the right-glove holder, paying the surplus left glove exactly zero. Scarcity, not effort, sets the stable price, and the core is blunt enough to say so.

3. The Shapley Value: Fairness as Average Marginal Contribution Intermediate

The core asks for stability and may deliver many answers or none. A different question is fairness: of all the ways to split $v(N)$, is there a single division that is demonstrably even-handed? Lloyd Shapley answered this in 1953 by writing down a few axioms any fair division ought to satisfy and proving that exactly one rule meets them all. The axioms are mild and hard to argue with. Efficiency: the whole value is distributed. Symmetry: two agents who contribute identically to every coalition receive equal pay. Null player: an agent that adds nothing to any coalition is paid nothing. Additivity: the value of two independent games run together is the sum of the separate values. The unique rule satisfying all four is the Shapley value.

Its definition is an average of marginal contributions. Imagine the agents joining the coalition one at a time in some order. When agent $i$ joins a partially formed coalition $S$, it adds value $v(S \cup \{i\}) - v(S)$, its marginal contribution in that order. The Shapley value $\phi_i$ pays agent $i$ the average of this marginal contribution over all $n!$ possible orderings:

$$\phi_i(v) \;=\; \frac{1}{n!} \sum_{\pi \in \Pi} \big[\, v(P_i^\pi \cup \{i\}) - v(P_i^\pi) \,\big],$$

where $\Pi$ is the set of all orderings of the agents and $P_i^\pi$ is the set of agents that precede $i$ in ordering $\pi$. Equivalently, grouping orderings that produce the same predecessor set $S$ gives the familiar weighted-subset form,

$$\phi_i(v) \;=\; \sum_{S \subseteq N \setminus \{i\}} \frac{|S|!\,(n - |S| - 1)!}{n!}\,\big[\, v(S \cup \{i\}) - v(S) \,\big].$$

By construction the shares sum to $v(N)$, so the Shapley value is always efficient. It rewards an agent for what it genuinely adds, averaged so that no agent is privileged by being asked to join first or last. Figure 28.4.2 traces all six orderings of our three robots and shows agent $A$'s marginal contribution in each, the numbers that average to its Shapley value.

Agent A's marginal contribution across all 3! = 6 join orderings join order when A joins, set before A A's marginal value A, B, C { } → v=0 10 − 0 = 10 A, C, B { } → v=0 10 − 0 = 10 B, A, C {B} → v=4 32 − 4 = 28 C, A, B {C} → v=4 26 − 4 = 22 B, C, A {B, C} → v=14 42 − 14 = 28 C, B, A {B, C} → v=14 42 − 14 = 28 average = (10+10+28+22+28+28) / 6 = 21 = φ(A) B and C are computed the same way; the three Shapley values sum to v(grand) = 42.
Figure 28.4.2: The Shapley value of agent $A$ as an average marginal contribution. Each of the $3! = 6$ orderings places $A$ after some set of predecessors; $A$'s marginal value is what the coalition gains when $A$ joins. Averaging the six contributions gives $\phi_A = 21$. Agent $A$ earns more than its solo value of 10 because, on average across orderings, it lifts the coalitions it joins by considerably more than that. The code in this section reproduces these numbers and confirms the shares for all three agents.

4. Computing Both, and Seeing Where They Disagree Intermediate

The two concepts answer different questions, and a small program makes the distinction tangible. The code below builds our three-robot game as a characteristic function, computes the Shapley value by averaging marginal contributions over every ordering exactly as the formula prescribes, then tests two candidate divisions for core membership: the Shapley value itself, and a naive equal split that hands each robot a third of the total. Core membership is checked by verifying that every one of the $2^n$ coalitions is offered at least the value it could secure alone.

from itertools import permutations, combinations

# Three robots cooperating on a delivery task. The characteristic function v(S)
# gives the value (deliveries completed per hour) that coalition S can secure on
# its own. A carries packages, B drives fast, C navigates; pairs and the trio do
# strictly better than the sum of singletons (the gains from cooperation).
agents = ["A", "B", "C"]
v = {
    frozenset(): 0,
    frozenset(["A"]): 10,
    frozenset(["B"]): 4,
    frozenset(["C"]): 4,
    frozenset(["A", "B"]): 32,
    frozenset(["A", "C"]): 26,
    frozenset(["B", "C"]): 14,
    frozenset(["A", "B", "C"]): 42,
}
grand = frozenset(agents)

# ---- Shapley value: average marginal contribution over all join orderings ----
def shapley(agents, v):
    n = len(agents)
    phi = {a: 0.0 for a in agents}
    orderings = list(permutations(agents))
    for order in orderings:
        joined = set()
        for a in order:
            before = frozenset(joined)
            after = frozenset(joined | {a})
            phi[a] += v[after] - v[before]   # a's marginal contribution here
            joined.add(a)
    for a in agents:
        phi[a] /= len(orderings)
    return phi

phi = shapley(agents, v)
print("Shapley value (fair share of the %d total):" % v[grand])
for a in agents:
    print("  agent %s : %6.2f" % (a, phi[a]))
print("  sum      : %6.2f   (must equal v(grand)=%d)" % (sum(phi.values()), v[grand]))

# ---- Core membership: no coalition can do better by breaking away ----
def in_core(x, agents, v):
    # efficiency: the whole value is shared
    if abs(sum(x[a] for a in agents) - v[frozenset(agents)]) > 1e-9:
        return False, "not efficient"
    # coalition rationality: every subset gets at least what it could secure alone
    for r in range(1, len(agents) + 1):
        for S in combinations(agents, r):
            payoff = sum(x[a] for a in S)
            if payoff + 1e-9 < v[frozenset(S)]:
                return False, "coalition %s could secure %d but only gets %.1f" % (
                    "".join(S), v[frozenset(S)], payoff)
    return True, "stable: no coalition can improve by leaving"

ok, reason = in_core(phi, agents, v)
print("\nIs the Shapley allocation in the core? %s" % ("YES" if ok else "NO"))
print("  reason: %s" % reason)

# A tempting but UNSTABLE equal split, for contrast.
equal = {a: v[grand] / 3 for a in agents}
ok2, reason2 = in_core(equal, agents, v)
print("\nIs the equal split (%.0f each) in the core? %s" % (v[grand] / 3, "YES" if ok2 else "NO"))
print("  reason: %s" % reason2)
Code 28.4.1: A complete cooperative game in pure Python. shapley averages each agent's marginal contribution over all $n!$ orderings; in_core verifies efficiency and tests every coalition's incentive to secede. The same in_core routine judges both the Shapley division and a naive equal split.
Shapley value (fair share of the 42 total):
  agent A :  21.00
  agent B :  12.00
  agent C :   9.00
  sum      :  42.00   (must equal v(grand)=42)

Is the Shapley allocation in the core? YES
  reason: stable: no coalition can improve by leaving

Is the equal split (14 each) in the core? NO
  reason: coalition AB could secure 32 but only gets 28.0
Output 28.4.1: The Shapley value pays $A$ the 21 derived by hand in Figure 28.4.2 and lands inside the core, so it is both fair and stable. The equal split of 14 each looks fair but is unstable: $A$ and $B$ together could secure 32 by leaving, yet the equal division offers their pair only 28, so they defect. Fairness and stability are distinct, and only one division here achieves both.

The lesson in those few lines is the whole point of the section. An intuitively fair rule (split evenly) can be unstable, dissolving the coalition it was meant to hold together, while a rule grounded in marginal contribution can be both fair and stable at once. When the Shapley value happens to lie in the core, as it does here, a system designer gets the best of both worlds: a division agents accept as just and one no subgroup wants to escape. The Shapley value does not always land in the core, and the core is sometimes empty, but when they coincide the value-sharing question has a clean answer.

Thesis Thread: Stable Value-Sharing Is What Makes Distributed Cooperation Possible

The recurring problem of Part VI is getting self-interested machines spread across a network to behave like one coherent intelligence. Cooperative game theory supplies the missing ingredient that raw coordination protocols lack: a principled, stable way to divide the gains so cooperation survives contact with self-interest. A consensus protocol can make agents agree on a value; the core and the Shapley value tell us which division of that value the agents will actually accept and not abandon. This is the same spine that runs from the all-reduce of Section 1.1 through every later coordination mechanism: distribution is only useful when the pieces stay together, and here the glue is fair, defection-proof payment.

5. Coalition Formation as a Distributed Problem Advanced

So far we assumed the grand coalition forms and asked only how to divide its value. In many multi-agent systems the prior question is live: which teams should form in the first place? When ten robots face a set of tasks, the best outcome may not be one giant team but a partition of the agents into several disjoint coalitions, each tackling a task it is suited to. Choosing that partition to maximize total value is the coalition structure generation problem, and agents must often solve it themselves through distributed negotiation, with no central planner dictating the teams. This is the multi-robot, multi-task setting taken up directly in Section 29.7 on coalition formation, and it drives the team assembly of the drone-swarm case study in Chapter 39.

The difficulty is combinatorial and severe. The number of coalitions is already $2^n$, and the number of ways to partition $n$ agents into coalitions, the Bell number, grows even faster: 5 agents admit 52 partitions, 15 agents admit over a billion. Evaluating every coalition structure to find the optimum is hopeless beyond a handful of agents, and computing the characteristic function itself may be expensive when each $v(S)$ requires solving a planning or scheduling subproblem. Real systems therefore lean on approximation: anytime algorithms that return progressively better structures and can be stopped when the budget runs out, greedy merge-and-split heuristics where agents locally agree to join or break apart, and compact representations of the characteristic function that avoid listing all $2^n$ values explicitly. The Shapley value inherits the same blow-up, since the exact formula sums over $n!$ orderings; for games beyond a dozen agents it is estimated by Monte Carlo sampling of random orderings rather than enumerated, the same trick we will rely on for its machine-learning incarnation.

Research Frontier: Shapley Values at Scale, From Data to Federated Credit (2024 to 2026)

The Shapley value has become a workhorse far outside its origin in coalitional games, and making it tractable is an active research front. In explainable machine learning, SHAP treats each input feature as a player and attributes a prediction to features by their Shapley values; current work (for example the 2024 line on amortized and model-specific estimators) pushes the cost down from exponential to a single forward pass so explanations keep up with large models. Data Shapley and its successors value individual training examples or data providers by their marginal contribution to model accuracy, and 2024 to 2026 work scales these estimates to large datasets and ties them to data markets and pricing. In federated learning (the setting of Chapter 14), Shapley-based contribution scores decide how to reward participating clients fairly, with recent methods cutting the number of model retrains needed for an accurate estimate. The common thread is the one from this section: the exact value is exponential, so the frontier is principled approximation that preserves the fairness axioms while becoming computable at scale.

Practical Example: Splitting the Bill in a Compute Consortium

Who: A platform architect at a research consortium where three labs share a jointly purchased GPU cluster.

Situation: The labs pooled their budgets to buy a cluster larger and cheaper per GPU-hour than any single lab could afford alone, and now the annual bill must be divided among them.

Problem: A flat three-way split felt unfair: one lab ran the heaviest jobs but also brought the workload that justified the bulk discount, while a smaller lab suspected it was subsidizing the others and threatened to leave and rent on-demand instead.

Dilemma: Divide the cost equally, which is simple but pushes the lightest user toward defection, or attempt a usage-proportional split, which ignores who actually unlocked the shared discount and can still leave a subgroup better off renting separately.

Decision: They modeled the consortium as a cooperative cost game, computed each lab's Shapley value of the total savings, and checked that the resulting cost shares lay in the core so no lab or pair could do better by splitting off.

How: They estimated the characteristic cost of every sub-consortium from on-demand price quotes, ran a Shapley computation structurally identical to Code 28.4.1, and confirmed core membership before circulating the allocation.

Result: Each lab paid its fair marginal share of the savings, the lightest user's bill dropped below its standalone rental cost so it stayed, and the allocation was stable: no subgroup could secede and save money.

Lesson: When a stable, defection-proof split exists, paying each party its marginal contribution keeps a voluntary consortium intact where a flat or naive-proportional split would have fractured it.

Library Shortcut: SHAP Computes Shapley Values for Model Explanations

Code 28.4.1 enumerates all $n!$ orderings, which is fine for three agents and impossible for the hundreds of features in a real model. The shap library implements the same Shapley-value mathematics with model-specific fast paths and Monte Carlo sampling, turning what would be an exponential enumeration into a few lines:

import shap                      # pip install shap

# model: any trained predictor; X: the feature rows to explain
explainer = shap.Explainer(model, X_background)   # treats each feature as a "player"
shap_values = explainer(X)                         # Shapley value of every feature, per row

shap.plots.bar(shap_values)      # average marginal contribution of each feature
Code 28.4.2: The same average-marginal-contribution idea as Code 28.4.1, now attributing a model's prediction to its input features. The library handles the orderings, the sampling, and the model-specific shortcuts (TreeSHAP, for instance, is exact and polynomial for tree ensembles), so the exponential sum of the exact formula never appears in your code.
Fun Note: A Nobel-Worthy Average

Lloyd Shapley shared the 2012 Nobel Memorial Prize in Economics, and the value bearing his name has had an improbable second life. The very same average-of-marginal-contributions formula now explains why a neural network flagged a transaction as fraud, prices a single data point in a training set, and rewards a hospital for joining a federated study. Not bad for a 1953 idea about how to split a pie among people who can sign contracts.

6. Where Cooperative Games Sit in the Larger Story Beginner

This section answered the cooperative half of game theory: given that agents can form binding teams, which teams are stable and how should the joint value be divided. The characteristic function compressed the game to the value of every subset; the core identified divisions no coalition would flee; the Shapley value singled out the unique fair division and, when it falls in the core, gave a split that is fair and stable together. These tools turn "should these agents cooperate?" into a question with computable, defensible answers, which is precisely what a designer of self-interested distributed agents needs.

What we have not yet asked is which outcomes are good for the group as a whole, independent of how the value is split. A division can be perfectly stable yet leave total welfare on the table, and comparing whole outcomes rather than individual shares requires a different yardstick. Section 28.5 takes up social welfare and Pareto optimality, the criteria for judging an outcome's collective quality, and connects them back to the equilibria and coalitions we have now built.

Exercise 28.4.1: When Is the Equal Split Stable? Conceptual

Using the three-robot game in Figure 28.4.1, the equal split of 14 each fell outside the core because $\{A, B\}$ could secure 32 but was offered only 28. Without running code, find the smallest change to a single pair value $v(\{A,B\})$, $v(\{A,C\})$, or $v(\{B,C\})$ that would bring the equal split into the core, holding $v(N) = 42$ and the singleton values fixed. Explain in one sentence why making a pair worth less can stabilize an equal division, and what that says about the relationship between how much value a subgroup can create alone and how hard it is to keep that subgroup in the grand coalition.

Exercise 28.4.2: An Empty Core and a Sampled Shapley Value Coding

Modify Code 28.4.1 to the "pairs only" game on three agents where every singleton is worth 0, every pair is worth 1, and the grand coalition is also worth 1. First show that in_core rejects every efficient division you try (the core is empty), and argue from the pair values why no stable grand coalition can exist. Then add a function shapley_sampled(agents, v, m) that estimates the Shapley value by averaging marginal contributions over $m$ randomly sampled orderings instead of all $n!$, and verify that for this game it converges to $(1/3, 1/3, 1/3)$ as $m$ grows. State why sampling is the only feasible route once $n$ passes a dozen.

Exercise 28.4.3: The Cost of Exact Fairness Analysis

The exact Shapley value sums over $n!$ orderings, and the core check inspects all $2^n$ coalitions. For $n = 10$, $n = 15$, and $n = 20$ agents, compute both counts and tabulate them. If evaluating a single coalition's value $v(S)$ requires solving a 1-millisecond scheduling subproblem, estimate the wall-clock time to enumerate all coalitions at each $n$. Using the growth rates, argue which of the two, the $n!$ Shapley sum or the $2^n$ core check, becomes intractable first, and explain how the sampled estimator of Exercise 28.4.2 changes the picture for the Shapley value but not, in general, for verifying core membership.