Every Agent Is a Code: Self-Models, Affect and the Limits of Self-Knowledge in Implicit-Coding Agents
A companion paper showed that every learner is a code: the cumulative log loss of a training pipeline is a code length, and Kraft's equality turns inductive bias into a conserved budget. Here the same accounting is extended from learners to agents that have a body, act, and predict themselves. An agent is a triple of predictive maps: a world model, a policy and a self-model. We prove that the world model and the self-model together form one prefix code on the agent's whole interaction history (its life), which obeys Kraft's equality, and that the expected length of this code exceeds the entropy of the life by exactly the redundancy of the world model plus the self-opacity, the divergence of the self-model from the policy. Self-opacity has a floor, a conditional mutual information fixed by what the self-model can read; an agent whose policy reads its own self-prediction can be transparent to itself when the policy is continuous, and there is a policy for which every self-model pays at least $\ln|\mathcal{A}|$ nats per step. Affect is defined in the same units. A viability prior on body states is a code whose length is the homeostatic drive; valence is the decrease of drive and arousal the code length of the current observation. Valence is conserved: it telescopes, its long-run mean is zero for every agent in every environment, and mean drive equals the entropy of the body's occupancy plus its divergence from the viability prior. The error of anticipated valence is bounded by the square root of the interoceptive redundancy of the world model. A workspace of $M$ symbols bounds control by a rate–distortion function, and no statistic of behaviour identifies any of these internal quantities. The second part of the paper lets the agent rewrite itself. A self-modifying agent, one that replaces its world model, its self-model, its policy or its values by any rule, is still a code on its life, and the conservation laws become laws of self-modification. Under its own prior every agent expects to lose from every rewrite. The nats saved by a rewrite form a test martingale: if the current self is right, no strategy of self-modification saves $c$ nats with probability above $e^{-c}$, so savings are evidence against the former self. A rewrite gated by $\ln(1/\alpha)$ nats of evidence abandons a correct self with probability at most $\alpha$ and costs at most that many nats plus one step; any rule this safe needs a number of steps of life fixed by the evidence the world supplies; and the total gain of all rewrites is bounded by the initial ignorance of the agent. An agent that keeps its former self with prior weight $1-\alpha$ loses at most $\ln\frac{1}{1-\alpha}$ nats if it was right and $\ln\frac1\alpha$ nats more than the price of whatever it should have become, on every life, and by Kraft's inequality no agent does better on both counts. Becoming one of $N$ distinguishable selves costs $\ln N$ nats, and the prices obey Kraft's inequality. Values rewritten before the fact keep total drive a code on body trajectories, with the entropy of the body as floor; values rewritten after the fact have no floor. We specify a tabular agent that realizes the definitions and test every statement with real numbers: Kraft's equality holds to $1.1\times10^{-16}$ on all 1,889,568 lives of a six-state body; the remaining identities and bounds are checked on 80 lives of 10,000 steps and again on an agent whose world model and self-model are small neural networks, and all outcomes are reported, including two hypotheses that failed. Fifty further scripts test the statements on self-modification: all 44 checks of theorems hold, and of 6 conjectures about self-modifying agents 3 are refuted, among them that greedy rewriting is safe. Inside the tabular agent, on a world that changes, a mixture over versions of the world model keeps its guarantees on every life but adapts late, because its candidates must first repay what they lost while the old world lasted; a prior over schedules of versions with decreasing switch rates adapts several times faster and codes every life better than each of its versions. The third part turns from predicting to acting. For every agent, expected total drive plus self-opacity equals the free energy of its self-model plus a third redundancy, that of its policy; an agent undercuts the free energy of its self-model by at most its opacity. With restricted access, drive and opacity trade along a frontier that no agent crosses, a self-model with full access makes optimal control free of opacity, and for a blind self-model the frontier is the distortion–rate function of the workspace. No agent is better in every world: against the agent that plans in a mixture of worlds, the prior-weighted balance of what any other agent gains and loses is that agent's policy redundancy, and no agent learns to act differently in two worlds faster than the worlds differ. We construct the frontier agent, in which each of the three redundancies, of the world model, the self-model and the policy, is as small as the other two allow, and which no agent with the same self-model beats in every world of its class; and we test it. On all 1,889,568 lives of the six-state body the new identities hold to $1.8\times10^{-15}$, and the exchange law holds in a class of four worlds; there the alternation that defines the frontier agent has up to 5 fixed points of different cost, and the conjecture that it always reaches the best is refuted. On the ring, in a tournament of 12 agents in three worlds, the frontier agent whose class contains the true world has the lowest mean drive of all learners in the two worlds of its class (2.660 nats per step against 2.883 for the planning agent of the first part, 0.019 above the optimal policy) and recovers from a change of the world in a median of 222 steps against 4,768; outside its class it is the third lowest of the 9 learners, behind a soft frontier agent at the canonical rate, which has the lowest drive there. The Boltzmann planner of the first part, given the true kernel, lies within 2% of the frontier of life cost for every access. No agent is best in every world and in every unit of account, as the exchange law requires, and two of the five hypotheses on the ring changed verdict between a shorter and a longer run. The paper measures functional indicators taken from scientific theories of consciousness. It does not show, and does not claim, that the agent is conscious or feels anything.
Authors
- Luca Eliseo Pavesi (ORCID: https://orcid.org/0009-0003-0532-2850)
Institutions
- University of Pavia (IT)
Publication Details
- Journal
- Zenodo (CERN European Organization for Nuclear Research)
- Published
- 2026-11-14
- DOI
- https://doi.org/10.5281/zenodo.24214686
- Primary Topic
- Embodied and Extended Cognition
- Type
- preprint