arXiv:2505.07705cs.CL2025-05NeurIPS被引 6

用可执行代码定义角色逻辑,让对话更稳定可控。

Codifying Character Logic in Role-Playing

  • 将角色行为转为带条件判断的可执行函数
  • 在5141个场景中提升行为一致性与多样性
  • 适合需要稳定角色表现的本地部署应用

本文提出编码化角色档案(Codified Profiles),将角色逻辑表示为结构化、可执行的函数,用于行为决策。每个档案定义 parse_by_scene(scene) 函数,根据场景输出一组基于逻辑的断言,使用 if-then-else 等控制结构及 check_condition(scene, question) 条件检查,其中问题如“角色是否处于危险中?”由角色扮演大模型判断为真、假或未知。相比传统直接拼接描述到提示词的方式,该方法具三方面优势:(1) 持久性——强制完整一致执行角色逻辑,不依赖模型隐式推理;(2) 可更新性——可系统化检查与修改行为逻辑,便于追踪调试;(3) 可控随机性——在逻辑内支持随机行为,实现细粒度变化,仅靠提示难以达成。为验证效果,构建包含83个角色与5141个场景的新基准,基于自然语言推理(NLI)评分对比角色回应与真实行为。实验表明,编码化档案显著提升持久性、可维护性与行为多样性。尤其通过预处理卸载大量推理任务,使10亿参数模型也能实现高质量角色扮演,为本地部署角色代理提供高效可扩展基础。

原文摘要 · Abstract (English)

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.

角色扮演逻辑编码可解释性本地部署

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。