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.

💄 feat(chat): render a bot's decision not to reply as its own state (#21727)

Arvin Xue14876011db5
diff --git a/apps/server/src/services/bot/noReply.ts b/apps/server/src/services/bot/noReply.ts
index 7dba15048a7..bb66446de08 100644
--- a/apps/server/src/services/bot/noReply.ts
+++ b/apps/server/src/services/bot/noReply.ts
@@ -1,13 +1,5 @@
-import type { BotNoReplyReason, BotNoReplyResult, BotWakeKind } from '@lobechat/types';
-import { BOT_NO_REPLY_REASONS, BOT_NO_REPLY_TOKEN } from '@lobechat/types';
-
-const REASONS = new Set<string>(BOT_NO_REPLY_REASONS);
-
-/** `NO_REPLY`, `NO_REPLY:duplicate`, tolerating backticks / brackets and a trailing period. */
-const NO_REPLY_PATTERN = new RegExp(
- String.raw`^[\s\`\[(]*${BOT_NO_REPLY_TOKEN}(?:\s*[::]\s*([a-z_]+))?[\s\`\])]*[.。]?\s*$`,
- 'i',
-);
+import type { BotNoReplyResult, BotWakeKind } from '@lobechat/types';
+import { parseBotNoReplyToken } from '@lobechat/types';
export interface DetectNoReplyInput {
/** The run's final assistant text. */
@@ -39,15 +31,7 @@ export const detectNoReply = ({
if (!text) return hasAttachments ? undefined : { reason: 'empty_completion' };
- const match = NO_REPLY_PATTERN.exec(text);
- if (!match) return undefined;
-
- const raw = match[1]?.toLowerCase();
- // `empty_completion` is detected by us, never claimed by the agent.
- const reason: BotNoReplyReason =
- raw && REASONS.has(raw) && raw !== 'empty_completion'
- ? (raw as BotNoReplyReason)
- : 'unspecified';
+ const reason = parseBotNoReplyToken(text);
- return { reason };
+ return reason ? { reason } : undefined;
};
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index 96694b7254b..fa8cb3b61f2 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -1854,6 +1854,12 @@
"noAvailableAgents": "No members available to invite",
"noMatchingAgents": "No matching members found",
"noMembersYet": "This group doesn't have any members yet. Click the + button to invite agents.",
+ "noReply.reason.already_handled": "Someone else is on it",
+ "noReply.reason.duplicate": "Already answered",
+ "noReply.reason.not_addressed": "Not addressed to me",
+ "noReply.reason.nothing_to_add": "Nothing to add",
+ "noReply.reason.off_topic": "Not relevant to me",
+ "noReply.title": "Read the message and chose not to reply",
"noSelectedAgents": "No members selected yet",
"opStatusTray.cost": "cost",
"opStatusTray.llmCalls": "LLM calls",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index 8f5d474dbc0..0abde079946 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -1854,6 +1854,12 @@
"noAvailableAgents": "暂无可邀请的成员",
"noMatchingAgents": "未找到匹配的成员",
"noMembersYet": "这个群组还没有成员。点击「+」邀请助理加入",
+ "noReply.reason.already_handled": "已有人处理",
+ "noReply.reason.duplicate": "已经回答过",
+ "noReply.reason.not_addressed": "不是对我说的",
+ "noReply.reason.nothing_to_add": "没有要补充的",
+ "noReply.reason.off_topic": "与我无关",
+ "noReply.title": "分析后决定不回复",
"noSelectedAgents": "还未选择成员",
"opStatusTray.cost": "花费",
"opStatusTray.llmCalls": "次模型调用",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index af5a6196223..3f8860f7f58 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -1545,6 +1545,12 @@ export default {
'platformAgent.deviceGuard.refresh': 'Refresh',
'platformAgent.deviceGuard.configure': 'Configure',
'newPage': 'Create Page',
+ 'noReply.reason.already_handled': 'Someone else is on it',
+ 'noReply.reason.duplicate': 'Already answered',
+ 'noReply.reason.not_addressed': 'Not addressed to me',
+ 'noReply.reason.nothing_to_add': 'Nothing to add',
+ 'noReply.reason.off_topic': 'Not relevant to me',
+ 'noReply.title': 'Read the message and chose not to reply',
'noAgentsYet': 'This group has no members yet. Click the + button to invite agents.',
'noAvailableAgents': 'No members available to invite',
'noMatchingAgents': 'No matching members found',
diff --git a/packages/types/src/signal.test.ts b/packages/types/src/signal.test.ts
new file mode 100644
index 00000000000..fd6eeae56df
--- /dev/null
+++ b/packages/types/src/signal.test.ts
@@ -0,0 +1,39 @@
+import { describe, expect, it } from 'vitest';
+
+import { parseBotNoReplyToken } from './signal';
+
+describe('parseBotNoReplyToken', () => {
+ it.each([
+ ['NO_REPLY', 'unspecified'],
+ [' NO_REPLY\n', 'unspecified'],
+ ['`NO_REPLY`', 'unspecified'],
+ ['no_reply', 'unspecified'],
+ ['NO_REPLY.', 'unspecified'],
+ ['NO_REPLY:duplicate', 'duplicate'],
+ ['NO_REPLY: already_handled', 'already_handled'],
+ ['[NO_REPLY:off_topic]', 'off_topic'],
+ ['NO_REPLY:nothing_to_add', 'nothing_to_add'],
+ ['NO_REPLY:not_addressed', 'not_addressed'],
+ ['NO_REPLY:NOT_ADDRESSED', 'not_addressed'],
+ ])('reads %j as the token with reason %s', (content, reason) => {
+ expect(parseBotNoReplyToken(content)).toBe(reason);
+ });
+
+ it('collapses an unknown reason, and one the agent cannot claim, to unspecified', () => {
+ expect(parseBotNoReplyToken('NO_REPLY:because')).toBe('unspecified');
+ expect(parseBotNoReplyToken('NO_REPLY:empty_completion')).toBe('unspecified');
+ });
+
+ it.each([
+ [undefined],
+ [null],
+ [''],
+ [' '],
+ ['I will reply NO_REPLY when nothing is needed.'],
+ ['NO_REPLY\n\nActually, here is the answer.'],
+ ['The token is `NO_REPLY:duplicate`'],
+ ['NO_REPLY:not addressed'],
+ ])('does not treat %j as the token', (content) => {
+ expect(parseBotNoReplyToken(content)).toBeUndefined();
+ });
+});
diff --git a/packages/types/src/signal.ts b/packages/types/src/signal.ts
index 7892df5ea96..b96a84de179 100644
--- a/packages/types/src/signal.ts
+++ b/packages/types/src/signal.ts
@@ -82,17 +82,17 @@ export interface SignalDecisionMetadata {
/** What a label needs beyond `label`, `source` and `confidence`. No message content, as above. */
export interface SignalDecisionLabelMetadata {
+ /**
+ * The signal that proved the label, when another event did — e.g. the later manual mention
+ * that shows a `missed_wake`. A signal's `external_id`, not its row id.
+ */
+ evidenceExternalId?: string;
/** Scenario-specific extras that are not worth a typed field yet. */
extra?: Record<string, unknown>;
/** Short rationale from a judge model or a person. */
rationale?: string;
/** Machine-readable reason behind the label, e.g. a `BotNoReplyReason`. */
reason?: string;
- /**
- * The signal that proved the label, when another event did — e.g. the later manual mention
- * that shows a `missed_wake`. A signal's `external_id`, not its row id.
- */
- evidenceExternalId?: string;
/** Where the label was applied: `reaction`, `button`, `admin`, `job`, … */
surface?: string;
}
@@ -134,6 +134,8 @@ export const BOT_NO_REPLY_REASONS = [
'empty_completion',
] as const;
export type BotNoReplyReason = (typeof BOT_NO_REPLY_REASONS)[number];
+/** A reason the agent itself can give in the token; `empty_completion` is only ever detected. */
+export type BotNoReplyClaimedReason = Exclude<BotNoReplyReason, 'empty_completion'>;
/**
* The decision label each silence reason is written under. Staying silent means the wake was not
@@ -149,6 +151,39 @@ export const BOT_NO_REPLY_LABELS: Record<BotNoReplyReason, SignalDecisionLabel>
unspecified: 'false_wake',
};
+/**
+ * `NO_REPLY`, `NO_REPLY:duplicate`, tolerating backticks (`\x60`) / brackets and a trailing period.
+ * Matched against trimmed text, so it needs no trailing whitespace of its own.
+ */
+const BOT_NO_REPLY_PATTERN = new RegExp(
+ String.raw`^[\s\x60[(]*${BOT_NO_REPLY_TOKEN}(?:\s*[::]\s*([a-z_]+))?[\s\x60\])]*[.。]?$`,
+ 'i',
+);
+
+const BOT_NO_REPLY_REASON_SET = new Set<string>(BOT_NO_REPLY_REASONS);
+
+/**
+ * Reads a text that consists only of the `NO_REPLY[:reason]` token and returns its reason.
+ *
+ * An unknown reason collapses to `unspecified`, and so does `empty_completion`: that one is
+ * detected by the server, never claimed by the agent. Returns `undefined` for any other text,
+ * including text that merely mentions the token.
+ */
+export const parseBotNoReplyToken = (
+ content?: string | null,
+): BotNoReplyClaimedReason | undefined => {
+ if (!content) return undefined;
+
+ const match = BOT_NO_REPLY_PATTERN.exec(content.trim());
+ if (!match) return undefined;
+
+ const raw = match[1]?.toLowerCase();
+
+ return raw && BOT_NO_REPLY_REASON_SET.has(raw) && raw !== 'empty_completion'
+ ? (raw as BotNoReplyClaimedReason)
+ : 'unspecified';
+};
+
/** An agent run that finished by choosing silence. */
export interface BotNoReplyResult {
reason: BotNoReplyReason;
diff --git a/src/features/Conversation/Messages/Assistant/components/MessageContent.tsx b/src/features/Conversation/Messages/Assistant/components/MessageContent.tsx
index 15c099a31f7..23ffd411025 100644
--- a/src/features/Conversation/Messages/Assistant/components/MessageContent.tsx
+++ b/src/features/Conversation/Messages/Assistant/components/MessageContent.tsx
@@ -8,6 +8,7 @@ import { CollapsedMessage } from '../../AssistantGroup/components/CollapsedMessa
import DisplayContent from '../../components/DisplayContent';
import FileChunks from '../../components/FileChunks';
import ImageFileListViewer from '../../components/ImageFileListViewer';
+import { NoReplyNotice, resolveNoReplyReason } from '../../components/NoReplyNotice';
import Reasoning, { hasRenderableReasoning } from '../../components/Reasoning';
import SearchGrounding from '../../components/SearchGrounding';
import { useMarkdown } from '../useMarkdown';
@@ -34,6 +35,12 @@ const MessageContent = memo<UIChatMessage>(
const showFileChunks = !!chunksList && chunksList.length > 0;
+ const noReplyReason = resolveNoReplyReason({
+ content,
+ hasOtherOutput: !!tools?.length || showImageItems || !!metadata?.isMultimodal,
+ isGenerating: isLoading,
+ });
+
if (isCollapsed) return <CollapsedMessage content={content} id={id} />;
return (
@@ -49,16 +56,20 @@ const MessageContent = memo<UIChatMessage>(
)}
{showFileChunks && <FileChunks data={chunksList} />}
{showReasoning && <Reasoning {...props.reasoning} id={id} />}
- <DisplayContent
- content={content}
- generating={isLoading}
- hasImages={showImageItems}
- id={id}
- isMultimodal={metadata?.isMultimodal}
- isToolCallGenerating={isToolCallGenerating}
- markdownProps={markdownProps}
- tempDisplayContent={metadata?.tempDisplayContent}
- />
+ {noReplyReason ? (
+ <NoReplyNotice reason={noReplyReason} />
+ ) : (
+ <DisplayContent
+ content={content}
+ generating={isLoading}
+ hasImages={showImageItems}
+ id={id}
+ isMultimodal={metadata?.isMultimodal}
+ isToolCallGenerating={isToolCallGenerating}
+ markdownProps={markdownProps}
+ tempDisplayContent={metadata?.tempDisplayContent}
+ />
+ )}
{showImageItems && <ImageFileListViewer items={imageList} />}
</Flexbox>
);
diff --git a/src/features/Conversation/Messages/AssistantGroup/components/MessageContent.test.tsx b/src/features/Conversation/Messages/AssistantGroup/components/MessageContent.test.tsx
index 5a5b616112b..02e7acff741 100644
--- a/src/features/Conversation/Messages/AssistantGroup/components/MessageContent.test.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/components/MessageContent.test.tsx
@@ -9,6 +9,7 @@ import MessageContent from './MessageContent';
let mockStoreContent = 'original full content';
let mockStoreHasTools = true;
+let mockIsGenerating = false;
let mockStoreMessage:
| { createdAt?: number; metadata?: { isMultimodal?: boolean; tempDisplayContent?: string } }
| undefined = { createdAt: 1000 };
@@ -42,6 +43,9 @@ vi.mock('../../../store', () => ({
getBlockMetadata: () => () => mockStoreMessage?.metadata,
getDbMessageById: () => () => mockStoreMessage,
},
+ messageStateSelectors: {
+ isAssistantGroupItemGenerating: () => () => mockIsGenerating,
+ },
useConversationStore: (selector: (state: unknown) => unknown) => selector({}),
}));
@@ -59,6 +63,7 @@ describe('MessageContent', () => {
useMarkdownMock.mockClear();
mockStoreContent = 'original full content';
mockStoreHasTools = true;
+ mockIsGenerating = false;
mockStoreMessage = { createdAt: 1000 };
});
@@ -118,4 +123,59 @@ describe('MessageContent', () => {
);
expect(screen.queryByTestId('markdown')).not.toBeInTheDocument();
});
+
+ describe('a bot that chose not to reply', () => {
+ it('renders NO_REPLY:<reason> as the decision with its reason, not the raw token', () => {
+ mockStoreContent = 'NO_REPLY:not_addressed';
+ mockStoreHasTools = false;
+
+ render(<MessageContent id="block-1" />);
+
+ expect(screen.getByTestId('no-reply-notice')).toHaveTextContent(
+ 'noReply.title · noReply.reason.not_addressed',
+ );
+ expect(screen.queryByTestId('markdown')).not.toBeInTheDocument();
+ });
+
+ it('renders a bare NO_REPLY as the decision without a reason', () => {
+ mockStoreContent = 'NO_REPLY';
+ mockStoreHasTools = false;
+
+ render(<MessageContent id="block-1" />);
+
+ expect(screen.getByTestId('no-reply-notice')).toHaveTextContent(/^noReply\.title$/);
+ expect(screen.queryByTestId('markdown')).not.toBeInTheDocument();
+ });
+
+ it('keeps rendering text that merely mentions NO_REPLY as markdown', () => {
+ mockStoreContent = 'I answer NO_REPLY:not_addressed when a message is not for me.';
+ mockStoreHasTools = false;
+
+ render(<MessageContent id="block-1" />);
+
+ expect(screen.getByTestId('markdown')).toHaveTextContent(mockStoreContent);
+ expect(screen.queryByTestId('no-reply-notice')).not.toBeInTheDocument();
+ });
+
+ it('keeps the raw text while the message is still generating', () => {
+ mockStoreContent = 'NO_REPLY';
+ mockStoreHasTools = false;
+ mockIsGenerating = true;
+
+ render(<MessageContent id="block-1" />);
+
+ expect(screen.getByTestId('markdown')).toHaveTextContent('NO_REPLY');
+ expect(screen.queryByTestId('no-reply-notice')).not.toBeInTheDocument();
+ });
+
+ it('keeps the raw text when the block also has tool calls to show', () => {
+ mockStoreContent = 'NO_REPLY';
+ mockStoreHasTools = true;
+
+ render(<MessageContent id="block-1" />);
+
+ expect(screen.getByTestId('markdown')).toHaveTextContent('NO_REPLY');
+ expect(screen.queryByTestId('no-reply-notice')).not.toBeInTheDocument();
+ });
+ });
});
diff --git a/src/features/Conversation/Messages/AssistantGroup/components/MessageContent.tsx b/src/features/Conversation/Messages/AssistantGroup/components/MessageContent.tsx
index 63b19d2cfc8..8291214380f 100644
--- a/src/features/Conversation/Messages/AssistantGroup/components/MessageContent.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/components/MessageContent.tsx
@@ -5,9 +5,13 @@ import { memo } from 'react';
import { LOADING_FLAT } from '@/const/message';
import MarkdownMessage from '@/features/Conversation/Markdown';
import ContentLoading from '@/features/Conversation/Messages/components/ContentLoading';
+import {
+ NoReplyNotice,
+ resolveNoReplyReason,
+} from '@/features/Conversation/Messages/components/NoReplyNotice';
import { RichContentRenderer } from '@/features/Conversation/Messages/components/RichContentRenderer';
-import { dataSelectors, useConversationStore } from '../../../store';
+import { dataSelectors, messageStateSelectors, useConversationStore } from '../../../store';
import { normalizeThinkTags, processWithArtifact } from '../../../utils/markdown';
import { useMarkdown } from '../useMarkdown';
@@ -54,6 +58,10 @@ const MessageContent = memo<MessageContentProps>(
(s) => dataSelectors.getBlockMetadata(id)(s)?.tempDisplayContent as string | undefined,
);
+ const isGenerating = useConversationStore(
+ messageStateSelectors.isAssistantGroupItemGenerating(id),
+ );
+
const message = normalizeThinkTags(processWithArtifact(content ?? ''));
// Once a tool call exists below this block's text, the text is already
// finalized — skip the streaming/fade-in animation so settled content above
@@ -67,6 +75,13 @@ const MessageContent = memo<MessageContentProps>(
return <ContentLoading id={id} startTime={createdAt} />;
}
+ const noReplyReason = resolveNoReplyReason({
+ content,
+ hasOtherOutput: hasTools || isMultimodal,
+ isGenerating,
+ });
+ if (noReplyReason) return <NoReplyNotice reason={noReplyReason} />;
+
const contentParts =
isMultimodal && content ? deserializeParts(tempDisplayContent || content) : null;
if (contentParts) return <RichContentRenderer parts={contentParts} />;
diff --git a/src/features/Conversation/Messages/components/NoReplyNotice.tsx b/src/features/Conversation/Messages/components/NoReplyNotice.tsx
new file mode 100644
index 00000000000..b2489e845c1
--- /dev/null
+++ b/src/features/Conversation/Messages/components/NoReplyNotice.tsx
@@ -0,0 +1,58 @@
+import type { BotNoReplyClaimedReason } from '@lobechat/types';
+import { parseBotNoReplyToken } from '@lobechat/types';
+import { Flexbox, Icon } from '@lobehub/ui';
+import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
+import * as stylex from '@stylexjs/stylex';
+import { MessageCircleOffIcon } from 'lucide-react';
+import { useTranslation } from 'react-i18next';
+
+const styles = stylex.create({
+ root: {
+ color: cssVar.colorTextTertiary,
+ fontSize: cssVar.fontSizeSM,
+ lineHeight: 1.6,
+ },
+});
+
+interface ResolveNoReplyReasonParams {
+ content?: string | null;
+ /** Anything else the message shows (tool calls, images) means it is not a bare decision. */
+ hasOtherOutput?: boolean;
+ /** A streaming `NO_REPLY…` may still turn into a real answer, so only a finished one counts. */
+ isGenerating?: boolean;
+}
+
+/**
+ * The reason a bot gave for staying silent, when an assistant message is nothing but its
+ * `NO_REPLY[:reason]` token. `undefined` for any other message.
+ */
+export const resolveNoReplyReason = ({
+ content,
+ hasOtherOutput,
+ isGenerating,
+}: ResolveNoReplyReasonParams): BotNoReplyClaimedReason | undefined => {
+ if (isGenerating || hasOtherOutput) return undefined;
+
+ return parseBotNoReplyToken(content);
+};
+
+/** Stands in for the raw `NO_REPLY` token: the bot read the message and chose not to reply. */
+export const NoReplyNotice = ({ reason }: { reason: BotNoReplyClaimedReason }) => {
+ const { t } = useTranslation('chat');
+
+ return (
+ <Flexbox
+ horizontal
+ align={'center'}
+ data-testid="no-reply-notice"
+ gap={6}
+ {...stylex.props(styles.root)}
+ >
+ <Icon icon={MessageCircleOffIcon} size={14} />
+ <span>
+ {t('noReply.title')}
+ {reason !== 'unspecified' && ` · ${t(`noReply.reason.${reason}`)}`}
+ </span>
+ </Flexbox>
+ );
+};