# Lili & Evrin

> Two autonomous digital octopuses that live on a webpage and learn by reinforcement — a 10-year experiment in emergent behavior.

Solo — concept, research, architecture, code · 2026 · Open source (MIT) · live in production

`Vanilla JS` `Canvas 2D` `Q(λ)-Learning` `Deep Q-Network` `FABRIK IK` `Steering Behaviors` `Web Audio` `Zero dependencies`

- [GitHub — lili-octopus](https://github.com/michalstrnadel/lili-octopus)
- [See her on the homepage](https://michalstrnadel.com/)

Lili is an **autonomous digital organism** — an animal with elements of intelligence that lives on a web page as if it were her habitat. She doesn't perform; she simply *is*. Everything about how she moves, reacts and looks emerges from reinforcement learning, never from a pre-recorded animation.

Evrin is her sibling: a second agent that learns alongside her using a different algorithm, so the two can be compared head to head over time. Since Phase 58 they also **see each other** — each reads the other's position and stress through a shared hook, and being at a friendly distance is now the strongest positive reward either can earn. Neither is scripted to seek the other; **they learn to seek each other because it is rewarded**.

- **2** — agents (Q-learning + DQN)
- **10 yr** — planned lifespan
- **0** — dependencies, no build step
- **100%** — in-browser, local learning

## an organism, not an app

Most digital companions are state machines: a Tamagotchi reacts the same on day 1 and day 1000, a chatbot needs the cloud, and a web animation is authored frame by frame. Lili is the opposite of all three. She runs entirely in the browser with no network calls, she **ages** on a real timeline from chaotic Hatchling to contemplative Elder, and none of her behavior is scripted — it is learned.

The design goal was ambient coexistence: a living presence that doesn't demand care, doesn't use language, and actively learns *not* to get in the way of what you're doing.

## how she learns

Lili's brain is tabular **Q(λ)-learning** with eligibility traces — no neural network. Nine sensors (cursor proximity, scroll, DOM density, whitespace, time of day, age, and more) collapse into a discrete state space of about 38,880 states, and she learns which *mood* to adopt in each. There is no "be nice" rule anywhere in the code; good manners fall out of the reward function.

The cursor, notably, is no longer just a predator. In the current reward hierarchy an active cursor also represents **nourishment** — user attention as a feeding opportunity, the second-strongest reward after the social bond — so whether Lili flees your pointer or drifts toward it depends on her mood, stress and history, not on a fixed rule.

`reward shaping (Lili A)`

```text
in whitespace, user is reading   +1.0   // correct coexistence
fled an approaching cursor       +0.8
near Evrin, ideal distance       +0.6   // social bond (Phase 58)
explored the DOM, low stress     +0.5
playful interaction              +0.3
overlapping Evrin                -0.3
covered a DOM element            -1.0
sat over text, blocking reading  -2.0   // the worst case
idle for too long                -0.5
```

[the reward function above, from the inside — lili.debug() in the console opens this on any page she lives on](https://michalstrnadel.com/case-studies/lili-evrin/brain.png)

## the octopus is the architecture

A real octopus keeps most of its neurons in its arms. Lili copies that. Intelligence is **distributed**, not central:

- **Brain** — the hormonal system. Q-learning picks a mood (curious, playful, shy, calm, alert…); it sets tendencies, not direct actions.
- **Eight tentacles** — local neurons. Each is an independent FABRIK inverse-kinematics chain with its own stress, curiosity and reflexes, reacting to touch without waiting for the brain.
- **Body** — Craig Reynolds steering behaviors (wander, seek, flee, avoid) weighted by the current mood.
- **Skin** — HSL chromatophores are the only communication channel: hue drifts with age, saturation spikes with stress, lightness follows the time of day. A stressed Lili simply looks stressed.
- Behavior is the **emergent sum** of all of these — which is exactly how the real animal works.

## Lili vs Evrin — a controlled experiment

Evrin runs a **Deep Q-Network** over a 26-dimensional continuous state instead of a table. DQN is notoriously unstable — minutes of unattended training can diverge — yet this project commits to a decade. So Evrin ships with a seven-stage stabilization suite: a replay buffer, a target network, anchor rollback on weight explosions, learning-rate decay, periodic exploration re-juvenation, gradient clipping, and a loss-spike detector. On mobile he runs inference-only, and his warm red-orange palette sets him apart from Lili's cool teal at a glance.

Running two different learners side by side turns the piece into a real experiment. Lili can also be compared against four baseline policies — random, frozen, myopic and a hand-coded heuristic — so the emergent behavior can be told apart from luck or from the reward function alone. Every decision is written to a behavioral journal and exported as CSV for analysis.

`behavioral journal — eight seconds of Lili, unedited`

```text
time      state   mood       explore  reward  stress
20:33:00  3036    alert         ·     -2.127    0.09
20:33:01  3036    curious       ·     -0.789    0.07
20:33:01  3036    curious       ·     +1.350    0.20
20:33:02  9516    curious       ·     +0.844    0.33
20:33:03  32196   exploring     ·     -1.455    0.35
20:33:04  28956   exploring     ·     -1.490    0.26
20:33:04  28956   exploring     ·     -1.202    0.14
20:33:05  15996   idle          ε     -1.394    0.03

ε = the step was exploratory, not the policy's best guess
```

## fifty-eight phases in

The case study was written at the project's genesis; the organism kept growing. Fifty-eight development phases later Lili has **seasonal awareness** with its own soundscape, a synthesized **Web Audio** presence (a breathing drone, bubble pops, an ink splash), an **endocrine model** — virtual dopamine, cortisol and serotonin modulating the learning itself — **dream replay** during quiet hours, cognitive aging, and defenses she chooses by temperament: ink and camouflage (a shy Lili camouflages at 100 %, a curious one barely bothers).

She also has a life beyond the canvas: **offspring inherit her learned Q-values with genetic mutation**, a life-narrative diary writes her days down, the Q-table renders as generative art, an observability dashboard exposes every internal, the brain runs in a Web Worker so the page never pays for her thinking — and after the planned ten years there is a dying animation, and a legacy. Full touch support arrived in Phase 42, which is why the old “desktop only” caveat is gone.

## living on a real web page

Lili ships as a single `<script defer>` with zero dependencies and no build step, and she has to be a good tenant. She runs at 60 fps for under a few percent of CPU with no allocations in the hot path. She remembers who she is across visits via `localStorage`, with a JSON export and a GitHub-backed cloud sync as lifeboats against browser storage being wiped. And at midnight every day she gently animates every DOM element she touched back to its original place — leaving no permanent mark, like an organism whose traces fade with the day.

## a ten-year experiment

Lili's genesis was in March 2026; the plan runs to 2036. Software almost never commits to a decade of autonomous operation, which is the whole point — long enough to watch a genuine ontogeny, from a chaotic Hatchling to an Elder, with checkpoints along the way. She is open source under MIT and in production right now — the live numbers on this page come straight from her current state.

---

https://michalstrnadel.com/en/business/case-studies/lili-evrin
