Skip to content

Commit 8211af9

Browse files
committed
fix: mutate tool in place to preserve provider metadata
1 parent 14b16ed commit 8211af9

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/common/utils/tools/tools.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Tool, tool } from "ai";
1+
import { type Tool } from "ai";
22
import { createFileReadTool } from "@/node/services/tools/file_read";
33
import { createBashTool } from "@/node/services/tools/bash";
44
import { createFileEditReplaceStringTool } from "@/node/services/tools/file_edit_replace_string";
@@ -38,10 +38,11 @@ export type ToolFactory = (config: ToolConfiguration) => Tool;
3838

3939
/**
4040
* Augment a tool's description with additional instructions from "Tool: <name>" sections
41-
* Creates a wrapper tool that delegates to the base tool but with an enhanced description.
41+
* Mutates the base tool in place to append the instructions to its description.
42+
* This preserves any provider-specific metadata or internal state on the tool object.
4243
* @param baseTool The original tool to augment
4344
* @param additionalInstructions Additional instructions to append to the description
44-
* @returns A new tool with the augmented description
45+
* @returns The same tool instance with the augmented description
4546
*/
4647
function augmentToolDescription(baseTool: Tool, additionalInstructions: string): Tool {
4748
// Access the tool as a record to get its properties
@@ -51,14 +52,10 @@ function augmentToolDescription(baseTool: Tool, additionalInstructions: string):
5152
typeof baseToolRecord.description === "string" ? baseToolRecord.description : "";
5253
const augmentedDescription = `${originalDescription}\n\n${additionalInstructions}`;
5354

54-
// Return a new tool with the augmented description
55-
return tool({
56-
description: augmentedDescription,
57-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
58-
inputSchema: baseToolRecord.inputSchema as any,
59-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
60-
execute: baseToolRecord.execute as any,
61-
});
55+
// Mutate the description in place to preserve other properties (e.g. provider metadata)
56+
baseToolRecord.description = augmentedDescription;
57+
58+
return baseTool;
6259
}
6360

6461
/**

0 commit comments

Comments
 (0)