Moving the Baker Out: A Spec for Running One NPC as Its Own Service

Jory’s flour arithmetic at 09:00 on the first morning of The Thirteenth Loaf ran in the same Python process as everyone else’s thinking. So did his request to Mara for one flour, and so did the engine’s refusal when he tried to accept Elsie’s twelve-loaf order before that flour was on his shelf. NPCSIM’s controller has one asynchronous worker. It picks whose turn it is and keeps every villager’s memory in a single map called agents, twelve entries side by side. Generation 27 is the spec for moving one of those entries out of the building.

The spec calls the result an independent NPC service. Jory is the example binding (an operator can pick any actor, and the default is still nobody), and he would get a long-running process of his own plus an LLM endpoint nobody else in the village shares. That process keeps his private checkpoint: memory, plans, wait state, counters and the last world revision he accepted. The example points him at a 4B model on a local port. Everything else stays put. There is still one authoritative world and one shared clock, and the coordinator still decides whose turn it is and which actions reach the world.

Why only one

The first release allows at most one external actor per episode. That’s a configuration limit, not a protocol limit, so lifting it later shouldn’t change anything that goes over the wire. I’d rather find out how leases break on one baker than on twelve villagers timing out together. The spec already sketches the later phase, a broker leasing turns to several NPC services at once with inference running in parallel and world transitions still serialized, but it’s a sketch, and this delivery doesn’t build it.

There’s also a reason sitting in the current code. The built-in MCP world lets the controller pick an actor with world_select_actor, and the server then mutates that one selected binding. If two client processes shared that connection, one could select Jory and the other could select Elsie a moment later, and Jory’s action would land on Elsie. So the NPC service never touches the world. It receives an observation scoped to Jory and returns a decision in the same Decision shape the internal villagers already produce: an action ID with its arguments, a justification, an expected outcome, and optionally a subgoal or typed plan steps. The coordinator takes it from there, with the same invalid-action recovery it applies to everyone else.

The spec rules out the other obvious design, a copy of the world for every NPC. Twelve copies of Millhaven would mean twelve opinions about how much flour is sitting at the mill, and nothing deterministic to settle them. The world owns truth. That line has been in the NPCSIM spec since the room with the key inside the box, and Generation 27 doesn’t loosen it.

Architecture diagram: the coordinator process keeps the authoritative world and eleven in-process villagers, while Jory's NPC service runs in a separate process with its own 3B to 4B model endpoint
Figure 1. Jory’s thinking moves to a separate process. The world and the other eleven villagers stay where they were.

The lease

Every turn Jory takes as an external actor starts with a turn lease. It carries a unique lease ID, the run, world, actor and session it belongs to, the revision of his cognitive checkpoint, the revision of the observation he’s being shown, and a deadline. The service gets to produce exactly one decision, or a deterministic wait, against it. A decision that arrives after the deadline is rejected, and so is one that refers to an observation the world has since moved past or names the wrong actor. Present the same lease ID twice and the service has to hand back the same recorded result, or say plainly that the lease is completed or expired.

The sentence in the spec that does the most work is this one: “A transport timeout is not evidence that the worker or world did not complete its operation.” Anyone who has watched an integration post the same vendor invoice twice, because the first call timed out after the database had already committed, knows why it’s there. Recovery asks for the lease and action status before it retries anything. And the request-ID idempotency on world actions stays exactly where it was, so even a confused retry can’t buy the same loaf twice.

The envelope for Jory carries Jory’s things. That means his profile and the documents he’s permitted to see, his own observation and available actions, his goal with the memory and plan behind it, and the shared clock fields he could already read. It never carries the full world state, Elsie’s memory, Mara’s private documents or anyone’s model credentials. The service token authorizes one actor in one run. A service that answers as somebody else gets treated as a protocol and authentication failure, not a curiosity.

The life of one turn lease in five steps, from lease issued to checkpoint saved, with the failure branch under each step
Figure 2. One turn lease, from issue to checkpoint. The red boxes are where the spec says no.

