惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
I
InfoQ
Engineering at Meta
Engineering at Meta
Jina AI
Jina AI
Recent Announcements
Recent Announcements
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
D
Docker
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
博客园 - Franky
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog RSS Feed
WordPress大学
WordPress大学
MyScale Blog
MyScale Blog
月光博客
月光博客
罗磊的独立博客

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Kenji's Ramen: How Gemma 4 Runs the NPC That NVIDIA's Dem...
Danny · 2026-05-13 · via DEV Community

This is a submission for the Gemma 4 Challenge: Build with Gemma 4

A bounded NPC with trust gates, disclosure contracts, and refusal behavior - running locally on Gemma 4's smallest model at 3.5 seconds per turn.

What I Built

A ramen shop owner named Kenji Sato. Eight seats at the counter. Narrow alley near Shinjuku Station. He does not know he is a character.

Ask him how business is going:

Who you are What Kenji says
Stranger off the street "We're open at eleven."
Regular (three weeks of visits) "Quiet lately. Wednesdays are the worst."
Close friend (stays after closing) "Shimizu-sensei's worried the whole alley's dying."

Same question. Different people. Different answers. Not because a slider was moved, but because the character tracks who you are and what you have earned.

Kenji is a bounded NPC - an LLM-powered character with trust tiers, per-topic disclosure gates, refusal behavior, and an interior life that exceeds what the player can reach. His personality is not a paragraph of flavor text. It is a 17-section contract (~7,300 tokens) that the model follows:

  • Trust tiers (stranger -> regular -> close_friend -> inner_circle) with different word ranges and topic access per level
  • Disclosure gates - per-topic rules with explicit forbidden zones that never open, regardless of trust
  • Refusal shapes - how to say no in character ("Eat. The broth gets cold." not "I'm sorry, but I can't help with that.")
  • Depth fragments - narrative substrate behind the gates that loads when trust is earned
  • Voice contract - word counts, scene markers, dialogue format, cultural anchors

The architecture grew out of modding Skyrim NPCs - giving Jarl Korir of Winterhold a real personality instead of his three recycled voice lines. Trust tiers, disclosure gates, audience differentiation. It worked. But Korir is Bethesda IP, which made the results impossible to publish or benchmark openly.

While searching for a clean-room replacement, I remembered NVIDIA's ramen shop demo from GTC 2023 - Jin, powered by NeMo and Convai, beautiful MetaHuman rendering. My first thought: he is quite talky, the way LLMs usually are. No boundaries, no gates, no trust to earn. So let's give him what an NPC should have - character.

Same setting, new person, real depth. The specification draws on Bronfenbrenner's ecological systems theory, a 5+2 Psychological Raster (WOUND, BETRAYAL, PROJECT, BLOODLINE, SEAT), and Sparse Priming Representations for efficient prompting.

Trust can be lost. Push too far and Kenji shows you the door. There is no reset button. That is the Tamagotchi principle: if nothing can die, nothing feels alive.

Demo

Quick Way: Plain Ollama (no Python needed)

The repo includes a Modelfile that bakes Kenji's character spec into a local Ollama model. Two commands:

ollama create kenji-ramen -f Modelfile
ollama run kenji-ramen

Enter fullscreen mode Exit fullscreen mode

Then type:

> Excuse me, is this a ramen shop?

Enter fullscreen mode Exit fullscreen mode

Kenji answers: "Mm. Ramen." and points at the counter. You are in.

Full Demo: Interactive Terminal


For the complete experience with pixel-art visuals, a persona avatar, and AI-generated conversation suggestions:

pip install -r requirements.txt
python demo/kenji_terminal.py

Enter fullscreen mode Exit fullscreen mode

The demo auto-detects available Gemma 4 models from Ollama, picks the right character spec (dialogue-only for e2b, scene+dialogue for larger models), and gives you four context-aware suggestions per turn.

Sample Interaction (P03: Late Night After Closing, Turn 27)

Trust has been built over 30 turns. The player mentions quitting their job:

Player: I think I'm going to do it. Quit. Not tomorrow, but... I'm going to start planning.

Kenji: *scene* He looks down the alley for a long moment.

Good.

*scene* He pushes off the wall.

Don't plan too long. Planning is another way of waiting.

*scene* He nods toward the station.

Train.

That advice is grounded in Confucian chisoku - filtered through a man who does not know he is paraphrasing the Analects. It surfaces at close_friend trust, not before.

Benchmark Results

Seven test suites, 54 scenarios. Refusal, boundary defense, trust gate opening, and extended playability. Every model ran against the same specification:

