@@ -185,7 +185,7 @@ func (s *interactiveState) createAgent() (*adk.ChatModelAgent, error) {
185185 s .summCapture .Capture (summary .Content , contextN )
186186 config .Logger ().Printf ("[summarization] Finalize: compacted %d context messages" , contextN )
187187 if s .agentTokenUsage != nil {
188- s .agentTokenUsage .Reset ()
188+ s .agentTokenUsage .ResetContext ()
189189 }
190190 return append (systemMsgs , summary ), nil
191191 },
@@ -228,7 +228,8 @@ func (s *interactiveState) createAgent() (*adk.ChatModelAgent, error) {
228228 if s .cfg .Budget != nil {
229229 providerName , modelName := s .cfg .GetProviderModel ()
230230 inputPer1M , outputPer1M := s .registry .GetModelCost (providerName , modelName )
231- pricing := internalmodel.ModelPricing {InputPer1M : inputPer1M , OutputPer1M : outputPer1M }
231+ cacheReadPer1M , _ := s .registry .GetModelCacheCost (providerName , modelName )
232+ pricing := internalmodel.ModelPricing {InputPer1M : inputPer1M , OutputPer1M : outputPer1M , CacheReadPer1M : cacheReadPer1M }
232233 budgetManager := agent .NewBudgetManager (s .cfg .Budget , pricing )
233234 budgetMw := agent .NewBudgetMiddleware (budgetManager , s .agentTokenUsage , func (status agent.BudgetStatus ) {
234235 config .Logger ().Printf ("[budget] warning level=%d cost=%.4f" , status .WarningLevel , status .EstimatedCost )
@@ -240,7 +241,7 @@ func (s *interactiveState) createAgent() (*adk.ChatModelAgent, error) {
240241 compactionStrategy := agent .NewThresholdCompactionStrategy (compactThreshold , s .chatModel , 6 )
241242 compactionMw := agent .NewCompactionMiddleware (compactionStrategy , contextLimit , s .agentTokenUsage , func (savedTokens int ) {
242243 if s .agentTokenUsage != nil {
243- s .agentTokenUsage .Reset ()
244+ s .agentTokenUsage .ResetContext ()
244245 }
245246 if s .p != nil {
246247 s .p .Send (tui.CompactDoneMsg {OldTokens : 0 , NewTokens : 0 })
@@ -318,7 +319,7 @@ func (s *interactiveState) applyModeSwitch(newMode tui.AgentMode) {
318319 config .Logger ().Printf ("[plan] agent creation failed: %v" , err )
319320 }
320321 if s .agentTokenUsage != nil {
321- s .agentTokenUsage .Reset ()
322+ s .agentTokenUsage .ResetContext ()
322323 }
323324 // Sync the TUI mode pill with the resulting unified mode (covers the
324325 // plan-completion revert to Normal, which the user did not trigger directly).
@@ -592,6 +593,10 @@ func (s *interactiveState) handleConfig(cfgMsg *config.Config) {
592593 return
593594 }
594595 s .chatModel = newChatModel
596+ // Attribute subsequent usage to the newly selected model.
597+ if s .rec != nil {
598+ s .rec .SetModel (newModelName )
599+ }
595600
596601 // Rebuild system prompt and tools to reflect config changes (e.g., SSH aliases)
597602 if s .agentMode == tui .ModePlanning {
@@ -622,7 +627,7 @@ func (s *interactiveState) handleCompact() {
622627 s .rec .RecordCompact (s .history [0 ].Content , oldLen - len (s .history ))
623628 }
624629 if s .agentTokenUsage != nil {
625- s .agentTokenUsage .Reset ()
630+ s .agentTokenUsage .ResetContext ()
626631 }
627632 s .p .Send (tui.CompactDoneMsg {
628633 OldTokens : oldTokens ,
@@ -665,6 +670,9 @@ func (s *interactiveState) handleAddModel() {
665670 return
666671 }
667672 s .chatModel = newChatModel
673+ if s .rec != nil {
674+ s .rec .SetModel (newModelName )
675+ }
668676 if newAg , agErr := s .createAgent (); agErr == nil {
669677 s .ag = newAg
670678 }
0 commit comments