Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion agent/auxiliary_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4226,9 +4226,17 @@ def _finalize(resolved_provider: str, sync_client: Any, default_model: Optional[
main_provider,
)
else:
# Bridge the runtime credentials recorded by set_runtime_main()
# into the resolver, mirroring _resolve_auto() (#35259). A
# custom:<name> main provider is flattened to bare "custom" with
# its base_url/api_key carried on the live runtime; without this
# bridge resolve_provider_client("custom", ...) finds no endpoint
# credentials and the whole vision chain returns None.
rpc_client, rpc_model = resolve_provider_client(
main_provider, vision_model,
api_mode=resolved_api_mode,
explicit_base_url=_RUNTIME_MAIN_BASE_URL or None,
explicit_api_key=_RUNTIME_MAIN_API_KEY or None,
api_mode=resolved_api_mode or (_RUNTIME_MAIN_API_MODE or None),
is_vision=True)
if rpc_client is not None:
logger.info(
Expand Down
41 changes: 41 additions & 0 deletions tests/agent/test_set_runtime_main_custom_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,44 @@ def test_named_custom_with_config_entry_still_routes(self, tmp_path, monkeypatch
assert base and base.rstrip("/") == "https://withcfg.example/v1"
finally:
mod.clear_runtime_main()


class TestResolveVisionUsesRuntimeGlobals:
"""Vision auto-detect must bridge the same runtime globals as _resolve_auto.

Regression for the sibling gap of #35259: set_runtime_main() records a
custom:<name> main provider as bare "custom" plus base_url/api_key, but
resolve_vision_provider_client()'s auto branch did not forward those
credentials, so vision_analyze failed with
"No LLM provider configured for task=vision provider=auto".
"""

def test_vision_auto_forwards_runtime_credentials(self):
"""The vision auto branch passes explicit_base_url/api_key/api_mode
from the runtime globals to resolve_provider_client."""
import agent.auxiliary_client as mod

mod.clear_runtime_main()
try:
mod.set_runtime_main(
"custom",
"claude-opus-4-7",
base_url="https://gateway.example.com/v1",
api_key="sk-vision-123",
api_mode="anthropic_messages",
)

with patch.object(mod, "resolve_provider_client") as mock_resolve, \
patch.object(mod, "_main_model_supports_vision", return_value=True):
mock_resolve.return_value = (MagicMock(), "claude-opus-4-7")
provider, client, _model = mod.resolve_vision_provider_client(provider="auto")

assert client is not None
mock_resolve.assert_called_once()
kwargs = mock_resolve.call_args[1]
assert kwargs["explicit_base_url"] == "https://gateway.example.com/v1"
assert kwargs["explicit_api_key"] == "sk-vision-123"
assert kwargs["api_mode"] == "anthropic_messages"
assert kwargs["is_vision"] is True
finally:
mod.clear_runtime_main()