Codified Finite-state Machines for Role-playing

Letian Peng, Yupeng Hou, Kun Zhou, Jingbo Shang
2/5/2026
cs.CL

No official code found. Best implementation: KomeijiForce/Codified_Finite_State_Machine (1 star, MIT, last commit 2026-03-04).

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.

View on arXivView PDF

Code Implementations(1)

MIT

Official Implementation of the ICLR 2026 paper "Codified Finite State Machines for Role-playing"

10PythonFeb 5, 20267 months agoMIT

Similar Papers

Cite this paper

@article{peng2026codified,
  title  = {Codified Finite-state Machines for Role-playing},
  author = {Letian Peng and Yupeng Hou and Kun Zhou and Jingbo Shang},
  year   = {2026},
  eprint = {2602.05905},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2602.05905v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2602.05905.svg)](https://codeofpaper.com/paper/2602.05905)

Discussion