How Do AI Characters Work? Prompts, Memory, Models

How Do AI Characters Work? Prompts, Memory, Models

An AI character is a language model plus a block of text that tells it who to be. There is no separate character program running in the background. Every time you send a message, the app builds a prompt containing the character’s description, part of your recent conversation and whatever it has saved about you, then asks the model to predict what that character says next.

Once you see what goes into that prompt, most of the odd behavior makes sense: why characters drift, why they forget, and why the same character feels sharper in one app than another.

What the model is actually doing #

A large language model predicts text. Given a sequence of words, it produces a likely continuation, one token at a time. A token is roughly three quarters of a word, so “Seraphina laughed” is about three tokens.

The model has no memory between requests and no knowledge of you. Everything it appears to know arrives in the prompt, every single turn. When a character says “you told me you work nights,” the app put that fact in front of the model moments earlier. Nothing persists inside the model itself.

That’s why the prompt is the whole ballgame. A character is well written or badly written in exactly the way a prompt is.

What’s in the prompt on every turn #

Most companion and roleplay apps assemble something like this before each reply:

PartWhat it holdsRoughly how much
System instructionsHow to behave: stay in character, write in first person, don’t narrate for the userA few hundred tokens
Character definitionName, age, personality traits, backstory, speaking style, appearance, what they call you200-800 tokens
ScenarioWhere this conversation is set and what’s happening50-200 tokens
Relationship stateMood, how close you are, the current story arcUnder 100 tokens
Rolling summaryA compressed account of everything earlier in the chat200-500 tokens
Retrieved factsThe saved details judged relevant to what you just said100-400 tokens
Recent messagesThe last stretch of conversation, word for wordThe bulk of what’s left
Your new messageWhat you just typedWhatever you wrote

All of it has to fit in the model’s context window. Everything that doesn’t fit gets dropped, which is the single biggest source of “why did it forget that?” complaints. We go through that failure in why AI chatbots forget things.

Where the character definition comes from #

Three ways, depending on the app.

Curated characters are written by the developer. Someone wrote the personality traits, the backstory and the speaking style by hand, usually with art to match, and tested them against the app’s model. These tend to hold together best because they were tuned for the model actually shipping.

Characters you write come from a form: a name, some traits, a description, a greeting. What you type lands almost verbatim in the prompt, which is why vague descriptions produce vague characters. The practical guidance is in how to write a good AI character description.

Characters the model writes are the quick-create path. You give an archetype and a sentence, and the model fills in the rest of the fields. Xin does this on the device: you enter a name, an age (18 and over), anime or realistic, and one line about who they are, and its on-device model writes the traits, backstory and speaking style into a proper character record you can then edit. It takes about thirty seconds and produces a fuller definition than most people write by hand.

Why the fields are separate #

It would be simpler to have one big text box. Apps split the definition into named fields because the fields get used differently. Speaking style can be restated near the end of the prompt where it has more influence on the next sentence. Appearance can be pulled in only when a scene calls for it. Age gets checked against a rule rather than read as prose. A structured character is also editable without rewriting the whole thing, and edits can be versioned so an ongoing chat doesn’t break.

How a character stays in character #

Three mechanisms do most of the work.

  1. Repetition of the definition. The character card sits in the prompt on every turn, not just the first. That’s why a character doesn’t dissolve after ten messages the way a one-off instruction to a general assistant does.
  2. The conversation as an example. The model imitates patterns it can see. After twenty messages in a consistent voice, the strongest evidence for how this character talks is the transcript itself.
  3. Sampling settings. Temperature, top-p and repetition penalty control how adventurous the next-token choice is. Companion apps usually run warmer than a factual assistant, because a predictable partner is a boring one.

Point two cuts both ways. If replies start going flat or repetitive, the model is copying flat, repetitive examples, and it will keep doing so until you change what it can see. Fixing repetitive AI chatbot replies covers the ways out.

Why the same character feels different in two apps #

Paste an identical character description into two apps and you’ll get two different personalities. The definition is only one input among several.

  • Model size. A 2-billion-parameter model and a 70-billion-parameter model read the same description with very different comprehension. Bigger models hold contradictions in mind, catch subtext and stay consistent longer.
  • Context window. A model with room for 4,000 tokens keeps a much shorter stretch of conversation verbatim than one with 32,000.
  • System prompt. Each app wraps your character in its own instructions, and those can dominate. An app that tells the model to keep replies to four sentences will produce a tighter character than one that doesn’t.
  • Memory design. Whether saved facts exist at all, how they’re chosen, and whether they’re pinned into every prompt.
  • Safety filters. Some apps post-process or block replies, which shows up as a character suddenly going stiff.

None of this is visible from the outside, which is why “this app’s characters are smarter” usually means “this app’s prompt assembly is better,” not that anyone trained a custom model.

What an AI character doesn’t have #

Worth being clear about, because the illusion is good:

  • No continuous existence. The character isn’t thinking between your messages. Nothing runs until you send something.
  • No beliefs or feelings. Mood and trust values are numbers the app tracks and inserts into the prompt so replies stay consistent. They’re bookkeeping, not an inner life.
  • No reliable self-knowledge. Ask a character how its memory works and you’ll get a plausible story that has nothing to do with the code. It’s predicting what such a character would say.
  • No guarantee of truth. A character will state things about the world confidently and be wrong, because it’s generating fitting dialogue, not checking facts.

Knowing the mechanism doesn’t spoil the experience much. It mostly makes you better at steering it.

Frequently asked questions #

Is each AI character a separate AI? #

No. One model serves every character in an app. What differs is the text put in front of it: the character definition, the scenario and the saved memories. Switching characters swaps that text, not the model.

Why does my AI character contradict its own backstory? #

Usually because the backstory has scrolled out of reach, or because it contradicts itself. If the definition says a character is shy and also the life of every party, the model will pick whichever fits the moment. Cut the contradiction, keep the description short, and put the details that matter most near the start.

Do AI characters learn from talking to me? #

Not in the sense of the model changing. The model’s weights stay fixed. What changes is the app’s saved notes about you, which get fed back into later prompts. That’s a memory store, not learning, and it’s why you can usually edit or delete what it “learned.” See how AI companion memory works.

Can an AI character run without the internet? #

Yes, if the model runs on your phone. Apps that do on-device inference download a model file once and generate replies locally, so characters work in airplane mode. Cloud apps send every message to a server and stop working offline.

How much text should a character definition be? #

Two to four hundred words is plenty for most apps. Past that you’re spending context budget that would otherwise hold conversation, and the model pays less attention to any individual line. Specific and short beats long and thorough.