compactionContextLimit returns the context-window limit of the model that generates the summary: the dedicated compaction model when one is configured, otherwise the agent's own model. Returns 0 when it can't be resolved. Failure is non-fatal: a before_compaction hook may supply its own summary and
(ctx context.Context, a *agent.Agent)
| 171 | // pass the cloned summary-call provider so its provider_opts (which |
| 172 | // match the underlying model) are considered. |
| 173 | func (r *LocalRuntime) compactionContextLimit(ctx context.Context, a *agent.Agent) int64 { |
| 174 | if a == nil { |
| 175 | return 0 |
| 176 | } |
| 177 | model := a.CompactionModel() |
| 178 | if model == nil { |
| 179 | model = a.Model(ctx) |
| 180 | } |
| 181 | if model == nil { |
| 182 | return 0 |
| 183 | } |
| 184 | summaryModel := provider.CloneWithOptions(ctx, model, |
| 185 | options.WithStructuredOutput(nil), |
| 186 | options.WithMaxTokens(compactor.MaxSummaryTokens), |
| 187 | ) |
| 188 | return r.resolveContextLimit(ctx, summaryModel, summaryModel.ID()) |
| 189 | } |
| 190 | |
| 191 | // effectiveContextLimit returns the context budget the running session |
| 192 | // operates within: the primary model's window, capped by the dedicated |