Skip to main content

Cart pole

This walkthrough builds a working balancer with one body, one brain, and persistence. It works without an LLM (stub brain fallback) and with one (Ollama on localhost).

Prerequisites

  • Node 18 or higher.
  • Optional: Ollama with llama3.2 pulled, for a real brain. Without it the demo uses a rotating stub brain.

Install

The whole file

cartpole.js:

Run

Real output

Six seconds of a session against llama3.2 running locally:
The brain calls happen at 1.5 second intervals (brainIntervalMs). The 60Hz physics tick keeps the pole alive between calls because of the reflex, which is why the brain only needs to nudge.

Watching brain calls drop

Add a stats line. The first session shows the brain busy. After a few sessions on the same goal, vertical memory takes over and the brain barely runs.
Run twice with a vertical memory attached:
Session 1 (cold cache):
Session 2 (memory loaded from disk):
The brain is silent. Plexa is serving from VerticalMemory.

What does not work yet

  • The cart-pole here uses simplified physics. For real MuJoCo physics, see adapters/mujoco-cartpole/muscle.py in the SCP repo (Python, network body).
  • Ollama’s first call is slow. In production demos, pre-warm with a small dummy invocation before starting the timer.
  • The bundled inprocess-demo example in the Plexa repo prints fancier stats. The walkthrough above is the same shape, just shorter.