Skip to content

fix(auxiliary): resolve provider/model from live runtime, not stale config#19485

Open
hunterlarcuad wants to merge 1 commit into
NousResearch:mainfrom
hunterlarcuad:fix/auxiliary-runtime-override
Open

fix(auxiliary): resolve provider/model from live runtime, not stale config#19485
hunterlarcuad wants to merge 1 commit into
NousResearch:mainfrom
hunterlarcuad:fix/auxiliary-runtime-override

Conversation

@hunterlarcuad

Copy link
Copy Markdown

Problem

Auxiliary tasks (context compression, summarization, memory flush, vision analysis) resolve their LLM provider/model independently from the main conversation loop. The main loop uses request_client constructed from self._client_kwargs (live runtime). Auxiliary paths read from config.yaml (stale until restart).

Impact: When a user switches models mid-session via /model, the main loop immediately uses the new model, but all auxiliary tasks continue using the old model from config.yaml until the agent restarts.

Root Cause

Dual source-of-truth:

  • Main loop: reads self.provider / self.model / self._client_kwargs — live
  • Auxiliary paths: _resolve_task_provider_model() -> config.yaml — stale

Fix: Active Runtime Resolver

Changes (agent/auxiliary_client.py, +91/-8)

  1. Thread-local carrier (_AGENT_RUNTIME_TLS) — Module-level threading.local with set/get/clear_agent_runtime_override() helpers. Tool handlers without an AIAgent reference (e.g. browser_tool.py vision) automatically pick up the active runtime.

  2. _resolve_task_provider_model() gains runtime_override kwarg — New Step 3 in priority chain:

    • Explicit provider/model/base_url/api_key args (always win)
    • Config file (auxiliary.{task}.provider/model)
    • Runtime override from active AIAgent (new)
    • "auto" chain (fallback)
  3. resolve_vision_provider_client() accepts main_runtime — Forwards runtime_override=main_runtime to resolution. Vision auto-fallback path uses _normalize_main_runtime(main_runtime) before _read_main_provider/model().

  4. call_llm() vision path forwards main_runtime — Both primary and fallback resolve_vision_provider_client() calls include it.

  5. get_text_auxiliary_client() / get_async_text_auxiliary_client() merge TLS via _effective_override(main_runtime) helper.

Changes (run_agent.py, +8)

  1. TLS set in run_conversation() entryset_agent_runtime_override(self._current_main_runtime()) right after set_session_context(). Follows same pattern (set per-call, overwritten next call, thread-local dies with thread).

Backward Compatibility

  • All new parameters are keyword-only with None default
  • Existing callers work unchanged
  • No new dependencies

Test Results

266 passed, 4 skipped, 0 failures (auxiliary + compression_feasibility)
1 error (unrelated: test_kanban_dashboard_plugin missing fastapi)

Fixes #19437

…onfig

Auxiliary tasks (compression, summarization, memory flush, vision)
independently resolved their LLM provider/model from config.yaml,
ignoring mid-session model switches (e.g. /model command).

Root cause: dual source-of-truth — main loop reads from
self._client_kwargs (live), auxiliary paths read from config.yaml
(stale until restart).

Fix: Active Runtime Resolver pattern
- Add thread-local carrier (_AGENT_RUNTIME_TLS) so tool handlers
  without a direct AIAgent reference (e.g. browser_tool.py vision)
  automatically pick up the active runtime.
- Add runtime_override parameter to _resolve_task_provider_model()\  as Step 3 in priority chain (explicit args → config → runtime → auto).
- Wire main_runtime through resolve_vision_provider_client() and
  call_llm() vision fallback path.
- Merge TLS into get_text_auxiliary_client() /\  get_async_text_auxiliary_client().
- Set TLS in run_conversation() entry (follows set_session_context
  pattern).

All existing callers work unchanged (keyword-only params, None default).
266 tests pass, 0 failures related to this change.

Fixes NousResearch#19437
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists labels May 4, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #19437 (issue) and #19470 (partial fix for vision path). This PR is a more comprehensive fix covering all auxiliary paths (compression, summarization, memory flush) via TLS carrier, not just vision.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #19437 (issue) and #19470 (partial fix for vision path). This PR is a more comprehensive fix covering all auxiliary paths via TLS carrier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auxiliary client uses independent resolution path, diverges from main conversation loop

2 participants