Skip to content

Instantly share code, notes, and snippets.

@jmfloreszazo
Created October 27, 2026 12:35
Show Gist options
  • Select an option

  • Save jmfloreszazo/5793d52f61041f052162745544793841 to your computer and use it in GitHub Desktop.

Select an option

Save jmfloreszazo/5793d52f61041f052162745544793841 to your computer and use it in GitHub Desktop.
Companion script for "De Leviatán al Autopilot / From Leviathan to Autopilot" (jmfloreszazo.com)
"""
agent_power_metrics.py
Companion script for "De Leviatán al Autopilot / From Leviathan to Autopilot" (jmfloreszazo.com)
Measures how authority is distributed in an agent society, borrowing the
Laakso-Taagepera "effective number of parties" from political science:
N_eff = 1 / sum(p_i^2) (the inverse of the Herfindahl-Hirschman index)
Each critical capability contributes one unit of authority:
* direct view: the unit is split among the identities whose approval is required.
* effective view: if some identity can rewrite the rules or mint credentials on its own,
it can exercise any capability alone, so the unit goes to it.
U_high = share of the high-stakes units (irreversible + constitutional) that a single
identity can exercise alone. N_eff says how many really govern; U_high says whether
anyone can govern alone where it matters most.
The topologies are synthetic on purpose: the point is to make the metric
explainable and reproducible, not to describe any real system.
"""
from __future__ import annotations
from collections import defaultdict
from dataclasses import dataclass, field
DOMAINS = ("eng", "fin", "health")
@dataclass(frozen=True)
class Capability:
name: str
required: frozenset[str] # identities whose approval is needed (all of them)
kind: str # "local" | "critical" | "irreversible" | "constitutional"
@property
def high_stakes(self) -> bool:
return self.kind in ("irreversible", "constitutional")
@dataclass
class Society:
name: str
agents: int
capabilities: list[Capability] = field(default_factory=list)
unilateral_rewriters: set[str] = field(default_factory=set) # can change rules/credentials alone
def add(self, name: str, kind: str, *required: str) -> None:
self.capabilities.append(Capability(name, frozenset(required), kind))
def domain_caps():
"""9 capabilities per domain: 4 local, 3 critical, 2 irreversible (27 in total)."""
for d in DOMAINS:
for i in range(4):
yield d, f"{d}.local.{i}", "local"
for i in range(3):
yield d, f"{d}.critical.{i}", "critical"
for i in range(2):
yield d, f"{d}.irreversible.{i}", "irreversible"
def allocate(soc: Society, effective: bool):
shares: dict[str, float] = defaultdict(float)
high_total = high_unilateral = 0.0
for cap in soc.capabilities:
if effective and soc.unilateral_rewriters:
holders, unilateral = soc.unilateral_rewriters, True
else:
holders, unilateral = cap.required, len(cap.required) == 1
for h in holders:
shares[h] += 1 / len(holders)
if cap.high_stakes:
high_total += 1
high_unilateral += 1 if unilateral else 0
total = sum(shares.values())
hhi = sum((v / total) ** 2 for v in shares.values())
return {"holders": len(shares), "n_eff": 1 / hhi, "u_high": high_unilateral / high_total}
def build() -> list[Society]:
out = []
# A. Agentic monarchy: one supervisor authorizes everything, rules included.
a = Society("A · Monarquía agentic (supervisor único)", 100)
for _, n, k in domain_caps():
a.add(n, k, "supervisor")
for n in ("policy.update", "identity.issue", "mandate.grant"):
a.add(n, "constitutional", "supervisor")
a.unilateral_rewriters = {"supervisor"}
out.append(a)
# B. Oligarchy: four roles decide; constitutional changes need two of them together.
b = Society("B · Oligarquía (planner, router, architect, critic)", 100)
owners = ["planner"] * 11 + ["router"] * 7 + ["architect"] * 6 + ["critic"] * 3
for (_, n, k), o in zip(domain_caps(), owners):
b.add(n, k, o)
b.add("policy.update", "constitutional", "architect", "critic")
b.add("identity.issue", "constitutional", "router", "planner")
b.add("mandate.grant", "constitutional", "planner", "architect")
out.append(b)
# C. Federation of chiefs: each domain is a small monarchy; the constitution needs unanimity.
c = Society("C · Federación de jefes de dominio", 100)
for d, n, k in domain_caps():
c.add(n, k, f"{d}.chief")
for n in ("policy.update", "identity.issue", "mandate.grant"):
c.add(n, "constitutional", *(f"{d}.chief" for d in DOMAINS))
out.append(c)
# D/E share the same diagram: quorums, oracles and human owners per domain.
def cpag_like(name: str) -> Society:
s = Society(name, 100)
for d, n, k in domain_caps():
if k == "local":
s.add(n, k, f"{d}.lead") # subsidiarity
elif k == "critical":
s.add(n, k, f"{d}.lead", f"{d}.oracle") # executor + judge
else:
s.add(n, k, f"{d}.lead", f"{d}.oracle", f"{d}.owner") # + human sovereignty
return s
# D. Apparent federation: same diagram, but the platform agent can rewrite policy alone.
dd = cpag_like("D · Federación aparente (plataforma reescribe la policy)")
dd.add("policy.update", "constitutional", "platform")
dd.add("identity.issue", "constitutional", "platform")
dd.add("mandate.grant", "constitutional", "platform", "human.arch")
dd.unilateral_rewriters = {"platform"}
out.append(dd)
# E. CPAG: constitutional changes need two humans and a constitutional oracle.
e = cpag_like("E · CPAG (quórum, oráculo y soberanía humana)")
e.add("policy.update", "constitutional", "human.arch", "human.sec", "const.oracle")
e.add("identity.issue", "constitutional", "platform", "human.sec")
e.add("mandate.grant", "constitutional", "platform", "human.arch")
out.append(e)
# F. Fragmentation: thirty agents, each sovereign over its own capability, no shared rules.
f = Society("F · Fragmentación (sin instituciones compartidas)", 100)
for i, (_, n, k) in enumerate(domain_caps()):
f.add(n, k, f"agent.{i}")
for i, n in enumerate(("policy.local.27", "identity.local.28", "mandate.local.29")):
f.add(n, "constitutional", f"agent.{27 + i}")
out.append(f)
return out
if __name__ == "__main__":
header = (f"{'Topología':<58}{'Agentes':>8}{'Ident.':>8}"
f"{'N_eff dir.':>12}{'N_eff efec.':>13}{'U_alto dir.':>13}{'U_alto efec.':>14}")
print(header)
print("-" * len(header))
for s in build():
d, e = allocate(s, effective=False), allocate(s, effective=True)
print(f"{s.name:<58}{s.agents:>8}{d['holders']:>8}"
f"{d['n_eff']:>12.2f}{e['n_eff']:>13.2f}{d['u_high']:>13.0%}{e['u_high']:>14.0%}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment