返回 DeepSeek-Reasonix
compact_summary_feedback.go
根目录 / internal / agent / compact_summary_feedback.go
1 package agent
2
3 import "reasonix/internal/provider"
4
5 // observeSummaryOutcome feeds a cache-aligned summary request's real token
6 // count back into prompt calibration. A provider overflow carries the exact
7 // prompt size the estimator missed, and a clean single-request success carries
8 // the same measurement for the history mix; the sampling path never sees
9 // either, so without this the next fold plan repeats the same misestimate.
10 func (a *Agent) observeSummaryOutcome(req provider.Request, usage *provider.Usage, err error) {
11 if a == nil {
12 return
13 }
14 if limit := provider.AsContextLimitError(err); limit != nil {
15 if limit.PromptTokens > 0 {
16 a.setPromptTokenCalibration(limit.PromptTokens, a.requestCalibrationShape(req))
17 }
18 if limit.WindowTokens > 0 {
19 a.learnContextBudget(limit.WindowTokens, 0, false)
20 }
21 return
22 }
23 if err != nil || usage == nil || usage.Estimated || usage.Unknown || usage.RequestCount > 1 {
24 return
25 }
26 if prompt := usage.LatestPromptTokens(); prompt > 0 {
27 a.setPromptTokenCalibration(prompt, a.requestCalibrationShape(req))
28 }
29 }
30
30 lines GO