]> git.giacomolli.uk - onechat/blobdiff - rebuild.go
Keep each schedule with its owning agent
[onechat] / rebuild.go
index 52c0861eabfac5463057319bba263a80755bd295..11c6bfcc536d1fbff9eef1d0d7c9a83412e5410c 100644 (file)
@@ -7,7 +7,7 @@ import (
        "fmt"
        "io"
        "io/fs"
        "fmt"
        "io"
        "io/fs"
-       "log"
+       "log/slog"
        "os"
        "path/filepath"
        "slices"
        "os"
        "path/filepath"
        "slices"
@@ -15,6 +15,11 @@ import (
        "time"
 )
 
        "time"
 )
 
+// rebuildCallLimit is the most model calls of a rebuild. A rebuild summarizes
+// the whole merged log, which can need more calls than a probe sample, and the
+// quota stop of the build run still guards the account.
+const rebuildCallLimit = 1500
+
 // rebuild merges added messages with the log of agent, in date order, and
 // builds a new memory beside it. The caller holds the token lock. The model
 // uses the original agent prompt and cache key. A failed or stopped build
 // rebuild merges added messages with the log of agent, in date order, and
 // builds a new memory beside it. The caller holds the token lock. The model
 // uses the original agent prompt and cache key. A failed or stopped build
@@ -50,12 +55,12 @@ func rebuild(ctx context.Context, agent *Agent, added []DatedMessage, client *Mo
                }
        }()
 
                }
        }()
 
-       memory, err := openMemory(ctx, root, time.Now, summarizer, log.New(io.Discard, "", 0))
+       memory, err := openMemory(ctx, root, time.Now, summarizer, slog.New(slog.DiscardHandler))
        if err != nil {
                return "", fmt.Errorf("open rebuilt memory: %w", err)
        }
 
        if err != nil {
                return "", fmt.Errorf("open rebuilt memory: %w", err)
        }
 
-       client.LimitCalls(buildCallLimit)
+       client.LimitCalls(rebuildCallLimit)
 
        run := BuildRun{
                memory:    memory,
 
        run := BuildRun{
                memory:    memory,