Table of Contents
Fetching ...

Codifying Character Logic in Role-Playing

Letian Peng, Jingbo Shang

TL;DR

Codified Profiles address the brittleness and lack of persistence in prompt-based role-playing by compiling character logic into executable parse_by_scene functions with semantic condition checks. The approach yields groundable, deterministic behavior with optional stochastic branches, enabling persistence, updatability, and controlled randomness. A new Fandom Benchmark of 83 characters and 5,141 scenes, scored via an NLI framework, demonstrates that codified profiles improve consistency, adaptability, and behavioral diversity, even for 1B-parameter LLMs, and supports evolving profiles aligned with storyline progress. The work shows practical implications for scalable, local deployment of role-playing agents and opens dataset and method avenues for richer, more transparent character logic in interactive AI systems.

Abstract

This paper introduces Codified Profiles for role-playing, a novel approach that represents character logic as structured, executable functions for behavioral decision-making. Each profile defines a set of functions parse_by_scene(scene) that outputs a list of logic-grounded assertions triggered_statements, using both explicit control structures (e.g., if-then-else) and condition checks like check_condition(scene, question), where each question is a semantically meaningful prompt about the scene (e.g., "Is the character in danger?") discriminated by the role-playing LLM as true, false, or unknown. This explicit representation offers three key advantages over traditional prompt-based profiles, which append character descriptions directly into text prompts: (1) Persistence, by enforcing complete and consistent execution of character logic, rather than relying on the model's implicit reasoning; (2) Updatability, through systematic inspection and revision of behavioral logic, which is difficult to track or debug in prompt-only approaches; (3) Controllable Randomness, by supporting stochastic behavior directly within the logic, enabling fine-grained variability that prompting alone struggles to achieve. To validate these advantages, we introduce a new benchmark constructed from 83 characters and 5,141 scenes curated from Fandom, using NLI-based scoring to compare character responses against ground-truth actions. Our experiments demonstrate the significant benefits of codified profiles in improving persistence, updatability, and behavioral diversity. Notably, by offloading a significant portion of reasoning to preprocessing, codified profiles enable even 1B-parameter models to perform high-quality role-playing, providing a scalable and efficient foundation for local deployment of role-play agents.

Codifying Character Logic in Role-Playing

TL;DR

Codified Profiles address the brittleness and lack of persistence in prompt-based role-playing by compiling character logic into executable parse_by_scene functions with semantic condition checks. The approach yields groundable, deterministic behavior with optional stochastic branches, enabling persistence, updatability, and controlled randomness. A new Fandom Benchmark of 83 characters and 5,141 scenes, scored via an NLI framework, demonstrates that codified profiles improve consistency, adaptability, and behavioral diversity, even for 1B-parameter LLMs, and supports evolving profiles aligned with storyline progress. The work shows practical implications for scalable, local deployment of role-playing agents and opens dataset and method avenues for richer, more transparent character logic in interactive AI systems.

Abstract

This paper introduces Codified Profiles for role-playing, a novel approach that represents character logic as structured, executable functions for behavioral decision-making. Each profile defines a set of functions parse_by_scene(scene) that outputs a list of logic-grounded assertions triggered_statements, using both explicit control structures (e.g., if-then-else) and condition checks like check_condition(scene, question), where each question is a semantically meaningful prompt about the scene (e.g., "Is the character in danger?") discriminated by the role-playing LLM as true, false, or unknown. This explicit representation offers three key advantages over traditional prompt-based profiles, which append character descriptions directly into text prompts: (1) Persistence, by enforcing complete and consistent execution of character logic, rather than relying on the model's implicit reasoning; (2) Updatability, through systematic inspection and revision of behavioral logic, which is difficult to track or debug in prompt-only approaches; (3) Controllable Randomness, by supporting stochastic behavior directly within the logic, enabling fine-grained variability that prompting alone struggles to achieve. To validate these advantages, we introduce a new benchmark constructed from 83 characters and 5,141 scenes curated from Fandom, using NLI-based scoring to compare character responses against ground-truth actions. Our experiments demonstrate the significant benefits of codified profiles in improving persistence, updatability, and behavioral diversity. Notably, by offloading a significant portion of reasoning to preprocessing, codified profiles enable even 1B-parameter models to perform high-quality role-playing, providing a scalable and efficient foundation for local deployment of role-play agents.
Paper Structure (42 sections, 3 equations, 17 figures, 8 tables)

This paper contains 42 sections, 3 equations, 17 figures, 8 tables.

Figures (17)

  • Figure 1: A presentation of the workflow and advantages of Codified Profiles.
  • Figure 2: The evolving mechanism of codified profile to synchronize character with the storyline.
  • Figure 3: Curation and evaluation scenarios of our Fandom Benchmark.
  • Figure 4: The role-playing performance with reasoning mechanism.
  • Figure 5: The Human/LLM-based preference evaluation results.
  • ...and 12 more figures