The Mathematics of AI Agents

The Mathematics of AI Agents

A laboratory companion by Jason Karpeles. Choose a mathematical question, inspect the calculation, then change an assumption or use your own documented inputs.

Start with one successful calculation · Follow a complete release controller

Illustrated readers · Standalone workbook · Separate answers · Notation guide · Release console mock-up (Chapter 18)

Each page shows one chapter notebook with its results already computed. To change values and run the code yourself, download the complete lab from the companion home page.

01: When a Score Becomes a Skill

Compare continuous evidence and thresholded scores without attributing a mechanism.

Notebook on GitHub · Illustrated reader · Input example · Solutions

02: How to Measure Emergence

Compute the signed four-cell contrast, positive amount, and valid share.

Notebook on GitHub · Illustrated reader · Input example · Solutions

03: How to Predict Emergence

Fit a declared curve on development data and score a separate test.

Notebook on GitHub · Illustrated reader · Input example · Solutions

04: The Path from Prediction to Action

Return reachable states, a permitted path, and sinks under frozen permissions.

Notebook on GitHub · Illustrated reader · Input example · Solutions

05: What the Model Becomes Inside an Agent

Compose a chooser and tool kernel, then separate marginal from trajectory reliability.

Notebook on GitHub · Illustrated reader · Input example · Solutions

06: The Price of a Choice

Return an expected-utility choice and a break-even value under declared stakes.

Notebook on GitHub · Illustrated reader · Input example · Solutions

07: The Equation That Looks Ahead

Compute a finite-horizon optimal policy and its value by backward induction.

Notebook on GitHub · Illustrated reader · Input example · Solutions

08: Acting in the Dark

Update a belief and calculate gross and net one-step information value.

Notebook on GitHub · Illustrated reader · Input example · Solutions

09: Searching the Future

Execute A* and audit supplied heuristic admissibility and cost.

Notebook on GitHub · Illustrated reader · Input example · Solutions

10: Plans Within Plans: Hierarchical Actions and Reusable Skills

Compute option returns with duration discounting and explicit completion.

Notebook on GitHub · Illustrated reader · Input example · Solutions

11: The Mathematics of Curiosity

Compare greedy, UCB, and Thompson choices in a declared stationary bandit.

Notebook on GitHub · Illustrated reader · Input example · Solutions

12: Credit for Consequences

Compare Monte Carlo, TD(0), and accumulating TD(lambda) updates on one trajectory.

Notebook on GitHub · Illustrated reader · Input example · Solutions

13: Learning to Choose: Training an Agent from Trajectories

Train a seeded softmax policy with REINFORCE and evaluate a separate success predicate.

Notebook on GitHub · Illustrated reader · Input example · Solutions

14: Building a World Inside

Calculate uniform transition error, actual fixed-policy finite values, and conditional bounds.

Notebook on GitHub · Illustrated reader · Input example · Solutions

15: What an Agent Should Remember: Retrieval, Compression, and Experience

Choose fresh valid records and inspect action preservation under compression.

Notebook on GitHub · Illustrated reader · Input example · Solutions

16: Thought as Search

Separate candidate coverage from actual selector success and choose a feasible allocation.

Notebook on GitHub · Illustrated reader · Input example · Solutions

17: State and Consequence

Separate effects from acknowledgements and price a next recovery step.

Notebook on GitHub · Illustrated reader · Input example · Solutions

18: When an Action Has Coordinates

Compare coordinate, semantic, and version-bound action contracts.

Notebook on GitHub · Illustrated reader · Input example · Solutions

19: When Another Mind Becomes Part of the World

Compute diagonal, cross-play, and deployment-mixture performance.

Notebook on GitHub · Illustrated reader · Input example · Solutions

20: Messages, Beliefs, and Consensus

Enumerate bounded message worlds and distinguish agreement from local knowledge.

Notebook on GitHub · Illustrated reader · Input example · Solutions

21: Markets, Teams, and Institutions

Compare Braess equilibrium, social optimum, tolls, and overhead.

Notebook on GitHub · Illustrated reader · Input example · Solutions

22: Safe Enough to Act

Compare penalty choice with hard authorization and expected-risk constraints.

Notebook on GitHub · Illustrated reader · Input example · Solutions

23: When the Environment Gives Instructions: The Mathematics of Agent Security

Replay a fictitious attack trace against capability, provenance, and review checks.

Notebook on GitHub · Illustrated reader · Input example · Solutions

24: How Much Capability Have We Extracted?

Report observed denominators, matched differences, uncertainty assumptions, and target mixtures.

Notebook on GitHub · Illustrated reader · Input example · Solutions

25: Improving an Agent Without Trusting the Improvement

Select on development and check only the frozen winner against a declared guard contract.

Notebook on GitHub · Illustrated reader · Input example · Solutions

26: How Much More Could the System Become?

Separate bank oracle coverage, actual choice, and permission-filtered success.

Notebook on GitHub · Illustrated reader · Input example · Solutions

27: The Mathematics of Delegation

Compute a review queue diagnostic and identify required handoff packets and release blockers.

Notebook on GitHub · Illustrated reader · Input example · Solutions