Table of Contents
Fetching ...

Codified Finite-state Machines for Role-playing

Letian Peng, Yupeng Hou, Kun Zhou, Jingbo Shang

TL;DR

Codified Finite-State Machines (CFSMs) are introduced, a framework that automatically codifies textual character profiles into FSMs using LLM-based coding, and extended into Codified Probabilistic Finite-State Machines (CPFSMs), where transitions are modeled as probability distributions over states.

Abstract

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.

Codified Finite-state Machines for Role-playing

TL;DR

Codified Finite-State Machines (CFSMs) are introduced, a framework that automatically codifies textual character profiles into FSMs using LLM-based coding, and extended into Codified Probabilistic Finite-State Machines (CPFSMs), where transitions are modeled as probability distributions over states.

Abstract

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.
Paper Structure (53 sections, 14 figures, 14 tables)

This paper contains 53 sections, 14 figures, 14 tables.

Figures (14)

  • Figure 1: The Mario case to introduce finite-state machines into the role-playing field.
  • Figure 2: The frameworks of CFSM and CPFSM. More implementation-focused flow: Figure \ref{['fig:flow']}.
  • Figure 3: Synthetic validation of LLMs' limitation in state transition understanding.
  • Figure 4: Left: CFSM & CPFSM Performance on RP models with different scales. Right: Best@K performance of different randomness modeling strategies.
  • Figure 5: The state dynamics of key states of characters modeled by CFSM.
  • ...and 9 more figures