X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/4343ca5fb6cc86eb887951f4fe16063bab29a238..2a528fe2981639cf099c713a6be16b8ea0e2cc67:/compactor.go diff --git a/compactor.go b/compactor.go index 2b23901..2b06288 100644 --- a/compactor.go +++ b/compactor.go @@ -15,20 +15,6 @@ const compactorTries = 5 // bytes, and a sample line as the ruler gets its content copied. var compactorRuler = strings.Repeat("-", nodeBytes) -// 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. tools are the tools of that agent, so a build sends the same prompt -// and tools as its turns. -func newCompactor(client *ModelClient, instructions func() (string, error), model ModelConfig, tools []ModelTool, images *ImageStore) *Compactor { - return &Compactor{ - client: client, - model: model, - instructions: instructions, - tools: tools, - images: images, - } -} - // Compactor builds the nodes of one agent with a model. A compaction is a call // like a turn, with the same system prompt and tools, so it reads them from the // prompt cache of the turns. The tools are never called. After them comes one @@ -52,16 +38,30 @@ type Compactor struct { images *ImageStore } +// 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. tools are the tools of that agent, so a build sends the same prompt +// and tools as its turns. +func newCompactor(client *ModelClient, instructions func() (string, error), model ModelConfig, tools []ModelTool, images *ImageStore) *Compactor { + return &Compactor{ + client: client, + model: model, + instructions: instructions, + tools: tools, + images: images, + } +} + // Summarize returns the line of the node of task. func (c *Compactor) Summarize(ctx context.Context, task Task) (string, error) { text, err := compactorTask(task) if err != nil { - return "", err + return "", fmt.Errorf("prepare compaction task: %w", err) } instructions, err := c.instructions() if err != nil { - return "", err + return "", fmt.Errorf("read compaction instructions: %w", err) } source := task.Context + "\n" + text @@ -110,7 +110,11 @@ func (c *Compactor) Summarize(ctx context.Context, task Task) (string, error) { } if len(lines) == 0 { - return "", err + if err != nil { + return "", fmt.Errorf("summarize node: %w", err) + } + + return "", nil } return compactorShortest(lines), nil @@ -125,6 +129,7 @@ func compactorTask(task Task) (string, error) { %s `, task.Index, nodeBytes, compactorRuler, task.Input[0]) + if len(task.Images) > 0 { text += "\nKeep each [image FILE] name and describe its kind, visible text, amounts, names, and context." }