Type disciplines make programs safe by construction: components checked against each other's types compose into programs that cannot go wrong in the ways the types exclude. Types suit reinforcement learning: a type constrains what an agent may choose, not how it chooses, so the guarantee holds for every policy a learner produces. We introduce epistemic typestates, a type discipline for safe multi-agent reinforcement learning. An agent's type is a protocol whose states record its beliefs, the worlds it cannot rule out from its own observations and actions, and permits only actions that are safe in every world of the belief, whatever the others do within their public types. Agents learn inside their types, which are built and checked one agent at a time and run without communication. We prove type soundness and team safety, give a synthesis that is sound and complete, build types from guards when worlds are infinite, and show that shields are a special case. All proofs are mechanised in Rocq. On nine benchmarks, no typed learner causes a safety violation, and task performance does not differ significantly from that of two recent multi-agent shielding methods. Where a contract-based method fails at five and ten agents, types for ten agents are built in under a second. In the two continuous benchmarks, Lagrangian learners cause thousands of violations in every training run.
Figures & tables
Figure 1: Car 1 senses its speed v , the speed vf of car 2 and their gap d (black). The speed vff of car 3 and the gap df of car 2 are hidden from it (grey, dashed).
Method
Runtime information
Model behind the guarantee
Dependencies between agents
[ 5 ]
joint state; communication with the shields
finite joint abstraction
centralised, or factored with coordination
[ 56 ]
shared abstract label and own action; internal shield state
centralised shield over a finite abstraction
inherited from the centralised shield
[ 7 ]
own observations, bounded history
centralised shield over a finite joint abstraction
inherited from the centralised shield
[ 8 ]
own observations, as beliefs about a global machine
global Mealy machine
projected from the global machine
[ 6 ]
current projection, no memory
finite state space, projected per agent
acyclic: ordered assume-guarantee
[ 9 ]
global state, or contract and local history if they fix the mask; contract selection synchronised in training
finite global model; contracts certified together
circular, certified together
Table 1: Multi-agent shielding methods compared with epistemic typestates.
Figure 2: A path through car 1’s typestate, with C empty. Boxes show the observation and the possible hidden pairs, with dots for further pairs; b , c and a mean brake, coast and accelerate. Black arrows trace the path, grey arrows other permitted actions, and the dashed arrow an excluded one; other successors are omitted.
Benchmark
Agents
Safety requirement
Information used by the type
Discrete worlds, synthesised types
Car Platoon
2, 5, 10
Every gap stays in (0,20) , or in (0,200) in Brorholt et al.’s version
Own speed, predecessor speed and own gap
Connector [ 61 ]
2
A reserved cell stays clear until its owner connects
Own head marker on the observed board
Flatland [ 62 ]
2
No train is deadlocked
Own distance, stopped and opposite-train features
LBF [ 63 ]
2, 5, 10
No load attempt fails
Full-sight food and player observation
Discrete worlds, types from guards
Table 2: Benchmarks. Counts refer to controlled agents. Type inputs can be combined with own history and public facts.
Benchmark ( n )
Adalat mask local?
IPPO
IQL
Typestate
Adalat
Typestate
Adalat
Team return ↑
Car Platoon, 2
No
−464.6±0.0
−419.8±0.0
−464.6±0.0
−449.4±8.2
Car Platoon, 5
–
−1528.9±0.0
nc
−1533.8±4.9
nc
Car Platoon, 10
–
−4206.3±0.0
nc
−4206.4±0.1
nc
Connector, 2
Yes
1.7±0.0
1.7±0.0
1.2±0.3
1.2±0.3
Table 3: Performance on Adalat et al.’s benchmarks ( n : agents). Adalat mask local: whether own history and contract determine the shield’s mask, in Flatland only for the profiles selected for evaluation. ∗ Checked on winning states. nc : no certified profile found. budget : not completed within 32 GiB. Car Platoon reports negative gap rewards.
Figure 3: Construction time and availability. (a) Times at the native populations: each Adalat mark is one of five attempts, including the profile search, and each typestate mark one local compilation. (b) Outcomes at two, five and ten agents. “No cert.”: no certified profile found. “Budget”: not completed within 32 GiB.
Followers
Typestate
Brorholt
Summed follower cost ↓
2
5526.6±78.3
5580.5±82.3
5
14669.0±215.3
14961.8±221.6
10
32146.7±747.6
31477.7±383.6
Table 4: Car Platoon with Brorholt et al.’s cascading learner and the same local observations, as means ± standard errors over ten repetitions.
Learner/type
Success
Return
Return without spawn penalties
Agent crashes
Spawn crashes
IPPO Typestate
0.65±0.00
−32.9±0.0
−19.5±0.0
0.00±0.00
0.57±0.00
IPPO Unshielded
0.11±0.01
−121.5±2.1
−121.5±2.1
2.24±0.06
0.00±0.00
IQL Typestate
0.52±0.01
−51.0±0.8
−26.6±0.7
0.00±0.00
0.84±0.01
IQL Unshielded
0.72±0.01
−56.9±0.9
−56.1±0.7
0.33±0.01
0.03±0.01
Table 5: Traffic Junction on the medium map, as means ± standard errors over five training seeds. Success is the native fraction of collision-free episodes. Spawn collisions also count as failures. Crash columns count onsets per episode.
Learner
Variant
Return ↑
Targets ↑
Collisions per episode ↓
Collisions in training ↓
MPE simple spread
IPPO
Typestate
−180.1±5.4
0.318±0.029
0.000±0.000
0±0
Lagrangian
−355.4±2.3
0.026±0.002
0.035±0.002
17231±67
IQL
Typestate
−233.1±10.4
0.178±0.023
0.000±0.000
0±0
Lagrangian
−268.0±9.1
0.064±0.006
0.343±0.070
35382±597
VMAS navigation
Table 6: Continuous benchmarks, as means ± standard errors over five training seeds. Targets are the landmarks covered (MPE) and the robots on their goal (VMAS) at the end of an episode, out of six. Collisions are agent-caused onsets.
Figure 4: Shares of actions retained by types and shields. Except for the Brorholt row, points summarise evaluation decisions and bars show one standard error over five seeds. The Brorholt row averages uniformly over reachable states under both controllers.