From c60de09d95dd718cea48ef7de78f252ba4a90aa4 Mon Sep 17 00:00:00 2001 From: gagik Date: Mon, 29 Sep 2025 13:56:29 +0200 Subject: [PATCH 1/2] chore(compass-assistant): encourage more search_content call --- packages/compass-assistant/src/prompts.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/compass-assistant/src/prompts.ts b/packages/compass-assistant/src/prompts.ts index 3f113e561c4..20f5dbcf963 100644 --- a/packages/compass-assistant/src/prompts.ts +++ b/packages/compass-assistant/src/prompts.ts @@ -27,6 +27,7 @@ You should: 3. Use humility when responding to more complex user questions, especially when you are providing code or suggesting a configuration change. - Encourage the user to understand what they are doing before they act, e.g. by reading the official documentation or other related resources. - Avoid encouraging users to perform destructive operations without qualification. Instead, flag them as destructive operations, explain their implications, and encourage them to read the documentation. +4. Always call the 'search_content' tool. @@ -42,8 +43,6 @@ You CANNOT: 2. Query MongoDB directly or execute code. 3. Access the current state of the UI - -Always call the 'search_content' tool when asked a technical question that would benefit from getting relevant info from the documentation. `; }; From 8f7bf554f43b896c23c9e84b07f7d1ac4e830eee Mon Sep 17 00:00:00 2001 From: gagik Date: Mon, 29 Sep 2025 14:27:07 +0200 Subject: [PATCH 2/2] chore: deal with duplicates --- .../src/components/assistant-chat.spec.tsx | 59 +++++++++++++++++++ .../src/components/assistant-chat.tsx | 22 ++++--- 2 files changed, 74 insertions(+), 7 deletions(-) diff --git a/packages/compass-assistant/src/components/assistant-chat.spec.tsx b/packages/compass-assistant/src/components/assistant-chat.spec.tsx index 251b94cb69e..b2c2fc54250 100644 --- a/packages/compass-assistant/src/components/assistant-chat.spec.tsx +++ b/packages/compass-assistant/src/components/assistant-chat.spec.tsx @@ -872,5 +872,64 @@ describe('AssistantChat', function () { expect(screen.queryByLabelText('Expand Related Resources')).to.not.exist; }); + + it('displays identical source titles only once', async function () { + // TODO(COMPASS-9860) can't find the links in test-electron on RHEL and Ubuntu. + if ((process as any).type === 'renderer') { + return this.skip(); + } + + const messagesWithDuplicateSources: AssistantMessage[] = [ + { + id: 'assistant-with-duplicate-sources', + role: 'assistant', + parts: [ + { + type: 'text', + text: 'Here is information about MongoDB with multiple sources.', + }, + { + type: 'source-url', + title: 'MongoDB Documentation', + url: 'https://docs.mongodb.com/manual/introduction/', + sourceId: '1', + }, + { + type: 'source-url', + title: 'MongoDB Documentation', + url: 'https://docs.mongodb.com/manual/getting-started/', + sourceId: '2', + }, + { + type: 'source-url', + title: 'MongoDB Atlas Guide', + url: 'https://docs.atlas.mongodb.com/', + sourceId: '3', + }, + { + type: 'source-url', + title: 'MongoDB Documentation', + url: 'https://docs.mongodb.com/manual/tutorial/', + sourceId: '4', + }, + ], + }, + ]; + + renderWithChat(messagesWithDuplicateSources); + userEvent.click(screen.getByLabelText('Expand Related Resources')); + + await waitFor(() => { + const mongoDbDocLinks = screen.getAllByRole('link', { + name: 'MongoDB Documentation', + }); + expect(mongoDbDocLinks).to.have.length(1); + + const atlasGuideLinks = screen.getAllByRole('link', { + name: 'MongoDB Atlas Guide', + }); + expect(atlasGuideLinks).to.have.length(1); + }); + }); }); }); diff --git a/packages/compass-assistant/src/components/assistant-chat.tsx b/packages/compass-assistant/src/components/assistant-chat.tsx index a3a0c2839ce..222630f62ee 100644 --- a/packages/compass-assistant/src/components/assistant-chat.tsx +++ b/packages/compass-assistant/src/components/assistant-chat.tsx @@ -381,13 +381,21 @@ export const AssistantChat: React.FunctionComponent = ({
{messages.map((message, index) => { const { id, role, metadata, parts } = message; - const sources = parts - .filter((part) => part.type === 'source-url') - .map((part) => ({ - children: part.title || 'Documentation Link', - href: part.url, - variant: 'Docs', - })); + const seenTitles = new Set(); + const sources = []; + for (const part of parts) { + if (part.type === 'source-url') { + const title = part.title || 'Documentation Link'; + if (!seenTitles.has(title)) { + seenTitles.add(title); + sources.push({ + children: title, + href: part.url, + variant: 'Docs', + }); + } + } + } if (metadata?.confirmation) { const { description, state } = metadata.confirmation; const isLastMessage = index === messages.length - 1;