DEV Community

ORCHESTRATE
ORCHESTRATE

Posted on

Active Inference, The Learn Arc — Part 13: Session §1.2 — Perception and Action, One Loop Up Close

Session 1.2 — Perception and action, one loop

Series: The Learn Arc — 50 posts teaching Active Inference through a live BEAM-native workbench. ← Part 12: Session 1.1. This is Part 13.

The session

Chapter 1, §2. Session title: Perception and action — one loop. Route: /learn/session/1/s2_perception_and_action.

The hero move of this session is small and important. Session 1.1 claimed that perception, action, and learning are three arguments to one functional. Session 1.2 makes you feel that claim for the first time, by closing the loop in a world you can watch.

The 8-minute arc

The session is structured so you can finish it in one coffee break:

  1. Two minutes — read the path-specific narration at the top. Kid version: "your brain is a guess-and-check machine; watch this agent guess and check." Real-world: "the Perceive-Plan-Act loop runs three steps per tick." Equation: "Eq. 4.13 → Eq. 4.14 → action sample." Derivation: the same three equations with citations.
  2. Three minutes — open /world, pick Tiny Open Goal, click Create agent + world. Press Step three times. Watch the maze, watch the belief heatmap, watch the policy posterior.
  3. Three minutes — take the quiz, then read the next session's teaser.

That's it. Eight minutes to watch one complete closed loop.

What the screen shows

When you press Step, the Episode GenServer runs six calls in sequence:

WorldPlane.Engine.current_observation/1        # 1. world emits an observation
AgentPlane.Runtime.perceive/2                  # 2. agent updates beliefs (Eq. 4.13)
AgentPlane.Runtime.plan/1                      # 3. agent computes F, G per policy (Eq. 4.14)
AgentPlane.Runtime.act/2                       # 4. agent emits an action
WorldPlane.Engine.apply_action/2               # 5. world advances + terminal check
(optional) DirichletA/B.update/2               # 6. online learning
Enter fullscreen mode Exit fullscreen mode

Three of those — steps 2, 3, 4 — are perception, planning, action. They land inside the same agent's state. No separate "motor module." No separate "perceptual module." One Jido.AgentServer, three transitions on its state.

The LiveView surfaces are wired 1-to-1 to those steps:

  • The belief heatmap reflects the result of step 2 (Eq. 4.13).
  • The policy posterior table reflects step 3 (Eq. 4.14).
  • The action history strip reflects step 4.
  • The maze grid reflects step 5.

Watch it tick three times and you're looking at Chapter 2's equations applied repeatedly, live.

The hero concept

The session's canonical metadata (from Book.Sessions):

title: "Perception and action — one loop"
hero: "Perception, action, learning — one loop, one theory."
Enter fullscreen mode Exit fullscreen mode

That hero line is also Chapter 1's hero line. Session 1.2 is where that claim gets its first concrete grounding.

What to pay attention to

Three things, in the order the session narration guides you through:

1. The heatmap sharpens after every observation. That's perception in its minimal form — the agent's posterior over "where am I?" narrowing as evidence accumulates. Eq. 4.13 is literally what produces that sharpening.

2. The policy posterior reorders before the agent moves. Plans that looked promising last tick get down-weighted when new observations make them less likely to work. That's Eq. 4.14 softmaxing over changing G values.

3. The agent doesn't teleport to the belief peak. There's always a lag between "where I think I am" and "where I go next." That lag is the theory's prediction of how real agents should look — never certain, always acting under uncertainty.

The linked lab

The session's linked lab is active_inference_pomdp_machine.html — the interactive POMDP visualization. It runs alongside your Jido agent in /world, but lets you slow down the loop to millisecond-by-millisecond scrubbing. You can see every intermediate belief, every policy weight, every action sample.

Click the linked-lab chip on the session page and the Shell opens at ?path=<your-path>&beat=intro. The path parameter respects your suite cookie, so the lab's narration matches your narration.

The concepts this session surfaces

The session's glossary strip has four terms:

  • generative model — the A/B/C/D machinery.
  • policy posterior — Q(π), what the agent softmaxes to pick an action.
  • Markov blanket — the contract between agent and world.
  • belief update — the Eq. 4.13 message-passing step.

Click any chip and the glossary drawer explains the term at your chosen path's vocabulary.

The BEAM point

The six-step loop runs in one GenServer call. One :step message lands in the Episode's mailbox. The GenServer executes all six steps atomically, commits the resulting events to Mnesia, publishes signals to the Glass bus, and replies.

That atomicity matters. In Python you'd have a for-loop with intermediate state that could be interrupted. On BEAM, the :step is a transaction — either all six substeps land or none do. When you click Step ten times in rapid succession, the mailbox queues them and they execute in order, each as its own atomic transition.

This is why the theory maps to Elixir so cleanly: a GenServer is a process with a mailbox that handles one message at a time. An Active Inference agent is a process with a mailbox (observations in, actions out) that handles one tick at a time. Same shape.

Run it yourself

The mental move

In Session 1.1 the claim was abstract. In Session 1.2 you watch the claim happen. Three Step presses and you've seen the loop close. Everything that follows — Chapter 2's derivation, Chapter 3's EFE, Chapter 4's A/B/C/D — is explaining why the loop works. Session 1.2 is proof that it does.

Next

Part 14: Session §1.3 — Why one theory — and what this book covers. The third and final session of Chapter 1. Closes the overview; sets up why Chapter 2 takes the math seriously. Before we dive into Bayes' rule, one more session to make sure the shape of the book is clear.


⭐ Repo: github.com/TMDLRG/TheORCHESTRATEActiveInferenceWorkbench · MIT license

📖 Active Inference, Parr, Pezzulo, Friston — MIT Press 2022, CC BY-NC-ND: mitpress.mit.edu/9780262045353/active-inference

Part 12: Session 1.1 · Part 13: Session 1.2 (this post) · Part 14: Session 1.3 → coming soon

Top comments (0)