Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(web): show agent opening statement in embedded floating widget (#18517)

euvre97812c9ce593
diff --git a/web/src/components/floating-chat-widget.tsx b/web/src/components/floating-chat-widget.tsx
index 08397f7bf5..8c038a5ce3 100644
--- a/web/src/components/floating-chat-widget.tsx
+++ b/web/src/components/floating-chat-widget.tsx
@@ -98,6 +98,13 @@ const normalizeWidgetFooterLink = (value: string | null) => {
return undefined;
};
+/**
+ * Stable id for the seeded agent prologue. `addNewestOneAnswer` dedupes by
+ * message id, so a re-invoked effect (e.g. under React StrictMode) merges
+ * into the seeded message instead of appending a duplicate.
+ */
+const PROLOGUE_MESSAGE_ID = 'prologue';
+
/**
* Renders the embeddable floating chat widget and applies URL-driven widget settings.
*/
@@ -164,6 +171,14 @@ const FloatingChatWidget = () => {
hasError,
} = hookResult;
const findReferenceByMessageId = (hookResult as any).findReferenceByMessageId;
+ // Only the agent flow exposes these. The chat flow receives its prologue
+ // through the completions handshake instead, so both stay optional here.
+ const { addNewestOneAnswer, isTaskMode } = hookResult as Partial<
+ Pick<
+ ReturnType<typeof useSendNextSharedMessage>,
+ 'addNewestOneAnswer' | 'isTaskMode'
+ >
+ >;
// Sync our local input with the hook's value when needed
useEffect(() => {
@@ -176,6 +191,23 @@ const FloatingChatWidget = () => {
isFromAgent ? useFetchExternalAgentInputs : useFetchExternalChatInfo
)();
+ // Seed the agent's opening statement. The agent send hook derives the
+ // prologue from the agent canvas graph store, which is never populated on
+ // the widget page, so mirror pages/agent/share and take the prologue from
+ // the agentbots inputs endpoint instead. The chat flow already gets its
+ // prologue from the completions handshake.
+ useEffect(() => {
+ if (!isFromAgent || isTaskMode) {
+ return;
+ }
+ if (data?.prologue) {
+ addNewestOneAnswer?.({
+ answer: data.prologue,
+ id: PROLOGUE_MESSAGE_ID,
+ });
+ }
+ }, [isFromAgent, isTaskMode, data?.prologue, addNewestOneAnswer]);
+
const title = data.title;
const displayTitle = widgetTitle || title || t('chat.chatSupport');
const displaySubtitle = widgetSubtitle || t('chat.replyInstantly');