Modeling latent character states is crucial for consistent and engaging role-playing (RP) with large language models (LLMs). Yet, existing prompting-based approaches mainly capture surface actions, often failing to track the latent states that drive interaction. We revisit finite-state machines (FSMs), long used in game design to model state transitions. While effective in small, well-specified state spaces, traditional hand-crafted, rule-based FSMs struggle to adapt to the open-ended semantic space of RP. To address this, we introduce Codified Finite-State Machines (CFSMs), a framework that automatically codifies textual character profiles into FSMs using LLM-based coding. CFSMs extract key states and transitions directly from the profile, producing interpretable structures that enforce character consistency. To further capture uncertainty and variability, we extend CFSMs into Codified Probabilistic Finite-State Machines (CPFSMs), where transitions are modeled as probability distributions over states. Through both synthetic evaluations and real-world RP scenarios in established artifacts, we demonstrate that CFSM and CPFSM outperform generally applied baselines, verifying effectiveness not only in structured tasks but also in open-ended stochastic state exploration.
翻译:对潜在角色状态进行建模对于实现与大型语言模型(LLM)一致且引人入胜的角色扮演(RP)至关重要。然而,现有的基于提示的方法主要捕捉表面行为,往往难以追踪驱动交互的潜在状态。我们重新审视了有限状态机(FSM)——这一在游戏设计中长期用于建模状态转换的工具。传统手工构建的、基于规则的FSM在小型、明确指定的状态空间中虽然有效,却难以适应RP开放式的语义空间。为解决这一问题,我们提出了编码有限状态机(CFSM)框架,该框架利用基于LLM的编码技术,自动将文本角色描述编码为FSM。CFSM直接从角色描述中提取关键状态和转换,生成可解释的结构以强制保持角色一致性。为进一步捕捉不确定性和可变性,我们将CFSM扩展为编码概率有限状态机(CPFSM),其中状态转换被建模为状态上的概率分布。通过在合成评估和既有作品中的真实RP场景进行实验,我们证明CFSM和CPFSM优于普遍应用的基线方法,验证了其不仅在结构化任务中有效,在开放式随机状态探索中同样有效。