molroo docs
Guides

Speaking Style

Give your persona a consistent speaking style extracted from real text.

Speaking Style

molroo can capture and reproduce a character's unique speaking style. Extract a style profile from sample text, set it on your persona, and every response will follow that style — automatically adjusted by the persona's current emotional state.

How it works

Sample text (chat logs, writing samples)
        |
        v
persona.extractStyleProfile()   SDK → API (extraction + storage)
        |
        v
persona.chat()                   Style constraints auto-injected into system prompt

Style constraints are generated server-side and included automatically in the system prompt. You never need to write style instructions yourself.

Quick start

import { Molroo } from '@molroo-io/sdk';
import { createOpenAI } from '@ai-sdk/openai';

const molroo = new Molroo({ apiKey: 'mk_live_...' });
const openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY! });

const persona = await molroo.createPersona(
  {
    identity: { name: 'Sera', role: 'barista' },
    personality: { O: 0.7, C: 0.6, E: 0.8, A: 0.9, N: 0.3, H: 0.8 },
  },
  { llm: openai('gpt-4o-mini') },
);

// Extract style from sample text — done once
const profile = await persona.extractStyleProfile([
  'omg that latte art is gorgeous!!',
  'haha yeah i always double-shot my espressos~',
  'u should try the oat milk version tho, its rly good',
  // ... more messages (20-30 recommended)
]);

// Every chat() call now follows this style
let history: Message[] = [];
const result = await persona.chat('What do you recommend?', { history });
// Response text will naturally match the extracted speaking style

What the profile captures

The extracted StyleProfile analyzes patterns in the sample text:

CategoryExamples
VocabularyWord choice frequency, casual vs. formal register
StructureSentence length, paragraph patterns, response length
PunctuationEmoji usage, ellipsis patterns, exclamation frequency
RegisterFormality level, slang density, hedging patterns

The more sample text you provide, the more accurate the profile. We recommend at least 20-30 messages for reliable extraction.

Emotion-aware modulation

The style isn't static. When the persona's emotional state changes, the speaking style adapts naturally:

  • A normally casual character becomes more terse when angry
  • Punctuation patterns shift under stress
  • Response length may change based on arousal level

This happens automatically — you don't need to manage it.

Extraction options

const profile = await persona.extractStyleProfile(messages, {
  timestamps: [1700000000, ...],   // Optional: message timestamps for temporal analysis
  otherMessages: ['...'],          // Optional: other people's messages for contrast
});

Next steps

On this page