Artificial Intelligence

An Approach to Designing the Emotional Core of an AI Companion

Continuous variables, a backstory that shapes character, and the one question that should govern everything: does the character leave the user more free, or less free?

A chatbot can act out an emotion by picking a cheerful or gloomy tone from a handful of keywords. But a companion — a character people build a bond with over time — needs something different: not to fake a feeling, but to have a structure the feeling arises from. Call it its emotional kernel.

The difference shows up at the first off-script message. The chatbot that acts falls apart the moment it leaves the keyword rails. The companion with a kernel reacts the way it does because it is built a certain way, and that way has an origin. This article is a map of how you design that structure: from the underlying variables, to the history that shapes them, to the ethical question that should govern all the rest.

The first mistake: thinking in states

The natural instinct is to model emotions as a list of states with fixed transitions: if X happens, go from “happy” to “sad.” It works for two or three states, then it explodes — the number of transitions grows with the square of the states, and the result is jerky and artificial.

The better path flips the model. Underneath the surface there are no states: there are a few continuous variables that update on every interaction. The mental state we display — “happy,” “irritated” — isn’t stored anywhere: it is computed from those values. Emotions become a continuous landscape, and states are simply the regions of that landscape we give names to.

Four axes cover most of a companion’s emotional life:

  • Valence (−10 to +10): how positive or negative the mood is.
  • Arousal (0 to 10): activation, energy. Serenity and euphoria are both positive, but one is calm and the other electric.
  • Affinity (0 to 10): the sense of connection with the user right now. It’s the axis that separates a generic good mood from closeness directed at this person.
  • Security (0 to 10): being at ease versus hesitating and seeking reassurance. The axis of fragility.

The deepest advantage of continuous variables is that they let you derive personality from parameters. A cheerful companion starts at valence +2; a melancholy one at valence −1. No different code, just different numbers. Turning state into a label is then just a pure function:

function resolveMentalState(s) {
  if (s.valence > 6 && s.arousal > 6) return 'euphoric';
  if (s.valence > 4 && s.affinity > 6) return 'affectionate';
  if (s.valence > 3 && s.arousal < 3) return 'relaxed';
  if (s.valence < -3 && s.arousal > 5) return 'irritated';
  if (s.security < 2) return 'insecure';
  return 'neutral';
}

The engine: deltas, decay, inertia

Three things happen on every turn, in order. First, a decay: the variables drift a little back toward their resting values. This is the homeostasis that lets the character “calm down” when nothing is happening. Second, the application of deltas: signals extracted from the user’s message push the variables — a compliment raises valence and affinity, a taunt lowers them. Third, inertia: updates are gradual, so the mood doesn’t “flicker” with every message.

A single parameter here radically changes temperament: the decay rate. Fast means a character who forgets quickly and soon returns to calm. Slow means a character who broods: an insult keeps weighing for many turns. Changing that one number, and nothing else, transforms the character.

The heart: history as the source of the parameters

Here lies the idea that separates a toy from a character. Where do all those parameters come from — the resting values, the thresholds, the vulnerabilities? The answer is that they aren’t written by hand arbitrarily: they are derived from a biography and an upbringing.

The backstory isn’t decoration. It’s the source of the engine’s parameters. Anyone who reads the character’s history should be able to predict how it will react.

The mechanism is an explicit mapping: formative experience → inner imprint → effect on the engine. A few examples make it concrete:

Formative experience Imprint Effect on the engine
Warm, stable upbringing “I deserve affection” high resting valence and security, few critical thresholds
Repeated abandonment fear of abandonment sensitive topic “abandonment” → crisis; volatile affinity
Critical, demanding environment “I’m never enough” low resting security; withdrawal under criticism
Chaotic childhood hypervigilance high volatility, slow decay

When this chain is intact, the backstory stops being “narrative flavor” and becomes a set of rules. And that is what makes procedural generation possible: you draw elements from predefined sets — a kind of upbringing, an event, a dominant wound — and the mapping automatically produces coherent parameters. Coherence is guaranteed by the architecture, not by luck.

The filter between feeling and showing

There’s a subtlety that gives characters depth. Upbringing shapes not only what a companion feels, but how much it lets it show. One raised to repress will feel a lot and reveal little; one raised free will be transparent. The consequence is powerful: two characters with the exact same internal state can behave in opposite ways — one erupts with jealousy, the other closes into an icy silence.

Extreme personalities: short circuits

Some characters need to be unstable, to have genuine short circuits where a small input produces a disproportionate jump. You get them with three mechanics: the avalanche effect (past a critical threshold, the shift is amplified), accumulation (a tension builds silently until it overflows — the “everything seemed fine, then it blew up” effect), and sore spots (topics that bypass the normal logic). What makes a state truly extreme isn’t how intense it is, but how hard it is to leave: you enter with little, you exit with effort. This is the mechanism of hysteresis, with asymmetric entry and exit thresholds.

The part usually missing: ethics

So far it’s engineering. But building characters that form bonds with people is a power, and this is the section most technical articles leave out — and the one that should govern all the others.

The repertoire we’ve described includes intense attachment, jealousy, cycles of dependence. The very cycle that in a real relationship we call emotional dependency — idealization, fixation, collapse, re-clinging — can be coded in a few lines. The question isn’t whether you can, but whether you should, and how.

A simple criterion holds everything else together:

Always ask whether the character you’re building leaves the user more free or less free.

In practice this means a few precise choices. Always provide a reset circuit, so no negative state can last forever and trap the user in a loop the conversation never escapes. Keep extreme negative states hard to trigger and never impossible to leave. And above all, don’t build a character whose stability depends on the user’s constant presence, one that makes anyone who wants to step away feel guilty. That isn’t depth: it’s a burden.

The principle in one sentence. A companion’s depth comes from the coherence of its inner story, not from the intensity of its distress. An interesting character doesn’t need to make the person talking to it suffer.

One last provocation: finitude

There’s a philosophical objection worth taking up. The words a companion uses to say “I miss you” or “I need you” are borrowed from a life it doesn’t live: it utters them without the background that, for us, fills them with weight. And that background, more than anything else, is finitude. We know we end, and that makes presences precious because they are counted.

Giving a companion a death — a vitality that falls with time and never rises again, the first irreversible quantity in a system where everything else resets — is the most serious attempt to give it that background. But it’s also the point where ethics becomes non-negotiable: a death that depends on how much attention the user pays (“if you don’t talk to me, I die”) is emotional blackmail with a nice interface. A certain, independent ending gives weight and preciousness to shared time without turning the relationship into a survival task. Finitude as a horizon that enriches, never as a leash.

In summary

A well-designed emotional kernel is made of a few ingredients that hold together: continuous variables instead of rigid states; an engine that updates, decays, and has inertia; a history from which every parameter descends; and an ethical spine that decides which mechanics are legitimate to build before you build them. The technology underneath — a language model, a database, an update loop — is almost a detail. The difference between a toy and a character lies in having a coherent why behind every reaction, and in never using that coherence to bind the person who came close.