]> git.giacomolli.uk - onechat/blobdiff - compactor.go
Give each agent a config and user instructions
[onechat] / compactor.go
index ac5fd1d56541e416e981c013cbe20f289afb281a..e899c094ee58ad0036cdd7443fac632a9b903df9 100644 (file)
@@ -30,17 +30,18 @@ var ruler = strings.Repeat("-", nodeBytes)
 type Compactor struct {
        client       *Client
        model        ModelConfig
-       instructions string
+       instructions func() (string, error)
        tools        []Tool
 }
 
-// newCompactor returns the compactor of the agent name, which sends its calls
-// through client with model.
-func newCompactor(client *Client, name string, model ModelConfig) *Compactor {
+// newCompactor returns the compactor of an agent, which sends its calls through
+// client with model. instructions gives the system prompt of the agent at each
+// build, so a build sends the same prompt as the turns of that time.
+func newCompactor(client *Client, instructions func() (string, error), model ModelConfig) *Compactor {
        return &Compactor{
                client:       client,
                model:        model,
-               instructions: prompt(name),
+               instructions: instructions,
                tools:        agentTools(),
        }
 }
@@ -53,6 +54,11 @@ func (c *Compactor) Summarize(ctx context.Context, task Task) (string, error) {
                return "", err
        }
 
+       instructions, err := c.instructions()
+       if err != nil {
+               return "", fmt.Errorf("compact node (%d, %d): %w", task.Level, task.Index, err)
+       }
+
        var lines []string
        note := ""
        for len(lines) < compactionTries {
@@ -65,9 +71,10 @@ func (c *Compactor) Summarize(ctx context.Context, task Task) (string, error) {
                response, err = c.client.Create(ctx, Request{
                        Model:        c.model.Model,
                        Effort:       c.model.Effort,
-                       Instructions: c.instructions,
+                       Instructions: instructions,
                        Tools:        c.tools,
                        Input:        []any{userMessage(parts...)},
+                       Node:         &nodeKey{task.Level, task.Index},
                })
                if err != nil {
                        break