Every timestep derives from one Lagrangian, expressed as a typed graph. Scenes pick the participating terms; solvers are programs over the graph.
Same engine binary, different active LagrangianNodes. Drag any block on the left; click play on the right to release the dam.
.lagra source to live renderThe entire source for the two-bead oscillator on the right. The compiler reads this file, the kernel walks the resulting graph, the solver advances state, the renderer reads pixels. Nothing else.
scene solver_walkthrough_oscillator { uses newtonian.classical_mechanics description "Two-bead harmonic oscillator." wasm true // landing-page bundle entity { type: ball_small, position: [-1.35, 0, 0], mass: 1.0, size: 0.35 } entity { type: ball_small, position: [ 1.35, 0, 0], mass: 1.0, size: 0.35 } bond harmonic [0, 1] { k: 2.0, r0: 2.0, damping: 0.04 } solver { dt: 0.002, steps_per_frame: 12 } }
Every token on the left maps to a typed object the engine evolves on the right. The Lagrangian-graph compilation and the verifiability-by-derivation framing for this scene are written up in the paper.
Nine particles, eight HarmonicBond nodes, one UniformAcceleration for gravity. The kernel doesn't know it's a "chain" — it just walks eight pairwise terms.
arrows show net force per bead · drag any bead · ▮▮ pauses · reset re-seeds
entity bead { mass: 1.0, size: 0.4 } entity anchor { mass: 1.0e8, size: 0.15 } // huge mass → pinned scene pendulum_chain { uses newtonian.classical_mechanics environment classical_gravity entity { type: anchor, position: [0, 3.50, 0] } entity { type: bead, position: [0, 2.95, 0] } // 7 more beads, each 0.55 below the previous bond harmonic [0, 1] { k: 120, r0: 0.55, damping: 0.10 } // 7 more pairwise bonds with the same {k, r0, damping} solver { dt: 0.003, steps_per_frame: 12 } }
Lagra is designed to ship inside an agent harness — Claude Code, Codex, or its own desktop IDE — and to be driven by code as readily as by hand.
crates/lagra-ide drives the same engine as the wasm demos above, with live validator overlays, per-particle drill-down, scene-source editing, and an MCP agents tab. Scenes spawn sub-agents that hold a typed handle to the running World and register actions as typed InterventionKind events.
Projects (avbd, optical_lagrangian, quantum_distillation, rigidformer) extend the runtime without bloating the kernel — see the repo for catalogs.
Because the entire engine is governed by a single equation, that equation itself can be changed — and the consequences measured everywhere at once. Every change becomes a falsifiable claim against the 66-scene regression suite.
The DNA helix on the right folds from first principles — 60 coarse-grained particles under Coulomb + harmonic bonds + base-pair stacking, no empirical Turner parameters in the force field. The same engine runs first-principles RNA folds, a qubit-Hamiltonian bridge for quantum-hardware execution, and the Albert harness — inspired by DeepMind's AI mathematician — which proposes Lagrangian modifications and validates each candidate against the suite.
Interventions are a natural fit for game-style state. Instead of coding mechanics, you insert entities and forces into the equation — gameplay logic and physics share the same scripting surface.
One codebase: native, mobile, wasm. The bundle on this page is ~800 KB gzipped, full parser + solver + CPU rasterizer included. On native, an optional gpu feature adds a wgpu compute-shader overlay without changing the pipeline.
36 rigid bodies, 12 layers of 3, settled on a friction floor. Drag any block — the red dot attaches a damped-spring intervention through the same surface a gameplay scripting hook would use. AVBD's contact solver keeps the stack stable through small perturbations and topples it gracefully when you yank too hard.
Differentiability is intrinsic to the Lagrangian — particles compute differentials at every step that flow back into the environment, yielding exact gradients over long trajectories for reinforcement learning, neural surrogates, or discovery loops. Trained modules (e.g. rigidformer in for AVBD's pairwise contact pass) swap in as sub-Lagrangians inside the same kernel, falling back to the exact evaluator when drift exceeds tolerance.
Conservation verifiers gate every step, so the engine trains against its own outputs without drifting off-physics. The Lagrangian formalism is scale-agnostic: the same engine simulates Q-desic geodesics around black holes and femtometer molecular dynamics, and automated agents exploring this parameter space can surface cross-scale connections that human intuition misses.
Twelve typed layers, Noether-gated each frame — the engine the ML on the left trains against.