aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools/FileContentTool.ts
diff options
context:
space:
mode:
authorJoanne <zehan_ding@brown.edu>2025-06-17 13:02:50 -0400
committerJoanne <zehan_ding@brown.edu>2025-06-17 13:02:50 -0400
commit2aa2c26b95a539d220e46b20cdfbef6ae39d6c43 (patch)
tree344a6f798f692fdd4921ab5a6762e907f5ad7b06 /src/client/views/nodes/chatbot/tools/FileContentTool.ts
parent430db63077868fa54829721d6530a810aa4d4588 (diff)
parentccfdf905400cd4b81d8cde0f16bb0e15cd65621b (diff)
Merge branch 'agent-paper-main' of https://github.com/brown-dash/Dash-Web into joanne-tutorialagent
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/FileContentTool.ts')
-rw-r--r--src/client/views/nodes/chatbot/tools/FileContentTool.ts78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/client/views/nodes/chatbot/tools/FileContentTool.ts b/src/client/views/nodes/chatbot/tools/FileContentTool.ts
new file mode 100644
index 000000000..f994aab67
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/FileContentTool.ts
@@ -0,0 +1,78 @@
+import { Observation } from '../types/types';
+import { ParametersType, ToolInfo } from '../types/tool_types';
+import { Vectorstore } from '../vectorstore/Vectorstore';
+import { BaseTool } from './BaseTool';
+
+const fileContentToolParams = [
+ {
+ name: 'filepaths',
+ type: 'string[]',
+ description: 'Array of file paths to retrieve content for. Limited to a maximum of 3 files.',
+ required: true,
+ },
+] as const;
+
+type FileContentToolParamsType = typeof fileContentToolParams;
+
+const fileContentToolInfo: ToolInfo<FileContentToolParamsType> = {
+ name: 'fileContent',
+ description: 'Retrieves the complete content of up to 3 specified files from the Dash codebase to help understand implementation details.',
+ citationRules: `When using the FileContentTool:
+1. Present file content clearly with proper code formatting
+2. Include the file path at the beginning of each file's content
+3. Use this tool after identifying relevant files with the CodebaseSummarySearchTool
+4. Maximum of 3 files can be retrieved at once`,
+ parameterRules: fileContentToolParams,
+};
+
+export class FileContentTool extends BaseTool<FileContentToolParamsType> {
+ constructor(private vectorstore: Vectorstore) {
+ super(fileContentToolInfo);
+ }
+
+ async execute(args: ParametersType<FileContentToolParamsType>): Promise<Observation[]> {
+ console.log(`Executing file content retrieval for: ${args.filepaths.join(', ')}`);
+
+ // Enforce the limit of 3 files
+ const filepaths = args.filepaths.slice(0, 3);
+ if (args.filepaths.length > 3) {
+ console.warn(`FileContentTool: Request for ${args.filepaths.length} files was limited to 3`);
+ }
+
+ const observations: Observation[] = [];
+
+ if (filepaths.length === 0) {
+ return [
+ {
+ type: 'text',
+ text: 'No filepaths provided. Please specify at least one file path to retrieve content.',
+ },
+ ];
+ }
+
+ // Add initial message
+ observations.push({
+ type: 'text',
+ text: `Retrieving content for ${filepaths.length} file(s):\n\n`,
+ });
+
+ // Fetch content for each file
+ for (const filepath of filepaths) {
+ const content = await this.vectorstore.getFileContent(filepath);
+
+ if (content) {
+ observations.push({
+ type: 'text',
+ text: `File: ${filepath}\n\n\`\`\`\n${content}\n\`\`\`\n\n`,
+ });
+ } else {
+ observations.push({
+ type: 'text',
+ text: `Error: Could not retrieve content for file "${filepath}"\n\n`,
+ });
+ }
+ }
+
+ return observations;
+ }
+}