loop: preserve cumulative usage across conversation compaction
conversation: add optional CumulativeUsage parameter to New function
Update CompactConversation to preserve cumulative usage statistics when
resetting the conversation, preventing usage numbers from being lost during
compaction.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: s11dcb84790847494k
diff --git a/llm/conversation/convo.go b/llm/conversation/convo.go
index 95e4fba..f3161ed 100644
--- a/llm/conversation/convo.go
+++ b/llm/conversation/convo.go
@@ -117,13 +117,16 @@
// New creates a new conversation with Claude with sensible defaults.
// ctx is the context for the entire conversation.
-func New(ctx context.Context, srv llm.Service) *Convo {
+func New(ctx context.Context, srv llm.Service, usage *CumulativeUsage) *Convo {
id := newConvoID()
+ if usage == nil {
+ usage = newUsage()
+ }
return &Convo{
Ctx: skribe.ContextWithAttr(ctx, slog.String("convo_id", id)),
Service: srv,
PromptCaching: true,
- usage: newUsage(),
+ usage: usage,
Listener: &NoopListener{},
ID: id,
toolUseCancel: map[string]context.CancelCauseFunc{},