X-Git-Url: http://git.giacomolli.uk/onechat/blobdiff_plain/d647f33b3e70f9419f6c0740e1d01b210439a519..a4cfb030bf949e2fc9cd0ddace9e33f24b791b18:/compactor.go?ds=inline diff --git a/compactor.go b/compactor.go index 16303b0..71d72c1 100644 --- a/compactor.go +++ b/compactor.go @@ -28,20 +28,21 @@ var ruler = strings.Repeat("-", nodeBytes) // because the view measures the real sizes. A call that fails before any line // fails the build, and the core tries it again at the next message. type Compactor struct { - client *Client + client *ModelClient model ModelConfig - instructions string - tools []Tool + instructions func() (string, error) + tools []ModelTool } -// 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 *ModelClient, instructions func() (string, error), model ModelConfig) *Compactor { return &Compactor{ client: client, model: model, - instructions: prompt(name), - tools: agentTools(), + instructions: instructions, + tools: promptTools(), } } @@ -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 { @@ -61,13 +67,13 @@ func (c *Compactor) Summarize(ctx context.Context, task Task) (string, error) { parts = append(parts, note) } - var response Response - response, err = c.client.Create(ctx, Request{ + var response ModelResponse + response, err = c.client.Create(ctx, ModelRequest{ Model: c.model.Model, Effort: c.model.Effort, - Instructions: c.instructions, + Instructions: instructions, Tools: c.tools, - Input: []any{userMessage(parts...)}, + Input: []any{modelUserMessage(parts...)}, Node: &nodeKey{task.Level, task.Index}, }) if err != nil {