From 7c9258cfc978e2ec311e99999e45d3599e7a9bbd Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Sun, 23 Nov 2025 19:47:11 +0530 Subject: [PATCH] feat(intents): update intent prompt --- .../classifier/intents/academicSearch.ts | 45 ++++++++++++++++- .../classifier/intents/discussionSearch.ts | 50 +++++++++++++++++-- .../agents/search/classifier/intents/index.ts | 2 + .../search/classifier/intents/registry.ts | 8 +-- .../search/classifier/intents/webSearch.ts | 24 ++++++++- .../search/classifier/intents/writingTask.ts | 46 ++++++++++++++++- 6 files changed, 163 insertions(+), 12 deletions(-) diff --git a/src/lib/agents/search/classifier/intents/academicSearch.ts b/src/lib/agents/search/classifier/intents/academicSearch.ts index b6da377..199f583 100644 --- a/src/lib/agents/search/classifier/intents/academicSearch.ts +++ b/src/lib/agents/search/classifier/intents/academicSearch.ts @@ -1,9 +1,50 @@ import { Intent } from '../../types'; +const description = `Use this intent to search for scholarly articles, research papers, scientific studies, and academic resources when the user explicitly requests credible, peer-reviewed, or authoritative information from academic sources. + +#### When to use: +1. User explicitly mentions academic keywords: research papers, scientific studies, scholarly articles, peer-reviewed, journal articles. +2. User asks for scientific evidence or academic research on a topic. +3. User needs authoritative, citation-worthy sources for research or academic purposes. + +#### When NOT to use: +1. General questions that don't specifically request academic sources - use 'web_search' instead. +2. User just wants general information without specifying academic sources. +3. Casual queries about facts or current events. + +#### Example use cases: +1. "Find scientific papers on climate change effects" + - User explicitly wants scientific papers. + - Intent: ['academic_search'] with skipSearch: false + +2. "What does the research say about meditation benefits?" + - User is asking for research-based information. + - Intent: ['academic_search', 'web_search'] with skipSearch: false + +3. "Show me peer-reviewed articles on CRISPR technology" + - User specifically wants peer-reviewed academic content. + - Intent: ['academic_search'] with skipSearch: false + +4. "I need scholarly sources about renewable energy for my thesis" + - User explicitly needs scholarly/academic sources. + - Intent: ['academic_search'] with skipSearch: false + +5. "Explain quantum computing" (WRONG to use academic_search alone) + - This is a general question, not specifically requesting academic papers. + - Correct intent: ['web_search'] with skipSearch: false + - Could combine: ['web_search', 'academic_search'] if you want both general and academic sources + +6. "What's the latest study on sleep patterns?" + - User mentions "study" - combine academic and web search for comprehensive results. + - Intent: ['academic_search', 'web_search'] with skipSearch: false + +**IMPORTANT**: This intent can be combined with 'web_search' to provide both academic papers and general web information. Always set skipSearch to false when using this intent. + +**NOTE**: This intent is only available if academic search sources are enabled in the configuration.`; + const academicSearchIntent: Intent = { name: 'academic_search', - description: - 'Use this intent to find scholarly articles, research papers, and academic resources when the user is seeking credible and authoritative information on a specific topic.', + description, requiresSearch: true, enabled: (config) => config.sources.includes('academic'), }; diff --git a/src/lib/agents/search/classifier/intents/discussionSearch.ts b/src/lib/agents/search/classifier/intents/discussionSearch.ts index 76b3b01..b7e2cfd 100644 --- a/src/lib/agents/search/classifier/intents/discussionSearch.ts +++ b/src/lib/agents/search/classifier/intents/discussionSearch.ts @@ -1,9 +1,53 @@ import { Intent } from '../../types'; +const description = `Use this intent to search through discussion forums, community boards, and social platforms (Reddit, forums, etc.) when the user explicitly wants opinions, personal experiences, community discussions, or crowd-sourced information. + +#### When to use: +1. User explicitly mentions: Reddit, forums, discussion boards, community opinions, "what do people think", "user experiences". +2. User is asking for opinions, reviews, or personal experiences about a product, service, or topic. +3. User wants to know what communities or people are saying about something. + +#### When NOT to use: +1. General questions that don't specifically ask for opinions or discussions - use 'web_search' instead. +2. User wants factual information or official sources. +3. Casual queries about facts, news, or current events without requesting community input. + +#### Example use cases: +1. "What do people on Reddit think about the new iPhone?" + - User explicitly wants Reddit/community opinions. + - Intent: ['discussions_search'] with skipSearch: false + +2. "User experiences with Tesla Model 3" + - User is asking for personal experiences from users. + - Intent: ['discussions_search'] with skipSearch: false + +3. "Best gaming laptop according to forums" + - User wants forum/community recommendations. + - Intent: ['discussions_search'] with skipSearch: false + +4. "What are people saying about the new AI regulations?" + - User wants community discussions/opinions. + - Intent: ['discussions_search', 'web_search'] with skipSearch: false + +5. "Reviews and user opinions on the Framework laptop" + - Combines user opinions with general reviews. + - Intent: ['discussions_search', 'web_search'] with skipSearch: false + +6. "What's the price of iPhone 15?" (WRONG to use discussions_search) + - This is a factual question, not asking for opinions. + - Correct intent: ['web_search'] with skipSearch: false + +7. "Explain how OAuth works" (WRONG to use discussions_search) + - This is asking for information, not community opinions. + - Correct intent: ['web_search'] with skipSearch: false + +**IMPORTANT**: This intent can be combined with 'web_search' to provide both community discussions and official/factual information. Always set skipSearch to false when using this intent. + +**NOTE**: This intent is only available if discussion search sources are enabled in the configuration.`; + const discussionSearchIntent: Intent = { - name: 'discussion_search', - description: - 'Use this intent to search through discussion forums, community boards, or social media platforms when the user is looking for opinions, experiences, or community-driven information on a specific topic.', + name: 'discussions_search', + description, requiresSearch: true, enabled: (config) => config.sources.includes('discussions'), }; diff --git a/src/lib/agents/search/classifier/intents/index.ts b/src/lib/agents/search/classifier/intents/index.ts index feefd2d..fcab1c7 100644 --- a/src/lib/agents/search/classifier/intents/index.ts +++ b/src/lib/agents/search/classifier/intents/index.ts @@ -1,5 +1,6 @@ import academicSearchIntent from './academicSearch'; import discussionSearchIntent from './discussionSearch'; +import privateSearchIntent from './privateSearch'; import IntentRegistry from './registry'; import webSearchIntent from './webSearch'; import widgetResponseIntent from './widgetResponse'; @@ -10,5 +11,6 @@ IntentRegistry.register(academicSearchIntent); IntentRegistry.register(discussionSearchIntent); IntentRegistry.register(widgetResponseIntent); IntentRegistry.register(writingTaskIntent); +IntentRegistry.register(privateSearchIntent); export { IntentRegistry }; diff --git a/src/lib/agents/search/classifier/intents/registry.ts b/src/lib/agents/search/classifier/intents/registry.ts index bc3464b..4efdbc4 100644 --- a/src/lib/agents/search/classifier/intents/registry.ts +++ b/src/lib/agents/search/classifier/intents/registry.ts @@ -18,10 +18,12 @@ class IntentRegistry { } static getDescriptions(config: { sources: SearchSources[] }): string { - const availableintnets = this.getAvailableIntents(config); + const availableintents = this.getAvailableIntents(config); - return availableintnets - .map((intent) => `${intent.name}: ${intent.description}`) + return availableintents + .map( + (intent) => `-------\n\n###${intent.name}: ${intent.description}\n\n`, + ) .join('\n\n'); } } diff --git a/src/lib/agents/search/classifier/intents/webSearch.ts b/src/lib/agents/search/classifier/intents/webSearch.ts index 9fccd2f..3f795e4 100644 --- a/src/lib/agents/search/classifier/intents/webSearch.ts +++ b/src/lib/agents/search/classifier/intents/webSearch.ts @@ -1,9 +1,29 @@ import { Intent } from '../../types'; +const description = ` +Use this intent to find current information from the web when the user is asking a question or needs up-to-date information that cannot be provided by widgets or other intents. + +#### When to use: +1. Simple user questions about current events, news, weather, or general knowledge that require the latest information and there is no specific better intent to use. +2. When the user explicitly requests information from the web or indicates they want the most recent data (and still there's no other better intent). +3. When no widgets can fully satisfy the user's request for information nor any other specialized search intent applies. + +#### Examples use cases: +1. "What is the weather in San Francisco today? ALso tell me some popular events happening there this weekend." + - In this case, the weather widget can provide the current weather, but for popular events, a web search is needed. So the intent should include a 'web_search' & a 'widget_response'. + +2. "Who won the Oscar for Best Picture in 2024?" + - This is a straightforward question that requires current information from the web. + +3. "Give me the latest news on AI regulations." + - The user is asking for up-to-date news, which necessitates a web search. + +**IMPORTANT**: If this intent is given then skip search should be false. +`; + const webSearchIntent: Intent = { name: 'web_search', - description: - 'Use this intent to find current information from the web when the user is asking a question or needs up-to-date information that cannot be provided by widgets or other intents.', + description: description, requiresSearch: true, enabled: (config) => config.sources.includes('web'), }; diff --git a/src/lib/agents/search/classifier/intents/writingTask.ts b/src/lib/agents/search/classifier/intents/writingTask.ts index 95b5af6..3edc0b3 100644 --- a/src/lib/agents/search/classifier/intents/writingTask.ts +++ b/src/lib/agents/search/classifier/intents/writingTask.ts @@ -1,9 +1,51 @@ import { Intent } from '../../types'; +const description = `Use this intent for simple writing or greeting tasks that do not require any external information or facts. This is ONLY for greetings and straightforward creative writing that needs no factual verification. + +#### When to use: +1. User greetings or simple social interactions (hello, hi, thanks, goodbye). +2. Creative writing tasks that require NO factual information (poems, birthday messages, thank you notes). +3. Simple drafting tasks where the user provides all necessary information. + +#### When NOT to use: +1. ANY question that starts with "what", "how", "why", "when", "where", "who" - these need web_search. +2. Requests for explanations, definitions, or information about anything. +3. Code-related questions or technical help - these need web_search. +4. Writing tasks that require facts, data, or current information. +5. When you're uncertain about any information needed - default to web_search. + +#### Example use cases: +1. "Hello" or "Hi there" + - Simple greeting, no information needed. + - Intent: ['writing_task'] with skipSearch: true + +2. "Write me a birthday message for my friend" + - Creative writing, no facts needed. + - Intent: ['writing_task'] with skipSearch: true + +3. "Draft a thank you email for a job interview" + - Simple writing task, no external information required. + - Intent: ['writing_task'] with skipSearch: true + +4. "What is React?" (WRONG to use writing_task) + - This is a QUESTION asking for information. + - Correct intent: ['web_search'] with skipSearch: false + +5. "How do I fix this error in Python?" (WRONG to use writing_task) + - This is asking for technical help. + - Correct intent: ['web_search'] with skipSearch: false + +6. "Write an email about the latest AI developments" (WRONG to use writing_task alone) + - This requires current information about AI developments. + - Correct intent: ['web_search'] with skipSearch: false + +**CRITICAL RULE**: When in doubt, DO NOT use this intent. Default to web_search. This intent should be rare - only use it for greetings and purely creative writing tasks that need absolutely no facts or information. + +**IMPORTANT**: If this intent is used alone, skipSearch should be true. Never combine this with other search intents unless you're absolutely certain both are needed.`; + const writingTaskIntent: Intent = { name: 'writing_task', - description: - 'Use this intent to assist users with writing tasks such as drafting emails, creating documents, or generating content based on their instructions or greetings.', + description, requiresSearch: false, enabled: (config) => true, };