[GM Workbench] Improv NPC panel with prefetch (C1 + C2) #155
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Motivation / Context
At-the-table improv is a distinct use case from prep-time generation: a GM needs a full, usable NPC (name, pronouns, occupation, want, secret, voice cue) instantly, with zero latency, when players go somewhere unplanned. The report ranks improv NPCs with instant recall into the wiki among the most differentiated Workbench tools (§6) — the moat isn't the generation itself but the "they matter now → wiki" one-click promotion, which no standalone generator site offers.
This combines two catalog entries (§3, Group C): C1 (instant NPC, served from a prefetched pool) and C2 (voice/mannerism cues for an existing npc entry).
Approach
C1 — Instant NPC panel:
instant_npctool inGENERATOR_TOOLS(generation_service.py, #136) flaggedprefetchable=True.planning_tasks.pyRedis prefetch pattern verbatim (§5.1's "prefetch reuse" guidance): a Celery task takes a per-campaign+tool lock (mirroringname_prefetch_lock:{campaign_id},planning_tasks.py:53-60), generates a small pool of ready-to-use NPCs in the background, and caches them under a Redis key analogous toname_cache:{campaign_id}:{category}(planning_tasks.py:80) with a TTL. The generalized prefetch endpoint from #136 (which generalizescampaigns.py:3074-3090) triggers this.generate_structured_textin JSON mode, usingcampaign_context(+game_system) from #136's context builders.campaigns.py:3093-3144), refilling the pool in the background as it's drawn down.entry_type=npcLoreEntryimmediately (same pattern as canonical names,sessions.py:283-296). Until saved, drawn NPCs are ephemeral/scratch (not necessarily persisted toGenerationResult— the prefetch pool itself is the buffer, consistent with how names work today).C2 — Voice & mannerism prompts:
npc_voicetool for generating 3 performable cues (speech pattern, verbal tic, physical mannerism, catchphrase) for an existing npc lore entry, reading itsbody+pronouns.GenerationResult, #138) or as a Draft appending a GM-only section to the entry — reusestart_merge_draft/ append semantics (draft_service.py:93) andWikiDraftReview.jsx, the same rail #130 uses for itsexpand_backstory/generate_statblockdraft modes. Do not duplicate #130's backstory/statblock generation — this tool is scoped strictly to performance cues (voice/mannerism), not backstory or stats.Dependencies
planning_tasks.py, unchanged by this issue except for reuse.Out of scope
expand_backstorydraft mode.generate_statblockdraft mode.Acceptance criteria
instant_npctool is prefetchable; a background Celery task keeps a per-campaign pool populated using the same lock+TTL pattern as name prefetch.entry_type=npcLoreEntryfrom the drawn NPC.npc_voicetool, given an existing npc entry, returns 3 performable cues (speech pattern, verbal tic, physical mannerism, catchphrase).npc_voiceoutput can be saved toGenerationResult(scratch) or proposed as a GM-only-sectionLoreEntryDraftappend, reviewable inWikiDraftReview.jsx.Done — merged to
feat/v3.10-gm-workbenchvia PR #222.Generalized prefetch (deferred here from #136):
ToolDef.pool_field+workbench_pool_service(per-campaign+tool Redis list — atomic LPOP draw, RPUSH fill, capped, 2h TTL) +prefetch_workbench_poolCelery task (lock+TTL, mirrorsprefetch_name_options) +POST /workbench/{tool_id}/drawand/prefetchendpoints (GM-only; 404 for non-prefetchable tools).C1
instant_npc(prefetchable,pool_field="npcs"): draws a fully-formed NPC (name, pronouns, occupation, want, secret, voice cue) with zero visible LLM wait; cold-pool inline fallback buffers the rest.InstantNpcGeneratorwarms the pool on mount, conjures on click, saves as annpcLoreEntry.C2
npc_voice: performable cues for an existing npc entry (cues only — backstory/statblocks stay with #130).NpcVoiceGeneratorreusesWorkbenchResultActions, so cues land as a new entry, an appended review draft on the npc entry, or a copy.All acceptance criteria met. No new models/migrations.
Verified: backend 730 passed (incl. new
test_workbench_npc.py— warm/low/cold pool paths, prefetch trigger, 404/403 guards, npc_voice generate + 422 + parser tolerance), frontend 389 passed, ruff + eslint clean, build OK. Not yet exercised against a live LLM/Redis pool on dev — pending your dev testing.