]> git.giacomolli.uk - onechat/blobdiff - tools.go
Store the subagents and read them with zoom
[onechat] / tools.go
index af500baf0af43c5be067dcb05f3adc8b13de6c86..5329446ff4b3d0ef8627fd7a13140853fb25c360 100644 (file)
--- a/tools.go
+++ b/tools.go
@@ -49,11 +49,12 @@ type ToolChat interface {
 // the log as it happens: the call as a tool message, the result as an echo
 // message. The call is durable before its tool runs, so the log never misses an
 // action outside the agent. Commands and files run as the user in the working
 // the log as it happens: the call as a tool message, the result as an echo
 // message. The call is durable before its tool runs, so the log never misses an
 // action outside the agent. Commands and files run as the user in the working
-// directory, with no sandbox.
+// directory, with no sandbox. Zoom with a name reads the log of a subagent.
 type Toolbox struct {
 type Toolbox struct {
-       log     ToolLog
-       chat    ToolChat
-       workdir string
+       log       ToolLog
+       chat      ToolChat
+       subagents *Subagents
+       workdir   string
 }
 
 // Call logs the call of the tool name with its JSON arguments, makes the log
 }
 
 // Call logs the call of the tool name with its JSON arguments, makes the log
@@ -92,7 +93,11 @@ func (b *Toolbox) run(ctx context.Context, name, arguments string) string {
        case "zoom":
                var args ToolZoomArguments
                err = toolDecodeArguments(arguments, &args)
        case "zoom":
                var args ToolZoomArguments
                err = toolDecodeArguments(arguments, &args)
-               if err == nil {
+               switch {
+               case err != nil:
+               case args.Name != nil:
+                       output, err = b.zoomAgent(ctx, *args.Name)
+               default:
                        output, err = b.zoom(args.ID, args.N)
                }
        case "date":
                        output, err = b.zoom(args.ID, args.N)
                }
        case "date":
@@ -136,6 +141,16 @@ func (b *Toolbox) run(ctx context.Context, name, arguments string) string {
        return output
 }
 
        return output
 }
 
+// zoomAgent returns the whole log of the subagent name.
+func (b *Toolbox) zoomAgent(ctx context.Context, name string) (string, error) {
+       subagent, err := b.subagents.Get(ctx, name)
+       if err != nil {
+               return "", err
+       }
+
+       return subagent.Show()
+}
+
 // zoom returns message id whole for n = 1, or else the two lines under the line
 // id+n.
 func (b *Toolbox) zoom(id, n int) (string, error) {
 // zoom returns message id whole for n = 1, or else the two lines under the line
 // id+n.
 func (b *Toolbox) zoom(id, n int) (string, error) {
@@ -307,10 +322,12 @@ func (b *Toolbox) path(path string) string {
        return filepath.Join(b.workdir, path)
 }
 
        return filepath.Join(b.workdir, path)
 }
 
-// ToolZoomArguments are the arguments of zoom.
+// ToolZoomArguments are the arguments of zoom. A Name that is not nil names
+// the subagent whose whole log zoom gives, and then ID and N are not used.
 type ToolZoomArguments struct {
 type ToolZoomArguments struct {
-       ID int `json:"id"`
-       N  int `json:"n"`
+       ID   int     `json:"id"`
+       N    int     `json:"n"`
+       Name *string `json:"name"`
 }
 
 // ToolDateArguments are the arguments of date.
 }
 
 // ToolDateArguments are the arguments of date.