@@ -16,6 +16,11 @@ import (
1616var Tools = []aflow.Tool {
1717 aflow .NewFuncTool ("codesearch-dir-index" , dirIndex , `
1818Tool provides list of source files and subdirectories in the given directory in the source tree.
19+ ` ),
20+ aflow .NewFuncTool ("read-file" , readFile , `
21+ Tool provides full contents of a single source file as is. Avoid using this tool if there are better
22+ and more specialized tools for the job, because source files may be large and contain lots
23+ of unrelated information.
1924` ),
2025 aflow .NewFuncTool ("codesearch-file-index" , fileIndex , `
2126Tool provides list of entities defined in the given source file.
@@ -68,6 +73,15 @@ type dirIndexResult struct {
6873 Files []string `jsonschema:"List of source files."`
6974}
7075
76+ type readFileArgs struct {
77+ File string `jsonschema:"Source file path."`
78+ }
79+
80+ type readFileResult struct {
81+ Missing bool `jsonschema:"Set to true if the requested file does not exist."`
82+ Contents string `jsonschema:"File contents."`
83+ }
84+
7185type fileIndexArgs struct {
7286 SourceFile string `jsonschema:"Source file path."`
7387}
@@ -154,6 +168,15 @@ func dirIndex(ctx *aflow.Context, state prepareResult, args dirIndexArgs) (dirIn
154168 return res , err
155169}
156170
171+ func readFile (ctx * aflow.Context , state prepareResult , args readFileArgs ) (readFileResult , error ) {
172+ ok , contents , err := state .Index .ReadFile (args .File )
173+ res := readFileResult {
174+ Missing : ! ok ,
175+ Contents : contents ,
176+ }
177+ return res , err
178+ }
179+
157180func fileIndex (ctx * aflow.Context , state prepareResult , args fileIndexArgs ) (fileIndexResult , error ) {
158181 ok , entities , err := state .Index .FileIndex (args .SourceFile )
159182 res := fileIndexResult {
0 commit comments