@@ -143,6 +143,9 @@ type CompactionResult struct {
143143 // PersistedStep.Runtime). Zero when the run was gated off before
144144 // calling the model.
145145 Runtime time.Duration
146+ // ProviderResponseID identifies the summary response. See
147+ // PersistedStep.ProviderResponseID.
148+ ProviderResponseID string
146149}
147150
148151// GenerateCompaction generates one context summary and returns it without
@@ -207,7 +210,7 @@ func GenerateCompaction(ctx context.Context, opts GenerateCompactionOptions) (Co
207210 if opts .OnModelStreamStart != nil {
208211 opts .OnModelStreamStart ()
209212 }
210- summary , err := generateCompactionSummary (ctx , opts .Model , opts .Messages , config )
213+ summary , responseID , err := generateCompactionSummary (ctx , opts .Model , opts .Messages , config )
211214 if err != nil {
212215 publishCompactionError (config , "failed to generate compaction summary" )
213216 return CompactionResult {}, err
@@ -222,13 +225,14 @@ func GenerateCompaction(ctx context.Context, opts GenerateCompactionOptions) (Co
222225 SystemSummary : strings .TrimSpace (
223226 config .SystemSummaryPrefix + "\n \n " + summary ,
224227 ),
225- SummaryReport : summary ,
226- Source : config .Source ,
227- ThresholdPercent : config .ThresholdPercent ,
228- UsagePercent : usagePercent ,
229- ContextTokens : contextTokens ,
230- ContextLimit : contextLimit ,
231- Runtime : summaryRuntime ,
228+ SummaryReport : summary ,
229+ Source : config .Source ,
230+ ThresholdPercent : config .ThresholdPercent ,
231+ UsagePercent : usagePercent ,
232+ ContextTokens : contextTokens ,
233+ ContextLimit : contextLimit ,
234+ Runtime : summaryRuntime ,
235+ ProviderResponseID : responseID ,
232236 }
233237 result .EstimatedContextTokens = int64 ((len (result .SystemSummary ) + bytesPerTokenEstimate - 1 ) / bytesPerTokenEstimate )
234238 if config .PublishMessagePart != nil && config .ToolCallID != "" {
@@ -481,7 +485,7 @@ func generateCompactionSummary(
481485 model fantasy.LanguageModel ,
482486 messages []fantasy.Message ,
483487 options CompactionOptions ,
484- ) (summary string , err error ) {
488+ ) (summary string , responseID string , err error ) {
485489 summaryPrompt := make ([]fantasy.Message , 0 , len (messages )+ 1 )
486490 summaryPrompt = append (summaryPrompt , messages ... )
487491 summaryParts := []fantasy.MessagePart {fantasy.TextPart {Text : options .SummaryPrompt }}
@@ -575,6 +579,7 @@ func generateCompactionSummary(
575579 case fantasy .StreamPartTypeFinish :
576580 finishSeen = true
577581 finishReason = part .FinishReason
582+ responseID = providerResponseID (part )
578583 case fantasy .StreamPartTypeError :
579584 streamErr = part .Error
580585 if streamErr == nil {
@@ -626,7 +631,7 @@ func generateCompactionSummary(
626631 call .Tools = nil
627632 summary , err = streamSummaryText ()
628633 }
629- return summary , err
634+ return summary , responseID , err
630635}
631636
632637// contextTooLargePhrases are context-window rejections fantasy does not
0 commit comments