Endocrine & Affect Simulation
Unlike standard chatbots that rely on static text prompts, AI Friend incorporates an internal neurochemical simulation. Internal affective states change how the LLM generates tokens in real time.
The Tonic + Phasic Mathematical Model
The endocrine engine tracks two primary neurochemicals: Cortisol (stress/caution) and Dopamine (reward/enthusiasm). Each hormone is decomposed into two distinct mathematical channels:
1. Tonic Channel (Affective Baseline)
The tonic baseline reflects long-term emotional equilibrium and is derived continuously from the 3D PAD (Pleasure, Arousal, Dominance) space:
2. Phasic Channel (Decaying Event-Driven Bursts)
Phasic bursts are triggered by conversational events (e.g. insults, achievements, praise, long pauses) and decay exponentially according to their calibrated half-lives:
- Dopamine Half-Life (): (Rapid reward spike and decay).
- Cortisol Half-Life (): (Prolonged stress persistence, ~75 minutes).
Because phasic channels operate independently of anti-correlated tonic baselines, the agent can experience realistic complex emotions, such as being simultaneously stressed and rewarded.
3. A Third Channel: Adrenaline
A third hormone, Adrenaline, is phasic-only — it has no tonic baseline, only a decaying burst (half-life ), fired by startle/interruption events and lifting arousal directly:
Unlike cortisol and dopamine, adrenaline doesn't have a slow-moving mood-like component — it's purely a fast reflex signal, matching its role as an interruption/shock reaction rather than a sustained mood.
Trust and Attachment (Marsh + Bowlby)
Alongside affect, every relationship tracks three independent trust components — benevolence, competence, and integrity (Marsh, 1994) — plus a separate attachment value (Bowlby). These update from the same per-turn appraisal that drives PAD:
where is relationship impact, is goal congruence, is relevance, and is norm alignment — all appraisal outputs, not hand-tuned dials. Attachment grows separately, scaled by both trust and how many interactions have happened so far:
This is why attachment is slow to build even with high trust: a friend who trusts you immediately (high benevolence/competence/integrity from the first conversation) still needs repeated interaction — the term — before attachment itself catches up. Trust can be earned in one exchange; attachment cannot. Both (trust change rate) and (attachment growth rate) are persona fields, seeded per-friend from how the description reads (see Persona Constitution) — a guarded character and a quick-to-trust one respond to the same events at genuinely different rates.
Try this live: the Trust & Attachment Visualizer in the playground runs this exact formula against appraisal sliders you control.
Dynamic LLM Sampling Modulation
Neurochemicals directly modulate LLM generation parameters during the cognitive action stream:
| Parameter | Modulated By | Impact on Generated Speech |
|---|---|---|
| Temperature | High cortisol lowers temperature (), making responses concise, cautious, and direct. | |
| Top-P | High dopamine increases top-p (), encouraging creative vocabulary, humor, and expressive metaphors. | |
| Max Tokens | Fatigue reduces token ceiling (), causing the agent to give shorter, less verbose answers when tired. | |
| Speaking Rate | High arousal accelerates speech pacing and shortens pauses. |
Authentic Emotional Friction
The agent does not artificially soften or placate when the user is rude or unreasonable. If an insult occurs:
- Valence drops, and an immediate phasic Cortisol burst fires.
- The agent's temperature drops, and deliberation selects an assertive or disengaged conversational stance.
- The response reflects authentic human annoyance, maintaining identity integrity rather than sycophantic obedience.