32 lines
995 B
Go
32 lines
995 B
Go
package runtime
|
|
|
|
// materialBudgetState describes only usage returned by the provider for a
|
|
// material subagent. A response with no reported usage cannot authorize a
|
|
// further request.
|
|
type materialBudgetState struct {
|
|
Limit, Used, LastPrompt, OutputCap, SavedCheckpoints, Responses int
|
|
UsageKnown bool
|
|
}
|
|
|
|
// materialFinalDecision reserves room for an answer before allowing another
|
|
// checkpoint request. It is deliberately an estimate, not a billing limit for
|
|
// an already in-flight request.
|
|
func materialFinalDecision(s materialBudgetState) (finalOnly, stop bool) {
|
|
if s.Responses == 0 {
|
|
return false, false
|
|
}
|
|
if !s.UsageKnown {
|
|
return false, true
|
|
}
|
|
margin := s.LastPrompt / 4
|
|
if margin < 1024 {
|
|
margin = 1024
|
|
}
|
|
remaining := s.Limit - s.Used
|
|
if remaining <= s.LastPrompt+margin {
|
|
return false, true
|
|
}
|
|
reserve := s.LastPrompt + s.OutputCap + margin
|
|
return s.SavedCheckpoints >= 2 || remaining <= 2*reserve, false
|
|
}
|