Skip to content

Commit 2cf2a74

Browse files
committed
implement glob limiting in tool
1 parent 73818bb commit 2cf2a74

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

core/tools/definitions/globSearch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export const globSearchTool: Tool = {
1212
group: BUILT_IN_GROUP_NAME,
1313
function: {
1414
name: BuiltInToolNames.FileGlobSearch,
15-
description: "Search for files in the project",
15+
description:
16+
"Search for files in the project. Output may be truncated; use targeted patterns",
1617
parameters: {
1718
type: "object",
1819
required: ["pattern"],
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
import { ToolImpl } from ".";
2+
import { ContextItem } from "../..";
23

4+
const MAX_AGENT_GLOB_RESULTS = 100;
35
export const fileGlobSearchImpl: ToolImpl = async (args, extras) => {
4-
const results = await extras.ide.getFileResults(args.pattern);
5-
return [
6+
const results = await extras.ide.getFileResults(
7+
args.pattern,
8+
MAX_AGENT_GLOB_RESULTS,
9+
);
10+
const contextItems: ContextItem[] = [
611
{
712
name: "File results",
813
description: "Results from file glob search",
914
content: results.join("\n"),
1015
},
1116
];
17+
18+
// In case of truncation, add a warning
19+
if (results.length === MAX_AGENT_GLOB_RESULTS) {
20+
contextItems.push({
21+
name: "Truncation warning",
22+
description: "Inform the model that results were truncated",
23+
content: `Warning: the results above were truncated to the first ${MAX_AGENT_GLOB_RESULTS} files. If the results are not satisfactory, refine your search pattern`,
24+
});
25+
}
26+
27+
return contextItems;
1228
};

0 commit comments

Comments
 (0)