Prompt就是模型的一半:逐行解析UserRepGen-4B的representation_prompt.txt
Prompt就是模型的一半:逐行解析UserRepGen-4B的representation_prompt.txt
UserRepGen-4B 是微软开源的用户表征生成模型,它能从一段多轮对话中提炼出"用户想做什么 + 用户通常怎么交流"的结构化描述,用来驱动独立的 LLM 用户模拟器。而决定它输出质量的,除了微调过的 Qwen3.5-4B 权重,还有仓库里那个只有 10 行的 representation_prompt.txt——本文带你逐行拆解这份 prompt 的设计意图与使用要点。
为什么 Prompt 值得逐行读?
先看 UserRepGen-4B 的定位:它不模拟用户说话,而是生成一份 JSON 格式的用户表征,包含两个字段:
| 字段 | 含义 | 是否允许出现话题细节 |
|---|---|---|
task |
用户想完成的任务 | ✅ 允许 |
user_behavior |
用户的一般性行为模式 | ❌ 禁止 |
关键事实是:这份 prompt 与训练流水线完全一致(见 README.md 中的说明)。UserRepGen-4B 采用在线监督微调(OSFT)+ 事后蒸馏(hindsight distillation)训练,训练时模型"看到"的就是这份 prompt 格式。因此推理时不能随意改写它——你改的每一个词,都在偏离模型被训练过的输入分布。
这也是"Prompt 就是模型的一半"的含义:权重教会模型"怎么输出",prompt 定义了"输出什么、不能输出什么"。
Prompt 全文速览
representation_prompt.txt 全文仅 10 行(1,469 字节),结构非常紧凑:
1 You are an expert at analyzing user behavior in conversations between a user and an AI assistant. Given the conversation below, your task is to produce a representation of the user.
2
3 Treat the conversation as evidence about the user, and use it to infer how they generally behave and how they would typically act in other conversations. Focus on stable, general tendencies such as: how they phrase and specify requests, how they decompose goals across turns, how they respond to and give feedback to the assistant, how and when they provide context, their communication style, the dialog acts they use, and their degree and depth of engagement. Keep this description general: do not include topic-specific details or content from the conversation, do not quote or closely paraphrase full user messages, and do not refer to specific moments in this conversation (e.g. "here", "in this conversation", "when they asked about X"). Short distinctive words or phrases may be quoted sparingly when they are useful examples of the user's communication style. Describe their patterns in your own general terms instead.
4
5 Separately, you will also describe the task the user is trying to accomplish. Here you may include topic-specific details about what the user is doing in the conversation.
6
7 Conversation:
8 {conversation_history}
9
10 Output a single valid JSON object of the form {{"task": "...", "user_behavior": "..."}}. Do not wrap the output in markdown or add any other text.
下面逐段拆解。
逐行解析
第 1 行:角色设定 + 任务声明
You are an expert at analyzing user behavior... your task is to produce a representation of the user.
这一行做了两件事:赋予专家角色(user behavior analyst),并给出总目标——生成 user representation。对微调模型来说,这句话的价值更多在于它是"训练时的固定前缀":模型在 3,200 条训练对话上反复见到过这个开头,开头一致才能稳定触发它学到的输出风格。新手注意:不要把它润色成更"自然"的中文或英文版本。
第 3 行:核心指令 —— 把对话当"证据"而不是"事实"
这是全文最长、信息密度最高的一句,包含三层设计:
① 认知立场:"Treat the conversation as evidence" 对话只是关于该用户的证据,不是关于其本人的确定性结论。这直接对应 README 中的风险提示——表征是"从单次对话推断出的描述,不是对某个人的核实事实"。
② 枚举 7 个行为维度,要求关注"稳定、一般的倾向":
- 如何措辞和限定请求(request formulation)
- 如何跨轮次分解目标(goal decomposition)
- 如何回应和反馈(response / feedback patterns)
- 何时、如何提供上下文(context provision)
- 沟通风格(communication style)
- 使用的对话行为(dialog acts)
- 投入程度与深度(engagement / termination behavior)
这份清单就是模型的"输出检查表",也解释了 README.md 中示例输出为何涵盖 terse 风格、渐进式约束披露、不早退不跑题等描述。
③ 三条负向约束(这是 prompt 里最容易被忽视的部分):
| 禁止事项 | 防止什么问题 |
|---|---|
| 不写话题相关内容 | 避免 user_behavior 泄漏任务细节,保住跨任务迁移能力 |
| 不整句引用或近似复述用户原话 | 避免"行为描述"退化成"对话摘要" |
| 不指向具体时刻("here"、"when they asked about X") | 保持描述在其他对话中仍成立 |
唯一的例外是"短而有辨识度的词或短语可以少量引用"——用来锚定沟通风格的证据(比如示例输出中引用 'text'、'empty cells' 这种简短表达)。
第 5 行:task 字段 —— 唯一允许"具体"的地方
Separately, you will also describe the task... Here you may include topic-specific details...
这一行与第 3 行形成刻意不对称:user_behavior 必须去语境化,task 必须保留语境。这正是跨任务实验(cross-task generalization)能成立的前提——把同一用户另一段对话学来的行为描述,与一个新任务描述组合,模拟器依然能还原该用户的交互方式。两个字段各司其职,prompt 里用 "Separately" 一词明确切分。
第 7–8 行:{conversation_history} 占位符与对话格式化
Conversation:
{conversation_history}
只有一个占位符。注意两点:
- 填充格式有约定:example.py 中每轮对话被拼接为
<a href="https://link.gitcode.com/i/baa33c9bd54768882aa64b72f9a9acdd" target="_blank">user]: .../[assistant]: ...并以换行分隔,role只能是user或assistant([example.py 有严格校验)。 - 这就是第 10 行用双大括号
{{"task"...}}的原因:整个文件会经过 Python 的str.format(conversation_history=...)填充(example.py),{{和}}是转义写法,最终呈现给模型的才是单个{。自己改造调用代码时如果忘了转义,会在这里直接抛KeyError。
第 10 行:输出契约 —— 单个合法 JSON,不加任何额外文本
Output a single valid JSON object of the form {"task": "...", "user_behavior": "..."}. Do not wrap the output in markdown or add any other text.
这行与代码侧的严格校验是配套设计:example.py 的 parse_representation 要求——必须是 dict、键集合恰好是 {"task", "user_behavior"}、两个值都是非空字符串,任何一条不满足就直接报错,而不是静默修复。对新手来说这意味着:拿到输出后要先做 JSON 解析和字段校验,再把它交给下游模拟器。
Prompt 之外:它如何被喂给模型
理解调用链能帮你避开大多数坑:
- 对话列表 → 按
<a href="https://link.gitcode.com/i/c07721407db775967c3476ee669ed32d" target="_blank">role]: content格式拼接 →template.format(conversation_history=history),见 [example.py - 整个 prompt 作为一条
user消息,经 chat template 渲染:chat_template.jinja 中enable_thinking=False会输出空的思考块<think>\n\n</think>\n\n,关闭基座模型的推理模式(README.md Quickstart 中同样设置了该参数) - 生成参数:
max_new_tokens=1024、贪心解码(do_sample=False),见 example.py - 解码后严格校验 JSON(见上文第 10 行解析)
⚠️ token 预算:训练上限是 8,192 prompt token + 1,024 completion token(共 9,216)。example.py 会对超长 prompt 直接抛 ValueError,官方不提供更长上下文的支持。
新手最容易踩的 3 个坑
- 随意改写 prompt:训练流水线使用的就是这份原文,"优化措辞"等于偏离训练分布,输出格式和行为描述质量都可能退化。要改提示策略,应走再训练而非微调提示。
- 超长对话直接塞入:超过 8,192 token 的 prompt 不在支持范围内,先在业务侧截断或摘要对话。
- 假设输出必然是合法 JSON:即便 prompt 要求严格,也要保留 example.py 那种"校验失败即报错"的逻辑,切勿静默兜底。
一句话总结
representation_prompt.txt 只有 10 行,却完整定义了 UserRepGen-4B 的输入契约(证据视角 + 7 个行为维度 + 负向约束)、输出契约(纯净双字段 JSON)与任务/行为的不对称分工——读懂这 10 行,才算真正读懂这个"用户表征生成"模型是怎么工作的。