11import { z } from 'zod' ;
22import { zodToJsonSchema } from 'zod-to-json-schema' ;
33
4- import { getDefaultSystemPrompt } from '../../core/toolAgent/index.js' ;
54import { getModel } from '../../core/toolAgent/config.js' ;
5+ import { getDefaultSystemPrompt } from '../../core/toolAgent/index.js' ;
66import { toolAgent } from '../../core/toolAgent.js' ;
77import { Tool , ToolContext } from '../../core/types.js' ;
88import { getTools } from '../getTools.js' ;
@@ -18,23 +18,14 @@ const parameterSchema = z.object({
1818 projectContext : z
1919 . string ( )
2020 . describe ( 'Context about the problem or environment' ) ,
21- fileContext : z
22- . object ( {
23- workingDirectory : z
24- . string ( )
25- . optional ( )
26- . describe ( 'The directory where the sub-agent should operate' ) ,
27- relevantFiles : z
28- . string ( )
29- . optional ( )
30- . describe (
31- 'A list of files, which may include ** or * wildcard characters' ,
32- ) ,
33- } )
34- . describe (
35- 'When working with files and directories, it is best to be very specific to avoid sub-agents making incorrect assumptions' ,
36- )
37- . optional ( ) ,
21+ workingDirectory : z
22+ . string ( )
23+ . optional ( )
24+ . describe ( 'The directory where the sub-agent should operate' ) ,
25+ relevantFilesDirectories : z
26+ . string ( )
27+ . optional ( )
28+ . describe ( 'A list of files, which may include ** or * wildcard characters' ) ,
3829} ) ;
3930
4031const returnSchema = z . object ( {
@@ -77,25 +68,22 @@ export const subAgentTool: Tool<Parameters, ReturnType> = {
7768 returnsJsonSchema : zodToJsonSchema ( returnSchema ) ,
7869 execute : async ( params , context ) => {
7970 // Validate parameters
80- const { description, goal, projectContext, fileContext } =
81- parameterSchema . parse ( params ) ;
71+ const {
72+ description,
73+ goal,
74+ projectContext,
75+ workingDirectory,
76+ relevantFilesDirectories,
77+ } = parameterSchema . parse ( params ) ;
8278
8379 // Construct a well-structured prompt
8480 const prompt = [
8581 `Description: ${ description } ` ,
8682 `Goal: ${ goal } ` ,
8783 `Project Context: ${ projectContext } ` ,
88- fileContext
89- ? `\nContext:\n${ [
90- fileContext . workingDirectory
91- ? `- Working Directory: ${ fileContext . workingDirectory } `
92- : '' ,
93- fileContext . relevantFiles
94- ? `- Relevant Files:\n ${ fileContext . relevantFiles } `
95- : '' ,
96- ]
97- . filter ( Boolean )
98- . join ( '\n' ) } `
84+ workingDirectory ? `Working Directory: ${ workingDirectory } ` : '' ,
85+ relevantFilesDirectories
86+ ? `Relevant Files:\n ${ relevantFilesDirectories } `
9987 : '' ,
10088 ]
10189 . filter ( Boolean )
@@ -110,8 +98,7 @@ export const subAgentTool: Tool<Parameters, ReturnType> = {
11098
11199 const result = await toolAgent ( prompt , tools , config , {
112100 ...context ,
113- workingDirectory :
114- fileContext ?. workingDirectory ?? context . workingDirectory ,
101+ workingDirectory : workingDirectory ?? context . workingDirectory ,
115102 } ) ;
116103 return { response : result . result } ;
117104 } ,
0 commit comments