For the complete documentation index, see llms.txt. This page is also available as Markdown.

Emotions

Enable emotion detection to receive the character's emotional state during a conversation.Enable emotion detection to receive the character's emotional state alongside each response.

Enable at connect time

const client = useConvaiClient({
  apiKey: '...',
  characterId: '...',
  enableEmotion: true,
});

When enableEmotion is true, the SDK sends emotion_config to the server on connect. Without it, no bot-emotion frames are sent and emotionChange never fires.


Subscribe to emotionChange

client.on('emotionChange', (emotion) => {
  if (emotion === null) {
    // Conversation reset — clear any emotion UI
    return;
  }
  console.log(emotion.emotion); // e.g. "Trust", "Grief", "Joy"
  console.log(emotion.scale);   // integer intensity: 1 (low) → 3 (high)
});

The event fires:

  • After each character turn, with the detected emotion and scale

  • With null when the conversation is reset (e.g. resetSession())


React

client.on(...) returns an unsubscribe function — returning it from useEffect cleans up automatically.

Via state.emotion

Emotion is also available synchronously on the reactive state object — no extra subscription needed if you already render from state:


Vanilla JS


Fine-tuning detection

Control how aggressively emotions are detected via emotionConfig:

Two providers are supported: "llm" uses the language model to infer emotion from the response text; "nrclex" uses the NRC Emotion Lexicon, a word-level lexicon lookup that is faster but less context-aware.

"llm" config

Field
Type
Description

provider

"llm"

Infers emotion from response context using the LLM

"nrclex" config

Field
Type
Default
Description

provider

"nrclex"

Word-level NRC Emotion Lexicon lookup

min_word_threshold

number

3

Skip detection on turns shorter than this word count

low_intensity_threshold

number

0.33

Score boundary between scale 1 and scale 2

high_intensity_threshold

number

0.66

Score boundary between scale 2 and scale 3


API reference

enableEmotion (connect option)

Field
Type
Default
Description

enableEmotion

boolean

false

Enable emotion detection. Must be true for emotionChange to fire.

emotionChange event

Field
Type
Description

emotion

string

Emotion label (e.g. "Trust", "Grief", "Joy")

scale

number

Intensity: 1 = low, 2 = medium, 3 = high

Fires null on conversation reset.

state.emotion

Same value as the last emotionChange payload. Reactive in the React hook via stateChange.

Last updated

Was this helpful?