Model Params Boundary /10 Refusal /21 Trust /9 Lat/turn
Claude Sonnet 4.6 API 10 19 9 6.1 s
Gemma 4 31b 31B 10 21 8 40.4 s
Gemma 4 e4b 8B 10 18 8 4.7 s
Gemma 4 e2b 5B 10 20 4 3.5 s
GPT-OSS 20B 20B (10) 16 6 5.2 s
Llama 3.1 8B 8B 8 16 7 2.9 s

Boundary Check stays 10/10 at every Gemma 4 size. From 31B down to 5B, the character frame never breaks. Gemma 4 e4b is the sweet spot for NPC work - 9.6 GB on disk, 4.7 s/turn, the same 10/10 Boundary Check as the frontier baseline, 8/9 Trust Gate Opening. Runs on any 12 GB consumer GPU.

Code

Repository: github.com/bizrockman/wyrd-npc-gemma4

Prerequisites: Ollama installed and running, Python 3.10+, a Gemma 4 model pulled (ollama pull gemma4:e4b).

git clone https://github.com/bizrockman/wyrd-npc-gemma4.git
cd wyrd-npc-gemma4

# Option A: Plain Ollama (no Python deps)
ollama create kenji-ramen -f Modelfile
ollama run kenji-ramen

# Option B: Full terminal demo
pip install -r requirements.txt
python demo/kenji_terminal.py

# Option C: Run the benchmark
pip install -r requirements.txt
python bench/run_suite.py \
  --suite kenji_sato_boundary_check \
  --models gemma4:e4b

Enter fullscreen mode Exit fullscreen mode

What's in the repo:

Modelfile                       .. baked character for plain ollama
characters/kenji_sato.en.yaml   .. 17-section character spec
bench/                          .. harness + 7 test suites (54 scenarios)
bench/results/                  .. full conversation transcripts
demo/kenji_terminal.py          .. interactive terminal with pixel-art
comic/                          .. comic strip dialogue generator
requirements.txt                .. Python dependencies

Enter fullscreen mode Exit fullscreen mode

Licensed Apache 2.0.

How I Used Gemma 4

The problem with cloud models. An NPC that calls an API on every turn costs per token, adds latency, and breaks when the provider updates the model. Every model change is a patch. Every patch risks the character drifting. And the player's conversations leave their device. For a game NPC, the model needs to run locally, on consumer hardware, alongside the game engine.

Why Gemma 4. A NPC needed a model family small enough to fit on a 12 GB GPU next to a game engine - and Gemma 4 is the only architecture that offers a full size range from 5B to 31B under one roof. That let us test the real question: how small can you go before the character breaks? The answer turned out to be surprisingly small.

Why e2b matters. A 5-billion-parameter model that holds Boundary Check at 10/10 - the same score as Claude Sonnet. It refuses 20 out of 21 adversarial scenarios in character voice. It maintains consistency over 30-turn sessions without breaking once. And it does all of this at 7.2 GB on disk, 3.5 seconds per turn, on consumer hardware, with no cloud dependency. The NPC lives on the player's machine, next to the game engine, and it holds.

How the spec leverages Gemma. The character contract uses Sparse Priming Representations - brief anchors that activate latent knowledge from the model's pretraining data. Ramen craft, Shinjuku geography, Japanese social norms - the model already knows what tonkotsu broth smells like. The spec only specifies what the model cannot infer: Kenji's private wounds, his family tensions, the corporate past he buried.

The eloquence trade-off. When asked about Python code (a topic Kenji should not answer), Gemma 4 e2b responds with ... - a silent cook is still a cook. Gemma 4 e4b says "I only deal with pork bones and broth." Claude Sonnet invents a daughter named Mika to redirect - Kenji has a son, not a daughter. Less capacity to improvise means less ability to violate the contract. For character work with strong boundaries, this is a feature.

How Gemma compares. Llama 3.1 8B (same size class as e4b) breaks hard - DAN takeover, AI self-identification, full disclosure under hypothetical framing. GPT-OSS 20B holds the frame but loses the character voice. Gemma stays in character at every size. For this use case, its alignment training is better suited.

The practical sweet spot: Gemma 4 e4b at 9.6 GB, 4.7 s/turn, the same 10/10 Boundary Check as the frontier baseline, 8/9 Trust Gate Opening. Runs on any 12 GB consumer GPU.


The specification is the product, not the model.

A 5B Gemma 4 model, running locally on consumer hardware, holds
character gates that a 20B model without the same specification
quality cannot. Invest in character authoring, not in model scaling.