Test-Time-Matching: Decouple Personality, Memory, and Linguistic Style in LLM-based Role-Playing Language Agent

Xiaoyu Zhan, Xinyu Fu, Hao Sun, Yuanqi Li, Jie Guo, Yanwen GuoarXiv 2025 · DOI

Introduction

Role-Playing Language Agents (RPLAs) are designed to emulate specific characters, ranging from literary icons like Elizabeth Bennet to fantasy figures like Albus Dumbledore. However, current approaches often fall into two traps: shallow immersion via prompting, where the model sounds like a generic assistant in a "costume," or the high computational and data costs associated with fine-tuning. Furthermore, existing methods often treat a character's persona as a monolithic entity, making it difficult to update a character's knowledge without inadvertently altering their unique linguistic style.

To address these challenges, we present Test-Time-Matching (TTM), a training-free framework that achieves high-fidelity role-playing by functionally decoupling a character’s personality, memory, and linguistic style.

Methodology: The TTM Framework

The TTM framework operates through a modular pipeline that shifts the complexity from training to inference. It consists of two primary phases: Extraction & Analysis and a Three-Stage Generation Pipeline.

Extraction and Analysis

The system first parses raw source texts (e.g., novels) to extract three distinct features:

  1. Personality: The core behavioral traits and cognitive tendencies of the character.
  2. Memory: A graph-based vector database containing factual background and specific experiences.
  3. Linguistic Style: The character's unique verbal patterns, vocabulary, and sentence structures.
The TTM framework architecture, illustrating the Extraction, Analysis, and Conversation stages.

Three-Stage Generation Pipeline

During a conversation, TTM generates responses through a sequential process:

  • Stage 1: Styleless Response: The LLM produces a neutral core response based on the character's personality and the immediate dialogue context.
  • Stage 2: Memory-Checked Response: The initial response is used to query the character's memory database via Retrieval-Augmented Generation (RAG), ensuring factual accuracy and incorporating specific character-relevant details.
  • Stage 3: Stylized Response (Progressive Matching): This stage employs "Progressive Matching" to rewrite the response sentence-by-sentence. By retrieving semantically similar historical utterances as templates, the model ensures the final output matches the character's specific cadence and vocabulary without losing logical coherence.

Experimental Evaluation

TTM was evaluated using characters from both English and Chinese classic literature, including Harry Potter, Pride and Prejudice, and Dream of the Red Chamber. The framework was benchmarked against leading models such as GPT-4o, Gemini-2.5-pro, and specialized agents like ChatHaruhi.

Performance comparison of TTM against state-of-the-art models in terms of Knowledge Accuracy and Persona Consistency.

The results demonstrate that TTM significantly outperforms both fine-tuned models and proprietary LLMs. In evaluations by human experts and "LLM-as-Judge" (GPT-4o), TTM achieved a Persona Consistency (C.P.) score of 9.21 and a Knowledge Accuracy (A.K.) score of 9.56, surpassing Gemini-2.5-pro and the base Qwen-3-32B model.

Discussion and Key Insights

The success of TTM highlights several critical insights for the development of RPLAs:

  • Decoupling is Key: Separating "what to say" (content) from "how to say it" (style) allows for more precise control and higher fidelity.
  • Test-Time Scaling: TTM demonstrates that high-quality role-playing can be achieved by increasing computational effort at the moment of generation rather than through expensive pre-training or fine-tuning.
  • Linguistic Templates: Using historical utterances as few-shot prompts during the final stage acts as a powerful guide for maintaining a character's unique "voice."

While TTM offers superior performance, it does come with increased computational costs due to multiple LLM calls per turn. Future work will focus on reducing latency and addressing "memory timelines" to prevent characters from referencing future events they should not yet know.

Summary updated

BibTeX
@misc{zhan2025test,
  author = {Xiaoyu Zhan and Xinyu Fu and Hao Sun and Yuanqi Li and Jie Guo and Yanwen Guo},
  title = {{Test-Time-Matching: Decouple Personality, Memory, and Linguistic Style in LLM-based Role-Playing Language Agent}},
  year = {2025},
  eprint = {2507.16799},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.16799},
}
Figure