commit 01b0bdb668b05fe24eb81ff3e5a230ac129d7cee
parent 894075a8526492de8a6035d100b70eceb2e49ad4
Author: Tom Zhang <tzhang@mozilla.com>
Date: Mon, 22 Dec 2025 16:14:34 +0000
Bug 2006507 - Hook up actual tools r=ai-models-reviewers,tburrell
Temporarily changed logic to only execute the first tool call returned until parallel tool call is implemented.
Differential Revision: https://phabricator.services.mozilla.com/D276926
Diffstat:
3 files changed, 39 insertions(+), 7 deletions(-)
diff --git a/browser/base/content/test/static/browser_all_files_referenced.js b/browser/base/content/test/static/browser_all_files_referenced.js
@@ -347,10 +347,6 @@ var allowlist = [
{
file: "moz-src:///browser/components/aiwindow/models/prompts/AssistantPrompts.sys.mjs",
},
- // Bug 2002638 - Move search browsing history to AI-window r?mardak (backed out due to unused file)
- {
- file: "moz-src:///browser/components/aiwindow/models/Tools.sys.mjs",
- },
// Bug 2004888 - [FirstRun] Create Firstrun.html opening firstrun welcome screen
{
file: "chrome://browser/content/aiwindow/firstrun.html",
diff --git a/browser/components/aiwindow/models/Chat.sys.mjs b/browser/components/aiwindow/models/Chat.sys.mjs
@@ -11,12 +11,22 @@ import {
OAUTH_CLIENT_ID,
SCOPE_PROFILE,
} from "resource://gre/modules/FxAccountsCommon.sys.mjs";
+import {
+ toolsConfig,
+ getOpenTabs,
+ searchBrowsingHistory,
+ GetPageContent,
+} from "moz-src:///browser/components/aiwindow/models/Tools.sys.mjs";
/**
* Chat
*/
export const Chat = {
- toolMap: {}, // TODO can import toolMap
+ toolMap: {
+ get_open_tabs: getOpenTabs,
+ search_browsing_history: searchBrowsingHistory,
+ get_page_content: GetPageContent.getPageContent.bind(GetPageContent),
+ },
async _getFxAccountToken() {
try {
@@ -57,7 +67,7 @@ export const Chat = {
streamOptions: { enabled: true },
fxAccountToken,
tool_choice: "auto",
- // tools: Add your tools configuration here,
+ tools: toolsConfig,
args: convo,
});
@@ -84,9 +94,13 @@ export const Chat = {
}
// 3) Build the assistant tool_calls message exactly as expected by the API
+ // Bug 2006159 - Implement parallel tool calling
+ // TODO: Temporarily only include the first tool call due to quality issue
+ // with subsequent tool call responses, will include all later once above
+ // ticket is resolved.
const assistantToolMsg = {
role: "assistant",
- tool_calls: pendingToolCalls.map(toolCall => ({
+ tool_calls: pendingToolCalls.slice(0, 1).map(toolCall => ({
id: toolCall.id,
type: "function",
function: {
@@ -97,6 +111,7 @@ export const Chat = {
};
// 4) Execute each tool locally and create a tool message with the result
+ // TODO: Temporarily only execute the first tool call, will run all later
const toolResultMessages = [];
for (const toolCall of pendingToolCalls) {
const { id, function: functionSpec } = toolCall;
@@ -146,6 +161,9 @@ export const Chat = {
tool_call_id: id,
content: typeof result === "string" ? result : JSON.stringify(result),
});
+
+ // Bug 2006159 - Implement parallel tool calling, remove after implemented
+ break;
}
convo = [...convo, assistantToolMsg, ...toolResultMessages];
diff --git a/browser/components/aiwindow/models/tests/xpcshell/test_Chat.js b/browser/components/aiwindow/models/tests/xpcshell/test_Chat.js
@@ -26,6 +26,24 @@ registerCleanupFunction(() => {
}
});
+add_task(async function test_Chat_real_tools_are_registered() {
+ Assert.strictEqual(
+ typeof Chat.toolMap.get_open_tabs,
+ "function",
+ "get_open_tabs should be registered in toolMap"
+ );
+ Assert.strictEqual(
+ typeof Chat.toolMap.search_browsing_history,
+ "function",
+ "search_browsing_history should be registered in toolMap"
+ );
+ Assert.strictEqual(
+ typeof Chat.toolMap.get_page_content,
+ "function",
+ "get_page_content should be registered in toolMap"
+ );
+});
+
add_task(async function test_openAIEngine_build_uses_prefs() {
Services.prefs.setStringPref(PREF_API_KEY, "test-key-123");
Services.prefs.setStringPref(PREF_ENDPOINT, "https://example.test/v1");