]> git.giacomolli.uk - onechat/blobdiff - tools.go
Parse cron expressions and find the next time
[onechat] / tools.go
index 5329446ff4b3d0ef8627fd7a13140853fb25c360..7640dee9f3ff18c7ecfa456967c3621239cd370c 100644 (file)
--- a/tools.go
+++ b/tools.go
@@ -50,10 +50,15 @@ type ToolChat interface {
 // 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. Zoom with a name reads the log of a subagent.
 // 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. Zoom with a name reads the log of a subagent.
+// The toolbox of the agent has the runs of its subagents for spawn and tell,
+// and the WhatsApp link for the WhatsApp tools. The toolbox of a subagent has
+// neither, so these are unknown tools there.
 type Toolbox struct {
        log       ToolLog
        chat      ToolChat
        subagents *Subagents
 type Toolbox struct {
        log       ToolLog
        chat      ToolChat
        subagents *Subagents
+       runs      *SubagentRuns
+       whatsapp  *WhatsApp
        workdir   string
 }
 
        workdir   string
 }
 
@@ -130,6 +135,42 @@ func (b *Toolbox) run(ctx context.Context, name, arguments string) string {
                if err == nil {
                        output, err = b.edit(args.Path, args.Old, args.New)
                }
                if err == nil {
                        output, err = b.edit(args.Path, args.Old, args.New)
                }
+       case "spawn":
+               var args ToolSpawnArguments
+               err = toolDecodeArguments(arguments, &args)
+               switch {
+               case b.runs == nil:
+                       err = fmt.Errorf("unknown tool %q", name)
+               case err == nil:
+                       output, err = b.runs.Spawn(ctx, args.Tasks, args.Effort)
+               }
+       case "tell":
+               var args ToolTellArguments
+               err = toolDecodeArguments(arguments, &args)
+               switch {
+               case b.runs == nil:
+                       err = fmt.Errorf("unknown tool %q", name)
+               case err == nil:
+                       output, err = b.runs.Tell(ctx, args.Name, args.Message)
+               }
+       case "whatsapp_find":
+               var args ToolWhatsAppFindArguments
+               err = toolDecodeArguments(arguments, &args)
+               switch {
+               case b.whatsapp == nil:
+                       err = fmt.Errorf("unknown tool %q", name)
+               case err == nil:
+                       output, err = b.whatsapp.Find(ctx, args.Name)
+               }
+       case "whatsapp_send":
+               var args ToolWhatsAppSendArguments
+               err = toolDecodeArguments(arguments, &args)
+               switch {
+               case b.whatsapp == nil:
+                       err = fmt.Errorf("unknown tool %q", name)
+               case err == nil:
+                       output, err = b.whatsapp.Send(ctx, args.ID, args.Chat, args.Text)
+               }
        default:
                err = fmt.Errorf("unknown tool %q", name)
        }
        default:
                err = fmt.Errorf("unknown tool %q", name)
        }
@@ -358,6 +399,31 @@ type ToolEditArguments struct {
        New  string `json:"new"`
 }
 
        New  string `json:"new"`
 }
 
+// ToolSpawnArguments are the arguments of spawn. A nil Effort is the effort of
+// the agent.
+type ToolSpawnArguments struct {
+       Tasks  []string `json:"tasks"`
+       Effort *string  `json:"effort"`
+}
+
+// ToolTellArguments are the arguments of tell.
+type ToolTellArguments struct {
+       Name    string `json:"name"`
+       Message string `json:"message"`
+}
+
+// ToolWhatsAppFindArguments are the arguments of whatsapp_find.
+type ToolWhatsAppFindArguments struct {
+       Name string `json:"name"`
+}
+
+// ToolWhatsAppSendArguments are the arguments of whatsapp_send.
+type ToolWhatsAppSendArguments struct {
+       ID   string `json:"id"`
+       Chat string `json:"chat"`
+       Text string `json:"text"`
+}
+
 // ToolHeadTail keeps the first and the last toolClipBytes bytes written to it,
 // and counts the bytes between them that it drops.
 type ToolHeadTail struct {
 // ToolHeadTail keeps the first and the last toolClipBytes bytes written to it,
 // and counts the bytes between them that it drops.
 type ToolHeadTail struct {