* refactor: remove browser_close tool — auto-cleanup handles it
The browser_close tool was called in only 9% of browser sessions (13/144
navigations across 66 sessions), always redundantly — cleanup_browser()
already runs via _cleanup_task_resources() at conversation end, and the
background inactivity reaper catches anything else.
Removing it saves one tool schema slot in every browser-enabled API call.
Also fixes a latent bug: cleanup_browser() now handles Camofox sessions
too (previously only Browserbase). Camofox sessions were never auto-cleaned
per-task because they live in a separate dict from _active_sessions.
Files changed (13):
- tools/browser_tool.py: remove function, schema, registry entry; add
camofox cleanup to cleanup_browser()
- toolsets.py, model_tools.py, prompt_builder.py, display.py,
acp_adapter/tools.py: remove browser_close from all tool lists
- tests/: remove browser_close test, update toolset assertion
- docs/skills: remove all browser_close references
* fix: repeat browser_scroll 5x per call for meaningful page movement
Most backends scroll ~100px per call — barely visible on a typical
viewport. Repeating 5x gives ~500px (~half a viewport), making each
scroll tool call actually useful.
Backend-agnostic approach: works across all 7+ browser backends without
needing to configure each one's scroll amount individually. Breaks
early on error for the agent-browser path.
* feat: auto-return compact snapshot from browser_navigate
Every browser session starts with navigate → snapshot. Now navigate
returns the compact accessibility tree snapshot inline, saving one
tool call per browser task.
The snapshot captures the full page DOM (not viewport-limited), so
scroll position doesn't affect it. browser_snapshot remains available
for refreshing after interactions or getting full=true content.
Both Browserbase and Camofox paths auto-snapshot. If the snapshot
fails for any reason, navigation still succeeds — the snapshot is
a bonus, not a requirement.
Schema descriptions updated to guide models: navigate mentions it
returns a snapshot, snapshot mentions it's for refresh/full content.
* refactor: slim cronjob tool schema — consolidate model/provider, drop unused params
Session data (151 calls across 67 sessions) showed several schema
properties were never used by models. Consolidated and cleaned up:
Removed from schema (still work via backend/CLI):
- skill (singular): use skills array instead
- reason: pause-only, unnecessary
- include_disabled: now defaults to true
- base_url: extreme edge case, zero usage
- provider (standalone): merged into model object
Consolidated:
- model + provider → single 'model' object with {model, provider} fields.
If provider is omitted, the current main provider is pinned at creation
time so the job stays stable even if the user changes their default.
Kept:
- script: useful data collection feature
- skills array: standard interface for skill loading
Schema shrinks from 14 to 10 properties. All backend functionality
preserved — the Python function signature and handler lambda still
accept every parameter.
* fix: remove mixture_of_agents from core toolsets — opt-in only via hermes tools
MoA was in _HERMES_CORE_TOOLS and composite toolsets (hermes-cli,
hermes-messaging, safe), which meant it appeared in every session
for anyone with OPENROUTER_API_KEY set. The _DEFAULT_OFF_TOOLSETS
gate only works after running 'hermes tools' explicitly.
Now MoA only appears when a user explicitly enables it via
'hermes tools'. The moa toolset definition and check_fn remain
unchanged — it just needs to be opted into.
130 lines
5.4 KiB
Python
130 lines
5.4 KiB
Python
"""Tests for hermes-api-server toolset and API server tool availability."""
|
|
import os
|
|
import json
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
import pytest
|
|
|
|
from toolsets import resolve_toolset, get_toolset, validate_toolset
|
|
|
|
|
|
class TestHermesApiServerToolset:
|
|
"""Tests for the hermes-api-server toolset definition."""
|
|
|
|
def test_toolset_exists(self):
|
|
ts = get_toolset("hermes-api-server")
|
|
assert ts is not None
|
|
|
|
def test_toolset_validates(self):
|
|
assert validate_toolset("hermes-api-server")
|
|
|
|
def test_toolset_includes_web_tools(self):
|
|
tools = resolve_toolset("hermes-api-server")
|
|
assert "web_search" in tools
|
|
assert "web_extract" in tools
|
|
|
|
def test_toolset_includes_core_tools(self):
|
|
tools = resolve_toolset("hermes-api-server")
|
|
expected = [
|
|
"terminal", "process",
|
|
"read_file", "write_file", "patch", "search_files",
|
|
"vision_analyze", "image_generate",
|
|
"execute_code", "delegate_task",
|
|
"todo", "memory", "session_search", "cronjob",
|
|
]
|
|
for tool in expected:
|
|
assert tool in tools, f"Missing expected tool: {tool}"
|
|
|
|
def test_toolset_includes_browser_tools(self):
|
|
tools = resolve_toolset("hermes-api-server")
|
|
for tool in ["browser_navigate", "browser_snapshot", "browser_click",
|
|
"browser_type", "browser_scroll", "browser_back",
|
|
"browser_press"]:
|
|
assert tool in tools, f"Missing browser tool: {tool}"
|
|
|
|
def test_toolset_includes_homeassistant_tools(self):
|
|
tools = resolve_toolset("hermes-api-server")
|
|
for tool in ["ha_list_entities", "ha_get_state", "ha_list_services", "ha_call_service"]:
|
|
assert tool in tools, f"Missing HA tool: {tool}"
|
|
|
|
def test_toolset_excludes_clarify(self):
|
|
tools = resolve_toolset("hermes-api-server")
|
|
assert "clarify" not in tools
|
|
|
|
def test_toolset_excludes_send_message(self):
|
|
tools = resolve_toolset("hermes-api-server")
|
|
assert "send_message" not in tools
|
|
|
|
def test_toolset_excludes_text_to_speech(self):
|
|
tools = resolve_toolset("hermes-api-server")
|
|
assert "text_to_speech" not in tools
|
|
|
|
|
|
class TestApiServerPlatformConfig:
|
|
def test_platforms_dict_includes_api_server(self):
|
|
from hermes_cli.tools_config import PLATFORMS
|
|
assert "api_server" in PLATFORMS
|
|
assert PLATFORMS["api_server"]["default_toolset"] == "hermes-api-server"
|
|
|
|
|
|
class TestApiServerAdapterToolset:
|
|
@patch("gateway.platforms.api_server.AIOHTTP_AVAILABLE", True)
|
|
def test_create_agent_reads_config_toolsets(self):
|
|
"""API server resolves toolsets from config like all other platforms."""
|
|
from gateway.platforms.api_server import APIServerAdapter
|
|
from gateway.config import PlatformConfig
|
|
|
|
adapter = APIServerAdapter(PlatformConfig())
|
|
|
|
with patch("gateway.run._resolve_runtime_agent_kwargs") as mock_kwargs, \
|
|
patch("gateway.run._resolve_gateway_model") as mock_model, \
|
|
patch("gateway.run._load_gateway_config") as mock_config, \
|
|
patch("run_agent.AIAgent") as mock_agent_cls:
|
|
|
|
mock_kwargs.return_value = {"api_key": "test-key", "base_url": None,
|
|
"provider": None, "api_mode": None,
|
|
"command": None, "args": []}
|
|
mock_model.return_value = "test/model"
|
|
# No platform_toolsets override — should fall back to hermes-api-server default
|
|
mock_config.return_value = {}
|
|
mock_agent_cls.return_value = MagicMock()
|
|
|
|
adapter._create_agent()
|
|
|
|
mock_agent_cls.assert_called_once()
|
|
call_kwargs = mock_agent_cls.call_args
|
|
toolsets = call_kwargs.kwargs.get("enabled_toolsets")
|
|
assert isinstance(toolsets, list)
|
|
assert len(toolsets) > 0
|
|
assert call_kwargs.kwargs.get("platform") == "api_server"
|
|
|
|
@patch("gateway.platforms.api_server.AIOHTTP_AVAILABLE", True)
|
|
def test_create_agent_respects_config_override(self):
|
|
"""User can override API server toolsets via platform_toolsets in config.yaml."""
|
|
from gateway.platforms.api_server import APIServerAdapter
|
|
from gateway.config import PlatformConfig
|
|
|
|
adapter = APIServerAdapter(PlatformConfig())
|
|
|
|
with patch("gateway.run._resolve_runtime_agent_kwargs") as mock_kwargs, \
|
|
patch("gateway.run._resolve_gateway_model") as mock_model, \
|
|
patch("gateway.run._load_gateway_config") as mock_config, \
|
|
patch("run_agent.AIAgent") as mock_agent_cls:
|
|
|
|
mock_kwargs.return_value = {"api_key": "test-key", "base_url": None,
|
|
"provider": None, "api_mode": None,
|
|
"command": None, "args": []}
|
|
mock_model.return_value = "test/model"
|
|
# User overrides with just web and terminal
|
|
mock_config.return_value = {
|
|
"platform_toolsets": {"api_server": ["web", "terminal"]}
|
|
}
|
|
mock_agent_cls.return_value = MagicMock()
|
|
|
|
adapter._create_agent()
|
|
|
|
mock_agent_cls.assert_called_once()
|
|
call_kwargs = mock_agent_cls.call_args
|
|
toolsets = call_kwargs.kwargs.get("enabled_toolsets")
|
|
assert sorted(toolsets) == ["terminal", "web"]
|