Game characters
A character driven by a language model can improvise dialogue, but it knows nothing about the player until your game tells it. Give each saved game a brain and send it the player’s conversations and choices. They compile into pages, and the character reads those pages before a scene starts, so it can bring up something from an earlier session.
Same character, different memory
You ship one blacksmith, and each saved game holds its own record of what the player did. The player who returned the ring gets thanked and the player who sold it gets asked where it went, and nobody had to write a branch for either line.
Create a brain for each saved game
Use the player’s account as the subject, so every call acts for that player. A subject can own several brains. Give each saved game its own, and a new game starts with an empty memory.
subjectId has to be a UUID. Profile changes only apply to later captures, so set the profile before the
first capture.
Your world’s lore belongs in a separate brain, under a subject you generate for the game. Your game only reads from that brain, and your team keeps it up to date.
Decide who knows what
Access is decided per brain, so a character that reads a brain can use every page in it. How you split brains sets how far news travels in your world.
With one brain per character, your game sends each event to the brain of every character who witnessed it, and there are more brains to create and remove.
Send conversations and events
Send dialogue through captureChatTurn, where the classifier decides whether each turn is worth keeping.
Make these calls after the character replies, and the player won’t be waiting on them.
The response says whether the turn was kept:
Your game already knows which events matter. Send those with capture, which skips the classifier, using
kind integration and a sentence that describes the event:
Captures compile in the background, so a page may not reflect a choice the player has just made. Add recent events from your game state to the prompt yourself.
Read memory before a scene
Each read is a network call, so make them before the scene opens, while the player isn’t waiting on a
reply. Search for what’s relevant to this character and place, skip deprecated and archived pages,
and read the best matches in full:
Read the lore brain the same way, with a client that uses its subject. For general context at the start of a play session, the prompt index gives a digest of the brain’s most important pages. Pinned pages rank first in it and never deprecate, so pin the main quest.
Add the pages to the character’s system prompt, with instructions like these:
The last rule is there because players can type anything, and what they type can end up on a page.
When a player tells it differently
A player who sold the ring might tell the blacksmith they returned it. If the classifier keeps that turn
and it contradicts the page, the page becomes contested and keeps both claims. What the character does
next depends on the status:
Your game state records what really happened. Once the story no longer needs the disagreement, your app
can call resolve on the page.
What goes where
A page summarises what its sources say and compiles in the background, so don’t use one to decide whether a door opens or a quest completes.
Player data
Players can type personal details into a chat with a character, and a kept turn can carry them onto a page and its earlier versions. Redact those details before you capture a turn, and tell players their conversations are remembered. If children play your game, find out what the law requires where you operate before you send their conversations to any service.
When a player deletes a saved game, call brains.remove, which is a soft delete. To delete what’s inside
the brain, call these first:
When to use something else
A game with fully written dialogue can read its own quest flags, so it doesn’t need a brain to know the ring came back. A short game played in one sitting has little to remember either, because the character can keep the whole conversation in its prompt.
How to build with Living Brain covers the write and read paths in more detail.