mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-29 06:31:32 +00:00
refactor(browser): dispatch _get_cloud_provider through agent.browser_registry
Switches tools.browser_tool's cloud-provider lookup from the hardcoded _PROVIDER_REGISTRY class-instantiation pattern to the agent.browser_registry singleton registry that plugins self-populate. Changes: - tools/browser_tool.py top imports: pull BrowserProvider from agent.browser_provider (re-exported as CloudBrowserProvider for legacy callers) and the three provider classes from plugins/browser/<vendor>/. Legacy class names (BrowserbaseProvider, BrowserUseProvider, FirecrawlProvider) remain on tools.browser_tool as re-export shims so existing test patches (monkeypatch.setattr(browser_tool, 'BrowserUseProvider', ...)) keep working. - _get_cloud_provider() now consults agent.browser_registry.get_provider() for explicit-config lookups. The auto-detect fallback still uses BrowserUseProvider() / BrowserbaseProvider() at the module level so the cache-policy test fixtures (which patch those names) keep driving the function. Test-time _PROVIDER_REGISTRY overrides are detected by class identity and routed through the legacy factory-call path. - agent/browser_provider.py: BrowserProvider grows is_configured() and provider_name() as thin backward-compat aliases for the legacy CloudBrowserProvider API. Subclasses MUST implement is_available() and name; the aliases delegate. This keeps ~6 caller sites in browser_tool.py working without churning them. - tests/tools/test_managed_browserbase_and_modal.py: _install_fake_tools_package grows stubs for agent.browser_provider / agent.browser_registry / plugins.browser.<vendor>.provider so the test's spec-loader path (sys.modules-reset + reload-tool-from-disk) can satisfy tools.browser_tool's top-level imports. Verified: all 23 existing tests in test_browser_cloud_*.py + test_managed_browserbase_and_modal.py still pass post-cutover. The legacy tools/browser_providers/ directory is NOT yet deleted; several tests still _load_tool_module() those files via spec_from_file_location. The deletion + test-path updates land in a later commit.
This commit is contained in:
parent
a15cdfb050
commit
40fde853fa
3 changed files with 147 additions and 10 deletions
|
|
@ -76,6 +76,49 @@ def _install_fake_tools_package():
|
|||
call_llm=lambda *args, **kwargs: "",
|
||||
)
|
||||
|
||||
# Stubs for the browser-provider plugin layer introduced in PR #25214.
|
||||
# The fake `agent` package has an empty __path__ so real submodules
|
||||
# aren't reachable; we install just enough stand-ins to satisfy
|
||||
# ``tools.browser_tool``'s top-level imports. The actual lifecycle
|
||||
# tests instantiate the real plugin classes via _load_tool_module
|
||||
# below, so the stubs only need to satisfy import + isinstance.
|
||||
class _StubBrowserProvider:
|
||||
"""Minimal BrowserProvider stub for ``from agent.browser_provider import BrowserProvider``."""
|
||||
|
||||
sys.modules["agent.browser_provider"] = types.SimpleNamespace(
|
||||
BrowserProvider=_StubBrowserProvider,
|
||||
)
|
||||
sys.modules["agent.browser_registry"] = types.SimpleNamespace(
|
||||
get_active_browser_provider=lambda: None,
|
||||
get_provider=lambda name: None,
|
||||
list_providers=lambda: [],
|
||||
register_provider=lambda provider: None,
|
||||
_resolve=lambda configured: None,
|
||||
)
|
||||
|
||||
# Plugin module stubs — the real plugin classes are loaded from disk by
|
||||
# the lifecycle tests below via _load_tool_module(). For the import
|
||||
# phase, we just need the class names to exist on the right module path.
|
||||
plugins_package = types.ModuleType("plugins")
|
||||
plugins_package.__path__ = [] # type: ignore[attr-defined]
|
||||
sys.modules["plugins"] = plugins_package
|
||||
plugins_browser_package = types.ModuleType("plugins.browser")
|
||||
plugins_browser_package.__path__ = [] # type: ignore[attr-defined]
|
||||
sys.modules["plugins.browser"] = plugins_browser_package
|
||||
|
||||
for _name, _classname in (
|
||||
("browserbase", "BrowserbaseBrowserProvider"),
|
||||
("browser_use", "BrowserUseBrowserProvider"),
|
||||
("firecrawl", "FirecrawlBrowserProvider"),
|
||||
):
|
||||
_vendor_pkg = types.ModuleType(f"plugins.browser.{_name}")
|
||||
_vendor_pkg.__path__ = [] # type: ignore[attr-defined]
|
||||
sys.modules[f"plugins.browser.{_name}"] = _vendor_pkg
|
||||
_provider_stub_cls = type(_classname, (_StubBrowserProvider,), {})
|
||||
sys.modules[f"plugins.browser.{_name}.provider"] = types.SimpleNamespace(
|
||||
**{_classname: _provider_stub_cls},
|
||||
)
|
||||
|
||||
sys.modules["tools.managed_tool_gateway"] = _load_tool_module(
|
||||
"tools.managed_tool_gateway",
|
||||
"managed_tool_gateway.py",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue