Skip to content

Centralize model-change TUI notification in the main loop#2044

Draft
dgageot wants to merge 1 commit intodocker:mainfrom
dgageot:board/each-time-i-have-a-feature-that-enables-28a6003f
Draft

Centralize model-change TUI notification in the main loop#2044
dgageot wants to merge 1 commit intodocker:mainfrom
dgageot:board/each-time-i-have-a-feature-that-enables-28a6003f

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Mar 10, 2026

Problem

Every feature that switches models (routing, alloy, fallback, model picker, per-tool overrides…) had to manually emit an AgentInfo event to update the TUI sidebar. This was scattered across 6+ call sites and easy to forget when adding new features.

Solution

Add a change-detection mechanism in RunStream: a lastEmittedModelID variable and emitModelInfo closure that automatically emits AgentInfo only when the effective model actually changes. Called before and after each LLM call, it covers all model-switching features uniformly.

Changes

  • loop.go: Replace 3 scattered manual AgentInfo emissions with emitModelInfo calls
  • model_picker.go: Remove AgentInfo emission from tool handler; rename setModelAndEmitInfosetCurrentAgentModel
  • agent_delegation.go: Use getEffectiveModelID instead of getAgentModelID so agent-switch events reflect active fallback cooldowns

Any future model-switching feature no longer needs to worry about TUI notification — the loop handles it automatically.

@dgageot dgageot requested a review from a team as a code owner March 10, 2026 17:33
docker-agent[bot]

This comment was marked as outdated.

Add a change-detection mechanism (lastEmittedModelID + emitModelInfo
closure) in RunStream that automatically emits AgentInfo only when the
effective model actually changes. This is checked before and after each
LLM call, covering per-tool overrides, fallback, model picker, cooldowns,
and any future model-switching feature — without each one having to
remember to notify the TUI.

- loop.go: replace 3 scattered manual AgentInfo emissions with
  emitModelInfo calls driven by the closure
- model_picker.go: remove AgentInfo emission from the tool handler;
  rename setModelAndEmitInfo to setCurrentAgentModel (no longer emits)
- agent_delegation.go: use getEffectiveModelID instead of getAgentModelID
  so agent-switch events reflect active fallback cooldowns

Assisted-By: docker-agent
@dgageot dgageot force-pushed the board/each-time-i-have-a-feature-that-enables-28a6003f branch from 5ca63ba to ad2a2bc Compare March 11, 2026 08:36
@dgageot dgageot marked this pull request as draft March 11, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants