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 · Setup and recovery · Release console mock-up (Chapter 18)

These pages are usable without Python or an account. To change and execute code, use the notebook launcher. To apply a method with an assistant, install the chapter skills and master skill through the launcher.

01: When a Score Becomes a Skill

Compare continuous evidence and thresholded scores without attributing a mechanism.

Notebook · Skill · Illustrated reader · Input example · Solutions

02: How to Measure Emergence

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

Notebook · Skill · Illustrated reader · Input example · Solutions

03: How to Predict Emergence

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

Notebook · Skill · Illustrated reader · Input example · Solutions

04: The Path from Prediction to Action

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

Notebook · Skill · 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 · Skill · 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 · Skill · Illustrated reader · Input example · Solutions

07: The Equation That Looks Ahead

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

Notebook · Skill · Illustrated reader · Input example · Solutions

08: Acting in the Dark

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

Notebook · Skill · Illustrated reader · Input example · Solutions

09: Searching the Future

Execute A* and audit supplied heuristic admissibility and cost.

Notebook · Skill · Illustrated reader · Input example · Solutions

10: Plans Within Plans: Hierarchical Actions and Reusable Skills

Compute option returns with duration discounting and explicit completion.

Notebook · Skill · Illustrated reader · Input example · Solutions

11: The Mathematics of Curiosity

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

Notebook · Skill · Illustrated reader · Input example · Solutions

12: Credit for Consequences

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

Notebook · Skill · 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 · Skill · Illustrated reader · Input example · Solutions

14: Building a World Inside

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

Notebook · Skill · 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 · Skill · Illustrated reader · Input example · Solutions

16: Thought as Search

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

Notebook · Skill · Illustrated reader · Input example · Solutions

17: State and Consequence

Separate effects from acknowledgements and price a next recovery step.

Notebook · Skill · Illustrated reader · Input example · Solutions

18: When an Action Has Coordinates

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

Notebook · Skill · Illustrated reader · Input example · Solutions

19: When Another Mind Becomes Part of the World

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

Notebook · Skill · Illustrated reader · Input example · Solutions

20: Messages, Beliefs, and Consensus

Enumerate bounded message worlds and distinguish agreement from local knowledge.

Notebook · Skill · Illustrated reader · Input example · Solutions

21: Markets, Teams, and Institutions

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

Notebook · Skill · Illustrated reader · Input example · Solutions

22: Safe Enough to Act

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

Notebook · Skill · 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 · Skill · Illustrated reader · Input example · Solutions

24: How Much Capability Have We Extracted?

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

Notebook · Skill · 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 · Skill · Illustrated reader · Input example · Solutions

26: How Much More Could the System Become?

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

Notebook · Skill · Illustrated reader · Input example · Solutions

27: The Mathematics of Delegation

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

Notebook · Skill · Illustrated reader · Input example · Solutions