mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-02 07:11:49 +00:00
fix: expose context engine tools with saved toolsets
This commit is contained in:
parent
1a9ef83147
commit
8595281f3c
4 changed files with 116 additions and 0 deletions
|
|
@ -26,6 +26,17 @@ class _StubEngine(ContextEngine):
|
|||
return messages
|
||||
|
||||
|
||||
class _ToolEngine(_StubEngine):
|
||||
def get_tool_schemas(self):
|
||||
return [
|
||||
{
|
||||
"name": "stub_recover",
|
||||
"description": "Recover context from the stub engine.",
|
||||
"parameters": {"type": "object", "properties": {}},
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_plugin_engine_gets_context_length_on_init():
|
||||
"""Plugin context engine should have context_length set during AIAgent init."""
|
||||
engine = _StubEngine()
|
||||
|
|
@ -56,6 +67,46 @@ def test_plugin_engine_gets_context_length_on_init():
|
|||
assert engine.threshold_tokens == int(204_800 * engine.threshold_percent)
|
||||
|
||||
|
||||
def test_active_context_engine_tools_survive_explicit_platform_toolsets():
|
||||
"""LCM-style recovery tools must survive saved `hermes tools` lists."""
|
||||
engine = _ToolEngine()
|
||||
cfg = {
|
||||
"context": {"engine": "stub"},
|
||||
"platform_toolsets": {"cli": ["web", "terminal"]},
|
||||
"agent": {},
|
||||
}
|
||||
|
||||
from hermes_cli.tools_config import _get_platform_tools
|
||||
|
||||
enabled_toolsets = _get_platform_tools(cfg, "cli", include_default_mcp_servers=False)
|
||||
assert "context_engine" in enabled_toolsets
|
||||
|
||||
with (
|
||||
patch("hermes_cli.config.load_config", return_value=cfg),
|
||||
patch("plugins.context_engine.load_context_engine", return_value=engine),
|
||||
patch("agent.model_metadata.get_model_context_length", return_value=204_800),
|
||||
patch("run_agent.get_tool_definitions", return_value=[]),
|
||||
patch("run_agent.check_toolset_requirements", return_value={}),
|
||||
patch("run_agent.OpenAI"),
|
||||
):
|
||||
from run_agent import AIAgent
|
||||
|
||||
agent = AIAgent(
|
||||
api_key="test-key-1234567890",
|
||||
base_url="https://openrouter.ai/api/v1",
|
||||
enabled_toolsets=sorted(enabled_toolsets),
|
||||
quiet_mode=True,
|
||||
skip_context_files=True,
|
||||
skip_memory=True,
|
||||
)
|
||||
|
||||
assert "stub_recover" in getattr(agent, "valid_tool_names", set())
|
||||
assert "stub_recover" in {
|
||||
tool.get("function", {}).get("name")
|
||||
for tool in getattr(agent, "tools", [])
|
||||
}
|
||||
|
||||
|
||||
def test_plugin_engine_update_model_args():
|
||||
"""Verify update_model() receives model, context_length, base_url, api_key, provider."""
|
||||
engine = _StubEngine()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue