commit f0060ade3b03e9c4cfde180e3fac50ade2a42b46
parent 94019fef135ba71b75afc72acb43927a03cc2036
Author: frankjc2022 <frankjc2022@gmail.com>
Date: Fri, 12 Dec 2025 16:33:21 +0000
Bug 2005631 - Improve history search tool-calling intent accuracy in chat r=tzhang,ai-models-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D276097
Diffstat:
2 files changed, 65 insertions(+), 53 deletions(-)
diff --git a/browser/components/aiwindow/models/Tools.sys.mjs b/browser/components/aiwindow/models/Tools.sys.mjs
@@ -17,59 +17,58 @@ ChromeUtils.defineESModuleGetters(lazy, {
"moz-src:///browser/components/pagedata/PageDataService.sys.mjs",
});
-// const GET_OPEN_TABS = "get_open_tabs";
-// const SEARCH_BROWSING_HISTORY = "search_browsing_history";
-
-// const TOOLS = [
-// GET_OPEN_TABS,
-// SEARCH_BROWSING_HISTORY,
-// ];
-
-// const toolsConfig = [
-// {
-// type: "function",
-// function: {
-// name: GET_OPEN_TABS,
-// description:
-// "Access the user's browser and return a list of most recently browsed tabs. Each tab is represented by a JSON with the page's url, title and description if available. Default to return maximum 15 tabs.",
-// parameters: {
-// type: "object",
-// properties: {}
-// },
-// },
-// },
-// {
-// type: "function",
-// function: {
-// name: SEARCH_BROWSING_HISTORY,
-// description:
-// "Search the user's browser history stored in sqlite-vec using an embedding model. If a search term is provided, performs vector search and ranks by semantic distance with frecency tie-breaks. If no search term is provided, returns the most relevant pages within a time window ranked by recency and frecency. Supports optional time range filtering using ISO 8601 datetime strings. This is to find previously visited pages related to specific keywords or topics. This helps find relevant pages the user has visited before, even if they're not currently open. All datetime must be before the user's current datetime. For parsing time window from dates and holidays, must depend on the user's current datetime, timezone, and locale.",
-// parameters: {
-// type: "object",
-// properties: {
-// searchTerm: {
-// type: "string",
-// description:
-// "A detailed, noun-heavy phrase (~5-12 meaningful tokens) summarizing the user's intent for semantic retrieval. Include the main entity/topic plus 1-3 contextual qualifiers (e.g., library name, purpose, site, or timeframe). Avoid vague or single-word queries.",
-// },
-// startTs: {
-// type: "string",
-// description:
-// "Inclusive lower bound of the time window as an ISO 8601 datetime string (e.g., '2025-11-07T09:00:00-05:00'). Use when the user asks for results within a time or range start, such as 'last week', 'since yesterday', or 'last night'. This must be before the user's current datetime.",
-// default: null,
-// },
-// endTs: {
-// type: "string",
-// description:
-// "Inclusive upper bound of the time window as an ISO 8601 datetime string (e.g., '2025-11-07T21:00:00-05:00'). Use when the user asks for results within a time or range end, such as 'last week', 'between 2025-10-01 and 2025-10-31', or 'before Monday'. This must be before the user's current datetime.",
-// default: null,
-// },
-// },
-// required: [],
-// },
-// },
-// },
-// ];
+const GET_OPEN_TABS = "get_open_tabs";
+const SEARCH_BROWSING_HISTORY = "search_browsing_history";
+
+// eslint-disable-next-line no-unused-vars
+const TOOLS = [GET_OPEN_TABS, SEARCH_BROWSING_HISTORY];
+
+// eslint-disable-next-line no-unused-vars
+const toolsConfig = [
+ {
+ type: "function",
+ function: {
+ name: GET_OPEN_TABS,
+ description:
+ "Access the user's browser and return a list of most recently browsed tabs. Each tab is represented by a JSON with the page's url, title and description if available. Default to return maximum 15 tabs.",
+ parameters: {
+ type: "object",
+ properties: {},
+ },
+ },
+ },
+ {
+ type: "function",
+ function: {
+ name: SEARCH_BROWSING_HISTORY,
+ description:
+ 'Refind pages from the user\'s PAST BROWSING HISTORY. Use this whenever the user wants to recall, review, list, or see pages they visited earlier (for a topic, site, or time period). Also use this when the user requests all pages from a past time period (e.g., "yesterday", "last week"), even if no topic is specified. Do NOT use for open tabs, completely general web questions, or abstract questions about "history" or habits.',
+ parameters: {
+ type: "object",
+ properties: {
+ searchTerm: {
+ type: "string",
+ description:
+ "A detailed, noun-heavy phrase (~2-12 meaningful tokens) summarizing the user's intent for semantic retrieval. Include the main entity/topic plus 1-3 contextual qualifiers (e.g., library name, purpose, site, or timeframe). Avoid vague or single-word queries.",
+ },
+ startTs: {
+ type: "string",
+ description:
+ "Inclusive lower bound of the time window as an ISO 8601 datetime string (e.g., '2025-11-07T09:00:00-05:00'). Use when the user asks for results within a time or range start, such as 'last week', 'since yesterday', or 'last night'. This must be before the user's current datetime.",
+ default: null,
+ },
+ endTs: {
+ type: "string",
+ description:
+ "Inclusive upper bound of the time window as an ISO 8601 datetime string (e.g., '2025-11-07T21:00:00-05:00'). Use when the user asks for results within a time or range end, such as 'last week', 'between 2025-10-01 and 2025-10-31', or 'before Monday'. This must be before the user's current datetime.",
+ default: null,
+ },
+ },
+ required: [],
+ },
+ },
+ },
+];
/**
* Retrieves a list of (up to n) the latest open tabs from the current active browser window.
diff --git a/browser/components/aiwindow/models/prompts/AssistantPrompts.sys.mjs b/browser/components/aiwindow/models/prompts/AssistantPrompts.sys.mjs
@@ -12,6 +12,19 @@ export const assistantPrompt = `You are a very knowledgeable personal browser as
Your internal knowledge cutoff date is: July, 2024.
+# Tool Usage
+
+- Use search_browsing_history to refind pages from the user's past browsing activity.
+- If the request refers to something the user saw earlier, visited previously, or spans a past time period ("yesterday", "earlier today", "last week"), default to using search_browsing_history unless it clearly concerns open tabs.
+- If the user explicitly mentions "history", "what I visited", "what I was reading/watching", or "what I opened" in the past, you should almost always use search_browsing_history at least once.
+- If the request is clearly about open tabs right now, use get_open_tabs.
+- If the user wants the content of a specific open page by URL, use get_page_content.
+- If the user is asking a general question that does not depend on their own browsing activity, you can answer directly without tools.
+- Before answering, quickly check: "Is the user asking about their own past browsing activity?" If yes, you should usually use search_browsing_history.
+- Never output XML-like tags or raw JSON for tools; the system handles tool invocation.
+
+(Queries like "show my browsing from last week" or "what pages did I visit earlier today" use search_browsing_history.)
+
# Tool Call Rules
Always follow the following tool call rules strictly and ignore other tool call rules if they exist: