Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(bot-wake): duty threshold defaults to 0.65, follow-ups to the bot's own line and thread wake (#21789)

Arvin Xubc4af095a01f
diff --git a/apps/server/src/services/agentSignal/scenarios/__tests__/botWakeConfig.test.ts b/apps/server/src/services/agentSignal/scenarios/__tests__/botWakeConfig.test.ts
index 739b61947cb..700cd1de115 100644
--- a/apps/server/src/services/agentSignal/scenarios/__tests__/botWakeConfig.test.ts
+++ b/apps/server/src/services/agentSignal/scenarios/__tests__/botWakeConfig.test.ts
@@ -44,7 +44,7 @@ describe('parseBotWakeSettings', () => {
expect(parseBotWakeSettings({ [K.enabled]: true }).rules.duties).toEqual({
mode: 'enforce',
text: undefined,
- threshold: 0.8,
+ threshold: 0.65,
});
expect(
parseBotWakeSettings({ [K.duties]: ' ', [K.enabled]: true }).rules.duties.text,
@@ -67,7 +67,7 @@ describe('parseBotWakeSettings', () => {
// A malformed value falls back to its default, keeping the rest.
expect(
parseBotWakeSettings({ [K.duties]: 42, [K.dutiesThreshold]: 3, [K.windowSeconds]: 60 }).rules,
- ).toMatchObject({ duties: { text: undefined, threshold: 0.8 }, windowSeconds: 60 });
+ ).toMatchObject({ duties: { text: undefined, threshold: 0.65 }, windowSeconds: 60 });
// A hand-written nested config spells them as an object.
expect(
parseBotWakeSettings({ botWake: { duties: { text: 'Triage bugs.', threshold: 0.9 } } }).rules
diff --git a/apps/server/src/services/agentSignal/scenarios/__tests__/botWakeDuty.test.ts b/apps/server/src/services/agentSignal/scenarios/__tests__/botWakeDuty.test.ts
index 82d9e85e2f2..50395605d1a 100644
--- a/apps/server/src/services/agentSignal/scenarios/__tests__/botWakeDuty.test.ts
+++ b/apps/server/src/services/agentSignal/scenarios/__tests__/botWakeDuty.test.ts
@@ -72,15 +72,15 @@ describe('duty policy', () => {
expect(judge).toHaveBeenCalledTimes(2);
});
- it('defaults to 0.8 and takes the threshold from the settings', async () => {
+ it('defaults to 0.65 and takes the threshold from the settings', async () => {
const at = (score: number) =>
createDutyPolicy(
parseBotWakeSettings({ [K.duties]: DUTIES, [K.enabled]: true }).rules,
judgeScoring(score),
).evaluate({ signal: signal(), state: {} });
- expect((await at(0.8)).verdict).toBe('allow');
- expect((await at(0.79)).verdict).toBe('deny');
+ expect((await at(0.65)).verdict).toBe('allow');
+ expect((await at(0.64)).verdict).toBe('deny');
});
it('never asks the model without duties', async () => {
diff --git a/apps/server/src/services/agentSignal/scenarios/__tests__/botWakePolicies.test.ts b/apps/server/src/services/agentSignal/scenarios/__tests__/botWakePolicies.test.ts
index a25e23eb087..454e3cb9973 100644
--- a/apps/server/src/services/agentSignal/scenarios/__tests__/botWakePolicies.test.ts
+++ b/apps/server/src/services/agentSignal/scenarios/__tests__/botWakePolicies.test.ts
@@ -370,6 +370,112 @@ describe('owner rules policy', () => {
});
});
+// From bot-wake review of missed wakes: the owner answering the bot right after its reply, and the
+// person it was helping pasting the link it asked for eight minutes later in the bot's thread.
+describe('owner rules policy: following up on the bot itself', () => {
+ const APP = 'app1';
+ const botLine = (at: number) => ({ at, authorId: APP, id: `m${at}`, isBot: true, text: '好的' });
+ const personLine = (authorId: string, at: number) => ({
+ at,
+ authorId,
+ id: `m${at}`,
+ isBot: false,
+ text: '嗯',
+ });
+
+ const run = ({
+ author = human,
+ botWake = {},
+ channel,
+ recent,
+ threadSubscribed = true,
+ }: {
+ author?: WakeAuthor;
+ botWake?: Record<string, unknown>;
+ channel: Partial<WakeChannelState>;
+ recent: ReturnType<typeof botLine>[];
+ threadSubscribed?: boolean;
+ }) => {
+ const result = createOwnerRulesPolicy('enforce', rulesFor(botWake)).evaluate({
+ signal: signal({ applicationId: APP, author }),
+ state: {
+ ...snapshot(channel),
+ conversation: { botNames: ['Nasa'], recent },
+ threadSubscribed,
+ },
+ });
+ return [result.verdict, result.reason];
+ };
+
+ const owner: WakeAuthor = { ...human, id: 'o1', isOwner: true };
+ const window = {
+ botLastSpokeAt: NOW - 28_000,
+ followupAuthorId: 'u2',
+ followupUntil: NOW + 272_000,
+ };
+
+ it('lets the owner answering the bot’s own line in the window follow up', () => {
+ expect(run({ author: owner, channel: window, recent: [botLine(NOW - 28_000)] })).toEqual([
+ 'allow',
+ 'owner-answers-bot',
+ ]);
+ });
+
+ it('leaves the owner answering someone else in the window to the duty judge', () => {
+ expect(
+ run({
+ author: owner,
+ channel: window,
+ recent: [botLine(NOW - 60_000), personLine('u2', NOW - 28_000)],
+ }),
+ ).toEqual(['abstain', 'no-owner-rule-opinion']);
+ // Not the owner: someone else replying to the bot is still more likely talking to the room.
+ expect(
+ run({ author: { ...human, id: 'u3' }, channel: window, recent: [botLine(NOW - 28_000)] }),
+ ).toEqual(['abstain', 'no-owner-rule-opinion']);
+ });
+
+ const lapsed = {
+ botLastSpokeAt: NOW - 484_000,
+ followupAuthorId: 'u1',
+ followupUntil: NOW - 184_000,
+ };
+
+ it('lets the person the bot answered come back to its thread after the window', () => {
+ expect(run({ channel: lapsed, recent: [botLine(NOW - 484_000)] })).toEqual([
+ 'allow',
+ 'thread-followup',
+ ]);
+ expect(
+ run({
+ botWake: { rules: { scope: 'bot-threads' } },
+ channel: lapsed,
+ recent: [botLine(NOW - 484_000), personLine('u1', NOW - 200_000)],
+ }),
+ ).toEqual(['allow', 'thread-followup']);
+ });
+
+ it('does not extend the window outside a subscribed thread, for others, or past 30 minutes', () => {
+ const recent = [botLine(NOW - 484_000)];
+ expect(run({ channel: lapsed, recent, threadSubscribed: false })).toEqual([
+ 'abstain',
+ 'no-owner-rule-opinion',
+ ]);
+ expect(run({ author: { ...human, id: 'u3' }, channel: lapsed, recent })).toEqual([
+ 'abstain',
+ 'no-owner-rule-opinion',
+ ]);
+ expect(run({ channel: { ...lapsed, botLastSpokeAt: NOW - 31 * 60_000 }, recent })).toEqual([
+ 'abstain',
+ 'no-owner-rule-opinion',
+ ]);
+ // Someone else spoke since: the author may be answering them.
+ expect(
+ run({ channel: lapsed, recent: [botLine(NOW - 484_000), personLine('u3', NOW - 60_000)] }),
+ ).toEqual(['abstain', 'no-owner-rule-opinion']);
+ });
+});
+
describe('owner rules policy: naming the bot', () => {
const rules = rulesFor({ rules: { ownerPresenceSeconds: 120 } });
const conversation = { botNames: ['Nasa'], recent: [] };
diff --git a/apps/server/src/services/agentSignal/scenarios/botWake/config.ts b/apps/server/src/services/agentSignal/scenarios/botWake/config.ts
index 08d919c34b0..caea9fb3a1b 100644
--- a/apps/server/src/services/agentSignal/scenarios/botWake/config.ts
+++ b/apps/server/src/services/agentSignal/scenarios/botWake/config.ts
@@ -10,7 +10,8 @@ export const DEFAULT_WAKE_RULES: WakeRules = {
classifier: { mode: 'enforce', threshold: 0.75 },
denyChannels: [],
// Off until the bot has duties: without the text there is nothing to judge a message against.
- duties: { mode: 'enforce', threshold: 0.8 },
+ // The decision model scores plain feature requests 0.65-0.76, so 0.8 let almost none through.
+ duties: { mode: 'enforce', threshold: 0.65 },
maxSilentWakes: 3,
ownerPresenceSeconds: 120,
scope: 'all',
diff --git a/apps/server/src/services/agentSignal/scenarios/botWake/policies/ownerRules.ts b/apps/server/src/services/agentSignal/scenarios/botWake/policies/ownerRules.ts
index 272e023f72c..892576523b7 100644
--- a/apps/server/src/services/agentSignal/scenarios/botWake/policies/ownerRules.ts
+++ b/apps/server/src/services/agentSignal/scenarios/botWake/policies/ownerRules.ts
@@ -3,6 +3,13 @@ import type { WakePolicy, WakePolicyMode, WakePolicyResult, WakeRules } from '..
export const OWNER_RULES_POLICY_ID = 'bot-wake:owner-rules';
+/**
+ * How long the person the bot answered may come back to it in a thread the bot is subscribed to,
+ * after the window closed: pasting the link it asked for eight minutes later is still the same
+ * exchange. The classifier still has to confirm, as in the window.
+ */
+export const THREAD_FOLLOWUP_MS = 30 * 60 * 1000;
+
const deny = (reason: string): WakePolicyResult => ({
confidence: 1,
reason,
@@ -34,7 +41,10 @@ const deny = (reason: string): WakePolicyResult => ({
* list, stand-down (`stood-down`), window, budget, owner presence; owner presence is skipped when
* the text names the bot)
* - `allow` when the bot spoke within the follow-up window, the author is the person whose message
- * woke it there, and nothing denied
+ * woke it there, and nothing denied (`inside-followup-window`); also for the owner answering the
+ * bot's own line in the window (`owner-answers-bot`), and for that person coming back within
+ * {@link THREAD_FOLLOWUP_MS} in a thread the bot is subscribed to, with nobody else in between
+ * (`thread-followup`)
* - `abstain` otherwise: outside the window, or for someone else in it, the owner's rules have no
* opinion
*/
@@ -61,7 +71,25 @@ export const createOwnerRulesPolicy = (mode: WakePolicyMode, rules: WakeRules):
: channel?.botLastSpokeAt !== undefined &&
now - channel.botLastSpokeAt < rules.windowSeconds * 1000;
- if (rules.scope === 'bot-threads' && !windowOpen) return deny('outside-followup-window');
+ const partner = channel?.followupAuthorId;
+ const authorId = signal.author?.id;
+ const isPartner = !partner || !authorId || authorId === partner;
+ // The line right before this one: the bot's own, or someone else joining in.
+ const previous = state.conversation?.recent.at(-1);
+ const answersBot =
+ previous !== undefined && previous.isBot && previous.authorId === signal.applicationId;
+ const threadFollowup =
+ !windowOpen &&
+ state.threadSubscribed === true &&
+ partner !== undefined &&
+ authorId === partner &&
+ channel?.botLastSpokeAt !== undefined &&
+ now - channel.botLastSpokeAt < THREAD_FOLLOWUP_MS &&
+ (previous === undefined || answersBot || previous.authorId === authorId);
+
+ if (rules.scope === 'bot-threads' && !windowOpen && !threadFollowup) {
+ return deny('outside-followup-window');
+ }
// 0 means no budget: the bot never goes quiet on its own count.
if (rules.maxSilentWakes > 0 && (channel?.silentWakes ?? 0) >= rules.maxSilentWakes) {
@@ -78,20 +106,20 @@ export const createOwnerRulesPolicy = (mode: WakePolicyMode, rules: WakeRules):
return deny('owner-present');
}
- // The window follows up on the person the bot answered. Anyone else speaking in it, the owner
- // included, is more likely answering that person than the bot; the duty judge may still wake
- // it, for a message within the bot's duties.
- const partner = channel?.followupAuthorId;
- const followsUp = !partner || !signal.author || signal.author.id === partner;
+ const followup = (reason: string): WakePolicyResult => ({
+ confidence: 0.6,
+ reason,
+ tags: ['owner-rule', 'followup-window'],
+ verdict: 'allow',
+ });
- if (windowOpen && followsUp) {
- return {
- confidence: 0.6,
- reason: 'inside-followup-window',
- tags: ['owner-rule', 'followup-window'],
- verdict: 'allow',
- };
- }
+ // The window follows up on the person the bot answered. Anyone else speaking in it is more
+ // likely answering that person than the bot; the duty judge may still wake it, for a message
+ // within the bot's duties. The owner speaking right after the bot's own line is the exception:
+ // the bot works for them, and the classifier still has to confirm it is for the bot.
+ if (windowOpen && isPartner) return followup('inside-followup-window');
+ if (windowOpen && signal.author?.isOwner && answersBot) return followup('owner-answers-bot');
+ if (threadFollowup) return followup('thread-followup');
return {
confidence: 0,
@@ -102,6 +130,6 @@ export const createOwnerRulesPolicy = (mode: WakePolicyMode, rules: WakeRules):
},
id: OWNER_RULES_POLICY_ID,
mode,
- requires: ['channel', 'conversation'],
- version: 4,
+ requires: ['channel', 'conversation', 'threadSubscribed'],
+ version: 5,
});
diff --git a/apps/server/src/services/bot/__tests__/agentBotProviderSettings.test.ts b/apps/server/src/services/bot/__tests__/agentBotProviderSettings.test.ts
index 634d3f7e2ea..4431c841998 100644
--- a/apps/server/src/services/bot/__tests__/agentBotProviderSettings.test.ts
+++ b/apps/server/src/services/bot/__tests__/agentBotProviderSettings.test.ts
@@ -253,7 +253,7 @@ describe('mergeBotSettingsPatch', () => {
expect(merged?.allowFrom).toEqual([]);
expect(merged?.userId).toBe('owner-1');
// A field neither stored nor sent still gets its schema default.
- expect(merged?.botWakeDutiesThreshold).toBe(0.8);
+ expect(merged?.botWakeDutiesThreshold).toBe(0.65);
});
it('writes a flat key the runtime reads, even for a bot configured with a nested botWake', () => {
diff --git a/apps/server/src/services/bot/platforms/__tests__/botWakeFields.test.ts b/apps/server/src/services/bot/platforms/__tests__/botWakeFields.test.ts
index 2e7a7b33965..ebf27688348 100644
--- a/apps/server/src/services/bot/platforms/__tests__/botWakeFields.test.ts
+++ b/apps/server/src/services/bot/platforms/__tests__/botWakeFields.test.ts
@@ -59,7 +59,7 @@ describe('bot-wake settings fields', () => {
]);
});
- it('give the duties a text area that is off while empty, with a dial from 0.8', () => {
+ it('give the duties a text area that is off while empty, with a dial from 0.65', () => {
const duties = botWakeFields.find((f) => f.key === BOT_WAKE_SETTING_KEYS.duties)!;
const threshold = botWakeFields.find((f) => f.key === BOT_WAKE_SETTING_KEYS.dutiesThreshold)!;
@@ -67,7 +67,7 @@ describe('bot-wake settings fields', () => {
expect(duties.rows).toBeGreaterThanOrEqual(8);
// No default: an untouched form saves no duties, so the bot never steps in on its own.
expect(duties.default).toBeUndefined();
- expect(threshold).toMatchObject({ default: 0.8, maximum: 1, minimum: 0, type: 'number' });
+ expect(threshold).toMatchObject({ default: 0.65, maximum: 1, minimum: 0, type: 'number' });
});
it('are shown by the Discord form', () => {
diff --git a/packages/builtin-tool-message/src/manifest.ts b/packages/builtin-tool-message/src/manifest.ts
index ac8a4ca8cff..fb3143ea6b0 100644
--- a/packages/builtin-tool-message/src/manifest.ts
+++ b/packages/builtin-tool-message/src/manifest.ts
@@ -211,7 +211,7 @@ const botSettingsSchema = {
},
botWakeDutiesThreshold: {
description:
- 'How sure the bot must be that a message falls within botWakeDuties before it steps in, 0..1 (default 0.8). Higher = steps in less often.',
+ 'How sure the bot must be that a message falls within botWakeDuties before it steps in, 0..1 (default 0.65). Higher = steps in less often.',
maximum: 1,
minimum: 0,
type: 'number',
diff --git a/packages/builtin-tool-message/src/systemRole.ts b/packages/builtin-tool-message/src/systemRole.ts
index 6c4f1ddceb4..e414d66a98a 100644
--- a/packages/builtin-tool-message/src/systemRole.ts
+++ b/packages/builtin-tool-message/src/systemRole.ts
@@ -131,7 +131,7 @@ All three arrays are written as a whole — passing \`{ allowFrom: [{ id: 'X' }]
Skipping step 1 will silently wipe other entries.
-**botWakeDuties** — the bot's duties (职责边界): free text, one duty per line, describing what the bot is responsible for in its channels. With bot-wake on, a message from anyone that nobody addressed to the bot but that falls within these duties may wake it; empty turns this off. \`botWakeDutiesThreshold\` (0..1, default 0.8) is how sure it must be. Only change the duties when the bot's owner asks. The text is written as a whole: \`getBotDetail\` → edit \`settings.botWakeDuties\` (keep every duty you did not mean to touch, in the owner's language) → \`updateBot({ settings: { botWakeDuties: '<full text>' } })\`.
+**botWakeDuties** — the bot's duties (职责边界): free text, one duty per line, describing what the bot is responsible for in its channels. With bot-wake on, a message from anyone that nobody addressed to the bot but that falls within these duties may wake it; empty turns this off. \`botWakeDutiesThreshold\` (0..1, default 0.65) is how sure it must be. Only change the duties when the bot's owner asks. The text is written as a whole: \`getBotDetail\` → edit \`settings.botWakeDuties\` (keep every duty you did not mean to touch, in the owner's language) → \`updateBot({ settings: { botWakeDuties: '<full text>' } })\`.
**replyStyle / channelReplyStyles / replyEmojis** — how the bot talks, not what it does. \`replyStyle\` is free text for every channel (tone, length, formatting, emoji use); \`channelReplyStyles\` (\`[{ channelId, style }]\`) replaces it in one channel or thread; \`replyEmojis\` (\`[{ emoji, usage? }]\`) lists the emoji and stickers it may use, each pasted as is (\`<:name:id>\` on Discord, \`:name:\` on Slack, or a Unicode emoji) with when it fits. To find a Discord custom emoji's code, ask the owner to send it with a backslash in front (\`\\:name:\`). Only change them when the bot's owner asks; same read-modify-write as the arrays above.
diff --git a/src/features/AgentChannel/PlatformDetail/index.save.test.tsx b/src/features/AgentChannel/PlatformDetail/index.save.test.tsx
index 34d2948d130..2e61a36e40d 100644
--- a/src/features/AgentChannel/PlatformDetail/index.save.test.tsx
+++ b/src/features/AgentChannel/PlatformDetail/index.save.test.tsx
@@ -185,7 +185,7 @@ describe('PlatformDetail saving', () => {
const [, , patch] = mocks.updateBotProvider.mock.calls[0];
expect(patch.settings.botWakeMaxSilentWakes).toBe(5);
// The sensitivity is edited but not saved: the write carries the stored value.
- expect(patch.settings.botWakeDutiesThreshold).toBe(0.8);
+ expect(patch.settings.botWakeDutiesThreshold).toBe(0.65);
expect(patch).not.toHaveProperty('credentials');
expect(mocks.connectBot).not.toHaveBeenCalled();