feat(summarization): add ReusePromptCaching option#1132
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha/10 #1132 +/- ##
===========================================
Coverage ? 81.67%
===========================================
Files ? 188
Lines ? 30554
Branches ? 0
===========================================
Hits ? 24956
Misses ? 3793
Partials ? 1805 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
f3eb202 to
5f672d4
Compare
shentongmartin
approved these changes
Jul 6, 2026
5f672d4 to
31b3077
Compare
Allow the summarization middleware to reuse the main conversation's cached prompt instead of rebuilding a fresh input, avoiding a full prompt-cache invalidation on every summarize call.
31b3077 to
67a3c27
Compare
shentongmartin
approved these changes
Jul 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The summarization middleware always rebuilds a fresh model input (
[innerSysInstruction, contextMessages..., userInstruction]) on every trigger, which fully invalidates the main conversation's cached prompt on the provider side. This change adds aReusePromptCachingoption so callers can opt into reusing that cache for the summarize call instead.API Changes
TypedConfig.ReusePromptCaching bool(and itsConfigalias). When enabled, the summarization input becomes[sysMsg, userMsg1, assistantMsg1, ..., userInstruction]— the original message history is kept byte-identical and only the user instruction is appended — and the summarize call additionally passesmodel.WithTools(state.ToolInfos)and, when set,model.WithDeferredTools(state.DeferredToolInfos), so the full tool envelope matches the main conversation's and the cache is preserved. Has no effect whenGenModelInputis set.Key Changes
ReusePromptCaching, there is a small chance it calls a tool instead of producing a summary directly — it's recommended to also configureRetryorFailoverwhen enabling this option.summarize/runFailovernow thread the state'sToolInfosandDeferredToolInfosthrough to the model options builder so both the primary and failover calls apply the same cache-preserving options.