commit 3ef513152eeba70f727d780959a658fe0495d188
parent a71a17c837d036576a7ce75ae3469887fdb77297
Author: Tom Zhang <tzhang@mozilla.com>
Date: Fri, 19 Dec 2025 18:18:16 +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:
2 files changed, 39 insertions(+), 3 deletions(-)
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");