]> git.giacomolli.uk - onechat/blobdiff - prompt.go
Run the tools of an agent and log each call
[onechat] / prompt.go
index e48c5a61b714350b61dc3bcca68b025c40b05383..b536a36d9658722969d477bd936ad176f1e69b2c 100644 (file)
--- a/prompt.go
+++ b/prompt.go
@@ -123,9 +123,9 @@ func prompt(name, instructions string) string {
        return text + instructionsHeading + instructions
 }
 
        return text + instructionsHeading + instructions
 }
 
-// agentTools returns the function tools of every call: zoom and date. A
-// compaction sends them too and never calls them, because a change of the
-// tools ends the shared prompt cache.
+// agentTools returns the function tools of every call: zoom, date, shell,
+// read, write, and edit. A compaction sends them too and never calls them,
+// because a change of the tools ends the shared prompt cache.
 func agentTools() []Tool {
        return []Tool{
                {
 func agentTools() []Tool {
        return []Tool{
                {
@@ -147,6 +147,45 @@ func agentTools() []Tool {
                        }),
                        Strict: true,
                },
                        }),
                        Strict: true,
                },
+               {
+                       Type:        "function",
+                       Name:        "shell",
+                       Description: "Run a command with bash, as the user, in the working directory, with no input. Gives its output and error output, and its exit status when it fails.",
+                       Parameters: objectSchema(map[string]any{
+                               "command": stringSchema("The bash command."),
+                       }),
+                       Strict: true,
+               },
+               {
+                       Type:        "function",
+                       Name:        "read",
+                       Description: "Read a text file.",
+                       Parameters: objectSchema(map[string]any{
+                               "path": stringSchema("The file, absolute or relative to the working directory."),
+                       }),
+                       Strict: true,
+               },
+               {
+                       Type:        "function",
+                       Name:        "write",
+                       Description: "Write a text file whole, replacing it when it exists. Makes the missing directories.",
+                       Parameters: objectSchema(map[string]any{
+                               "path": stringSchema("The file, absolute or relative to the working directory."),
+                               "text": stringSchema("The whole new content."),
+                       }),
+                       Strict: true,
+               },
+               {
+                       Type:        "function",
+                       Name:        "edit",
+                       Description: "Replace the one occurrence of old in a text file with new.",
+                       Parameters: objectSchema(map[string]any{
+                               "path": stringSchema("The file, absolute or relative to the working directory."),
+                               "old":  stringSchema("The exact text to replace. It must occur once in the file."),
+                               "new":  stringSchema("The text that replaces old."),
+                       }),
+                       Strict: true,
+               },
        }
 }
 
        }
 }
 
@@ -175,3 +214,11 @@ func integerSchema(description string) map[string]any {
                "description": description,
        }
 }
                "description": description,
        }
 }
+
+// stringSchema returns the JSON schema of a string.
+func stringSchema(description string) map[string]any {
+       return map[string]any{
+               "type":        "string",
+               "description": description,
+       }
+}