]> git.giacomolli.uk - onechat/blobdiff - agent.go
Define child agent areas and reporting rules
[onechat] / agent.go
index 3fc954672e9038e9c2a154ced280d419def63a0a..790e18be79c788140a6bf1944aba4e3c90c459ef 100644 (file)
--- a/agent.go
+++ b/agent.go
@@ -50,6 +50,7 @@ func openAgent(dir string) (*Agent, error) {
 
        decoder := json.NewDecoder(bytes.NewReader(data))
        decoder.DisallowUnknownFields()
+
        err = decoder.Decode(&config)
        if err == nil && !errors.Is(decoder.Decode(&struct{}{}), io.EOF) {
                err = errors.New("data after the JSON object")
@@ -95,6 +96,10 @@ func (a *Agent) Prompt() (string, error) {
                return "", fmt.Errorf("find instructions path: %w", err)
        }
 
+       if a.config.Parent != "" {
+               return promptChild(a.config.Name, a.config.Parent, a.config.Responsibility, path, instructions), nil
+       }
+
        return prompt(a.config.Name, path, instructions), nil
 }
 
@@ -124,13 +129,15 @@ func (a *Agent) instructions() (string, error) {
 // made once when the file is made, and never changes. The cache key comes from
 // the ID, so a rename keeps the prompt cache and two agents with one name do
 // not share a key. Workdir is the directory where the commands of the agent
-// run.
+// run. Responsibility and Parent are set together for a child agent.
 type AgentConfig struct {
-       Name    string `json:"name"`
-       ID      string `json:"id"`
-       Model   string `json:"model"`
-       Effort  string `json:"effort"`
-       Workdir string `json:"workdir"`
+       Name           string `json:"name"`
+       ID             string `json:"id"`
+       Model          string `json:"model"`
+       Effort         string `json:"effort"`
+       Workdir        string `json:"workdir"`
+       Responsibility string `json:"responsibility,omitempty"`
+       Parent         string `json:"parent,omitempty"`
 }
 
 // validate makes sure that each setting has a valid value.
@@ -148,6 +155,14 @@ func (c AgentConfig) validate() error {
                return errors.New("agent needs a model and an effort")
        }
 
+       if (strings.TrimSpace(c.Responsibility) == "") != (c.Parent == "") {
+               return errors.New("a child needs both responsibility and parent")
+       }
+
+       if strings.ContainsAny(c.Parent, "\r\n") {
+               return errors.New("parent must be one line of text")
+       }
+
        if !filepath.IsAbs(c.Workdir) {
                return fmt.Errorf("workdir %q is not an absolute path", c.Workdir)
        }