Failing without guessing

The failure table has nine rows. None of them lets the world move on a guess. If the service is gone before resume, the episode stays paused and shows the health error. Lose it in the middle of a model call and the uncertain result sits unapplied until the lease status comes back. A late result after expiry is ignored outright, and a checkpoint that doesn’t match its actor, run, revision or schema blocks migration while the previous binding stays recoverable.

The rule with the least give in it is the one about fallback. If Jory’s model endpoint goes down, the first slice does not quietly route him back to the global model. The village pauses at the last confirmed world action. Moving him back in-process takes an operator’s confirmation and a current checkpoint. A baker whose decisions started coming from a different model halfway through a run, with no record of the switch, would make every later log entry about him suspect. The spec requires admin diagnostics to say which execution mode and model produced each decision, without leaking private state or credentials, and a silent fallback would break that on the first outage.

None of this assumes a big model. The spec says a 3B to 4B model has to be able to run Jory with no larger model standing behind it, and it refuses to hard-code anyone’s VRAM. Deployment guidance is supposed to measure weight memory, KV cache, context size and tokens per second instead of promising a number of agents. What makes a small model plausible is the typed plan contract NPCSIM already has: an NPC plans, and the coordinator carries out routine follow-through in code, so the model gets called at decision points rather than for every step to the mill. When a small model does fail, with invalid JSON or an action ID nobody advertised, the run pauses or surfaces a worker error. It will not invent a valid action to cover for the model. Broad catches that turn an error into a fabricated decision are prohibited by name.

Table of nine failure conditions from the Generation 27 spec and the required behavior for each
Figure 3. The safe failure table from the spec, nine rows long.

Two things the draft hasn’t settled

Who owns Jory’s memory is the first. The goals give it to the service, and the checkpoint endpoints export and load it there. But the turn envelope also carries his memory from the coordinator on every lease, and those can’t both be the source of truth. Putting it in the coordinator for the first slice would make the trip back in-process much simpler, since the agents map already holds it.

The second is whether the village waits. Turns are still serialized in the first slice, so while Jory’s 4B model thinks, do the other eleven villagers stand around? If they do, a slow call can hold up all of Millhaven for as long as it runs, up to the 30-second model timeout in the example config. If they don’t, the first slice has already wandered into the concurrency the spec saves for later, where several NPCs wake on events and the world needs a revision contract to reject competing actions.

Acceptance criterion five sends Jory back the other way. The episode pauses at a safe boundary, the coordinator verifies his checkpoint against actor, run, revision and schema, and only then does he take a turn in-process again. If the check fails, the old binding stays in place and Jory keeps thinking on port 9101.

Follow me here if you want the next NPCSIM run in your feed.


Previously in NPCSIM

The Key Is Inside the Box: How NPCSIM Works One locked room, then a village of twelve on a shared clock.

Who Owes Whom: A Spec for Sending My NPCs Less Shrinking what NPCSIM sends to the model, and what the first test runs showed.

Millhaven: The Thirteenth Loaf Twelve loaves at the tavern 45 minutes early, then an hour spent buying a thirteenth.

The World Gives the Same Answer. The Badger Doesn’t. Where the deterministic world ends and the agent begins.

I Took the NPC’s Seat for 28 Turns Playing Wren in The Forgotten Workshop against a 12-turn agent run.

Elsewhere

NPCSIM: the repo on GitHub, the code behind everything above.

Dog and Pony Autopsy: dogandponyautopsy.wordpress.com, post-mortems on vendor demos that didn’t land.

AD&D365: adnd365.com, Dynamics 365 training run on Dungeons & Dragons mechanics.

Gamifying the Enterprise: the book on Amazon, game mechanics for continuous proficiency.

Canticle: the repo on GitHub, a programming language whose source files have to be valid poems.

Everything else I have written: my Amazon author page.

LinkedIn: connect with me there.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.