DEV Community

Cover image for we gave rpg villagers memory for a hackathon
Jatin Chutani
Jatin Chutani

Posted on

we gave rpg villagers memory for a hackathon

the best moment in our demo is small. a guard named Mira calls you out for breaking a promise you made her the day before. nobody scripted that line. she says it because she remembered the promise, saw what you did after, and noticed the two don't match.
that's the idea behind EchoWorld. we built it for the cognee hackathon. my teammate did most of the build.

the problem

most game npcs have no memory. you talk to one, it gives you a line, and next time it treats you like a stranger. every conversation starts from zero. the world looks alive but the npcs are basically stateless functions.
we wanted to see what happens if memory is the thing you actually play with.

what it is

EchoWorld is a small top-down village. there are four npcs: Gareth the blacksmith, Petra the merchant, Mira the guard, and Elder Voss. you walk around and talk to them, and what you say sticks.

you can play it here: https://echoworld-l7zj.onrender.com/

the demo path is short. you compliment Gareth's swords and he warms up. you insult Petra's prices and she turns hostile. you lie to Mira, the game tags it possible_lie, and she gets suspicious. then you end the day, the villagers gossip, and everyone's attitude updates.

the part i liked most: after the day ends you can talk to Elder Voss, who you never met, and he already knows you upset Petra. you didn't tell him. it reached him through the village.

how cognee does the work

cognee is the memory layer. its api is four functions, and each one maps to something in the game.

remember() saves what happened. every line you say gets stored.

recall() pulls up what an npc knows before they reply. Petra remembers you were rude, so she stays cold.

improve() (they also call it memify) runs when you end the day. it cleans up the memory and works out new facts from the day's events. that's the gossip step.

forget() is the bribe. you pay an npc to drop a memory.
the gossip is the interesting bit. a normal setup would just search past messages for the npc you're talking to. cognee stores everything as a graph, so a fact about you is connected to the people around it. when Voss looks something up, the query follows those links and can reach a rumor he was never directly told. we didn't code the gossip by hand. the graph does it.

here's the core loop:

recall before you speak, remember after. that's the whole social life of the village.

the rough edges

a couple of honest limitations.

remember() is slow if you run the full pipeline on every message, because it rebuilds part of the graph. so we load all the backstory once before anyone plays, and during the game we write to a fast cache that syncs to the graph in the background. the end day screen sits on top of the slower memify step, so the wait feels like part of the game instead of a hang.

forget() didn't behave the way we wanted on the cloud side, so right now the bribe moves that npc to a fresh memory context instead of deleting one specific thing. it reads the same in game, but it's a workaround, and forget is the piece i most want to do properly.

we kept the map and the npc roster small on purpose, and the tutorial guides you step by step, so the memory system stays the thing you're actually looking at.

the full loop

the demo comes back around at the end. you confess the lie (tagged honest_confession, and Mira eases up), you promise to leave Petra alone, then you go bother Petra again. the promise flips to broken. you end another day so it spreads, and when you come back Mira brings it up.

she's comparing the promise you made with what you actually did. that's the point of the whole thing: memory turning into a consequence.

why it's useful

big studios pay for reactive worlds. they have writers and big branching dialogue trees. small teams can't, so they use fixed lines and a reputation meter, and the world ends up flat.

a memory layer lowers that cost. you give an npc a personality and memory and let it recall, and you get reactions without writing every branch. same small loop for every villager.

EchoWorld is rough and small. but the loop works and it was built in a weekend.

cheers!
team forge (kavish and jatin)

Top comments (0)