Skip to content

Commit a566ac2

Browse files
yangxianshengPeter Steinberger
andauthored
fix(active-memory): detect Chinese recall intent in escalate mode (#117338) (#117419)
* fix(active-memory): detect Chinese recall intent in escalate mode (#117338) * fix(active-memory): recognize formatted multilingual recall intent --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent 4cbbccd commit a566ac2

3 files changed

Lines changed: 236 additions & 7 deletions

File tree

‎extensions/active-memory/escalation.test.ts‎

Lines changed: 175 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,158 @@ describe("active-memory escalation", () => {
1212
"Can you remind me what seat I prefer?",
1313
"You said earlier that the rollout was paused",
1414
"What happened two weeks ago?",
15+
"Do you remember what we decided to deploy tomorrow?",
16+
"¿Qué decidimos para mañana?",
17+
"你还记得我们上次讨论的数据库配置吗?",
18+
"你还记得我们上周决定明天部署的方案吗?",
19+
"你還記得我們上次討論過的資料嗎?",
20+
"你還記得我們上週決定明天部署的方案嗎?",
21+
"你还记得我们上次讨论下周发布的配置吗?",
22+
"你還記得我們上個月討論下禮拜部署的方案嗎?",
23+
"你记得数据库配置吗?",
24+
"帮我找一下之前的聊天记录",
25+
"幫我找一下之前的聊天記錄",
26+
"我们之前讨论的那个方案",
27+
"我們之前討論的那個方案",
28+
"上次,讨论的那个方案",
29+
"之前 讨论过的那个方案",
30+
"我们之前决定过的部署方案是什么?",
31+
"我們之前決定過的部署方案是什麼?",
32+
"前回の会話で決めた設定を覚えてる?",
33+
"前回の会話で決めた設定を覚えていますか?",
34+
"この設定を覚えてますか?",
35+
"以前話した設定を覚えている?",
36+
"以前話していた設定は何ですか?",
37+
"前回決めた来週の設定を覚えてますか?",
38+
"先週相談した明日の予定を覚えてる?",
39+
"지난번에 우리가 논의했던 설정 기억나?",
40+
"지난 번에 우리가 이야기했던 설정은 뭐였어?",
41+
"저번에 우리가 결정했던 설정은?",
42+
"예전에 말했던 설정 기억나요?",
43+
"지난번에 우리가 결정했던 내일 배포 설정 기억나요?",
44+
"지난 주에 논의했던 다음 배포 일정 기억나죠?",
45+
"그 설정 기억나지?",
46+
"그 설정 기억나지요?",
47+
"그 설정 기억나죠?",
48+
"그 설정 기억나ㅋㅋ",
1549
])("recognizes recall intent in %j", (message) => {
1650
expect(hasRecallIntent(message)).toBe(true);
1751
});
1852

53+
it.each([
54+
"How do I configure SQLite?",
55+
"Run the tests before merging",
56+
"Before we deploy, run the tests",
57+
"Remember to send the report",
58+
"Remind me tomorrow",
59+
"How does prior authorization work?",
60+
"部署之前先运行测试",
61+
"部署之前先决定方案",
62+
"部署之前先讨论方案",
63+
"部署之前先记录方案",
64+
"部署之前需要记录的事项",
65+
"上线之前整理资料",
66+
"部署之前先整理聊天记录",
67+
"上线之前清理对话记录",
68+
"部署之前准备好聊天记录",
69+
"上线之前准备新的资料",
70+
"部署之前整理的资料",
71+
"部署之前整理的聊天记录",
72+
"记得明天发送报告",
73+
"你记得明天发送报告吗?",
74+
"你记得明早发送报告吗?",
75+
"你记得今晚发送报告吗?",
76+
"你记得今后发送报告吗?",
77+
"你記得今後發送報告嗎?",
78+
"你记得待会发送报告吗?",
79+
"你记得等会发送报告吗?",
80+
"你記得等會發送報告嗎?",
81+
"你记得等下发送报告吗?",
82+
"你记得下礼拜发送报告吗?",
83+
"你記得下禮拜發送報告嗎?",
84+
"你记得上周的报告明天发送吗?",
85+
"你還記得上週的報告明天發送嗎?",
86+
"記得明天發送報告",
87+
"你還記得明天發送報告嗎?",
88+
"记住这个配置",
89+
"記住這個",
90+
"医生说过敏反应很严重",
91+
"你说过敏反应怎么办",
92+
"我说过敏药在哪里",
93+
"我们说过敏症状",
94+
"讨论过期证书怎么更新",
95+
"我们讨论过期证书怎么更新",
96+
"你提过期资料了吗",
97+
"你讨论过期配置如何处理",
98+
"我谈过期合同",
99+
"我們討論過期證書怎麼更新",
100+
"你說過敏反應怎麼辦",
101+
"上次天气不错",
102+
"明日の予定を教えて",
103+
"この設定を覚えておいて",
104+
"前回は晴れだった",
105+
"以前より話しやすくなった",
106+
"以前より話したい",
107+
"以前のように話したくない",
108+
"前回より相談したい",
109+
"前回のように相談したくない",
110+
"以前より決めたい",
111+
"以前と同じように決めたくない",
112+
"以前より伝えたい",
113+
"前回のように伝えたくありません",
114+
"前回より話したい",
115+
"以前のように話したがる",
116+
"前回のように相談したがる",
117+
"以前と同じように決めたがる",
118+
"前回のように伝えたがる",
119+
"以前のように話したがらない",
120+
"前回のように相談したがりません",
121+
"前回会話したい",
122+
"以前会話したい",
123+
"前回のように会話したい",
124+
"以前のように会話したい",
125+
"以前のように会話が弾む",
126+
"以前とは違う会話をしたい",
127+
"以前話していただけますか",
128+
"前回のように話していただけますか",
129+
"以前話していただきたい",
130+
"前回話していただきたい",
131+
"この設定を覚えているように設定して",
132+
"この設定を覚えてるようにしてください",
133+
"覚えてますように",
134+
"この設定を覚えている状態にして",
135+
"この設定を覚えてる状態にしてください",
136+
"覚えていることにして",
137+
"覚えてるままにして",
138+
"明日その予定を思い出させて",
139+
"今晩覚えてますか?",
140+
"今夜覚えてる?",
141+
"あした覚えてますか?",
142+
"あす覚えてますか?",
143+
"後日覚えてますか?",
144+
"前回の設定を明日覚えてますか?",
145+
"あとで思い出して",
146+
"내일 보고서를 보내줘",
147+
"이 설정을 기억해줘",
148+
"내일 기억나요?",
149+
"오늘 밤 기억나죠?",
150+
"오늘 저녁 기억나지?",
151+
"오늘 오후 기억나지?",
152+
"차주 기억나요?",
153+
"글피 기억나죠?",
154+
"지난번 설정을 내일 기억나요?",
155+
"지난 주 일정을 내일 기억나죠?",
156+
"다음 회의 기억나죠?",
157+
"나중에 기억나지?",
158+
"지난번 날씨가 좋았어",
159+
"내일 기억나게 알려줘",
160+
"나중에 기억나도록 알림 설정해줘",
161+
"잊지 않게 내일 기억나게 해줘",
162+
])("does not mistake ordinary or future-facing %j for recall intent", (message) => {
163+
expect(hasRecallIntent(message)).toBe(false);
164+
});
165+
19166
it("requires recall intent and a weak deterministic lane in escalate mode", () => {
20-
expect(hasRecallIntent("How do I configure SQLite?")).toBe(false);
21-
expect(hasRecallIntent("Run the tests before merging")).toBe(false);
22-
expect(hasRecallIntent("Before we deploy, run the tests")).toBe(false);
23-
expect(hasRecallIntent("Remember to send the report")).toBe(false);
24-
expect(hasRecallIntent("Remind me tomorrow")).toBe(false);
25-
expect(hasRecallIntent("How does prior authorization work?")).toBe(false);
26167
expect(
27168
shouldEscalateRecall({
28169
mode: "escalate",
@@ -44,6 +185,20 @@ describe("active-memory escalation", () => {
44185
hasStrongLaneOneHit: false,
45186
}),
46187
).toBe(false);
188+
expect(
189+
shouldEscalateRecall({
190+
mode: "escalate",
191+
message: "你还记得我们上次讨论的数据库配置吗?",
192+
hasStrongLaneOneHit: false,
193+
}),
194+
).toBe(true);
195+
expect(
196+
shouldEscalateRecall({
197+
mode: "escalate",
198+
message: "你还记得我们上次讨论的数据库配置吗?",
199+
hasStrongLaneOneHit: true,
200+
}),
201+
).toBe(false);
47202
});
48203

49204
it("preserves always mode and disables escalation in off mode", () => {
@@ -61,5 +216,19 @@ describe("active-memory escalation", () => {
61216
hasStrongLaneOneHit: false,
62217
}),
63218
).toBe(false);
219+
expect(
220+
shouldEscalateRecall({
221+
mode: "always",
222+
message: "记住这个配置",
223+
hasStrongLaneOneHit: true,
224+
}),
225+
).toBe(true);
226+
expect(
227+
shouldEscalateRecall({
228+
mode: "off",
229+
message: "你还记得我们上次讨论的数据库配置吗?",
230+
hasStrongLaneOneHit: false,
231+
}),
232+
).toBe(false);
64233
});
65234
});

‎extensions/active-memory/escalation.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,43 @@ const RECALL_INTENT_PATTERNS = [
1717
/\bremind\s+(?:me|us)\s+(?:what|which|who|where|why|how)\b/iu,
1818
];
1919

20+
// Future reminders stay quiet unless a completed past discussion or decision
21+
// shows that its future topic is itself the subject of retrospective recall.
22+
const LOCALIZED_RECALL_INTENT_PATTERNS = [
23+
{
24+
intent:
25+
/[还還][记記]得|[记記]得(?=.{0,24}(?:[吗嗎]|[??]))|(?:[之以]前|上(?:次|回)|曾[经經])[\s,,、::]{0,3}(?:(?:我们|我們|我|你|您)?(?:(?:聊|[说說]|[谈談]|[讨討][论論]|提)(?:[过過](?=[了的这這那什吗嗎么麼??。,、\s]|$)|[了的])|[决決]定(?:[过過](?=[了的这這那什吗嗎么麼??。,、\s]|$)|了)|[记記][录錄](?:[过過](?=[了的这這那什吗嗎么麼??。,、\s]|$)|了))|(?:的)?(?:聊天|[对對][话話])[记記][录錄]|的[资資]料)/u,
26+
future:
27+
/明(?:天|日|晚|年|早)|今(?:晚|夜|后|後)|[后後](?:天|日)|下(?:周|週|星期|(?:个|個)?月|次|回|礼拜|禮拜)|以(?:后|後)|之(?:后|後)|将来|將來|未来|未來|稍(?:后|後|晚)|待(?:会|會)|等(?:会|會|下)/u,
28+
retrospective:
29+
/(?:上(?:次|回|周|週|星期|(?:个|個)?月)|曾[经經]|昨(?:天|日))[\s,,、::]{0,3}(?:我们|我們|我|你|您)?[\s,,、::]{0,3}(?:聊|[说說]|[谈談]|[讨討][论論]|提|[决決]定|[记記][录錄])/u,
30+
},
31+
{
32+
intent:
33+
/覚えて(?:る|ます|い(?:る|ます))(?!ように|状態に|ことに|ままに)|(?:前回|この前|この間|以前)(?!\s*より).{0,24}(?:話(?:した|していた(?!だ)|してた)|言った|伝えた|相談した|決めた)(?![いくが])/u,
34+
future:
35+
/明(?:日|晩)|今(?:晩|夜)|明後日|来(?:週|月|年)|次(?:回|の)|あとで|後で|後ほど|後日|あした|あす|今後|これから|将来/u,
36+
retrospective:
37+
/(?:前回|この前|この間|以前|先週|先月|昨日)(?!\s*より).{0,24}(?:話(?:した|していた(?!だ)|してた)|言った|伝えた|相談した|決めた)(?![いくが])/u,
38+
},
39+
{
40+
intent:
41+
/기억나(?:요|지(?:요)?|죠|ㅋ+)?(?![\p{L}\p{N}_])|(?:지난\s*번|저번|예전).{0,24}(?:논의했|(?:이야기|얘기|대화)했|말했|언급했|결정했)/u,
42+
future: /내(?:일|년)|오늘\s*(?:밤|저녁|오후)|모레|글피|차주|다음|나중|앞으로|미래|이따|곧/u,
43+
retrospective:
44+
/(?:지난\s*(?:번|주|달)|저번|예전|어제).{0,24}(?:논의했|(?:이야기|얘기|대화)했|말했|언급했|결정했)/u,
45+
},
46+
];
47+
2048
export function hasRecallIntent(message: string): boolean {
2149
const normalized = message.replace(/\s+/g, " ").trim();
2250
return (
23-
normalized.length > 0 && RECALL_INTENT_PATTERNS.some((pattern) => pattern.test(normalized))
51+
normalized.length > 0 &&
52+
(RECALL_INTENT_PATTERNS.some((pattern) => pattern.test(normalized)) ||
53+
LOCALIZED_RECALL_INTENT_PATTERNS.some(
54+
({ intent, future, retrospective }) =>
55+
intent.test(normalized) && (!future.test(normalized) || retrospective.test(normalized)),
56+
))
2457
);
2558
}
2659

‎extensions/active-memory/index.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,33 @@ describe("active-memory plugin", () => {
16761676
expect(runEmbeddedAgent).not.toHaveBeenCalled();
16771677
});
16781678

1679+
it.each(["你还记得我们上次讨论的数据库配置吗?", "你还记得我们上周决定明天部署的方案吗?"])(
1680+
"escalates only retrospective Chinese %j when recall mode is unset",
1681+
async (prompt) => {
1682+
registerPluginConfig({ mode: undefined });
1683+
expect(currentActiveMemoryConfig().mode).toBeUndefined();
1684+
1685+
const context = {
1686+
sessionKey: "agent:main:telegram:direct:owner",
1687+
messageProvider: "telegram",
1688+
channelId: "owner",
1689+
};
1690+
1691+
const ordinary = await runPromptBuild({ prompt: "部署之前先整理聊天记录" }, context);
1692+
expect(ordinary).toBeUndefined();
1693+
expect(runEmbeddedAgent).not.toHaveBeenCalled();
1694+
1695+
const future = await runPromptBuild({ prompt: "你记得明天发送报告吗?" }, context);
1696+
expect(future).toBeUndefined();
1697+
expect(runEmbeddedAgent).not.toHaveBeenCalled();
1698+
1699+
const recall = await runPromptBuild({ prompt }, context);
1700+
expect(runEmbeddedAgent).toHaveBeenCalledOnce();
1701+
expectPrependContextContains(recall, "lemon pepper wings");
1702+
expectEmbeddedChannel("telegram");
1703+
},
1704+
);
1705+
16791706
it("fails closed when the live active-memory plugin entry is removed", async () => {
16801707
configFile = {
16811708
plugins: {

0 commit comments

Comments
 (0)