The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): keep the caller's positional/keyword split when restoring hosted arguments
Tekniumbeb769985f8d
diff --git a/hermes_cli/plugin_host_wire.py b/hermes_cli/plugin_host_wire.pyindex dd1125dcbb1..f59b0631cfa 100644--- a/hermes_cli/plugin_host_wire.py+++ b/hermes_cli/plugin_host_wire.py@@ -218,20 +218,22 @@ def declared_return(cls: type, name: str) -> Any:def restore_arguments(fn: Optional[Callable[..., Any]], args: list, kwargs: dict) -> tuple[list, dict]:"""``args``/``kwargs`` for a call to the unbound method ``fn``, each rebuilt as its declared- parameter type; unchanged when the call does not bind to ``fn``'s signature."""+ parameter type. Positional stays positional and keyword stays keyword: the plugin's override may+ take ``**kwargs`` where the ABC names the parameter."""if fn is None:return args, kwargstry:hints = typing.get_type_hints(fn)- signature = inspect.signature(fn)- bound = signature.bind(None, *args, **kwargs) # None stands in for ``self``+ params = list(inspect.signature(fn).parameters.values())[1:] # drop ``self``except (NameError, TypeError, ValueError, AttributeError):return args, kwargs- variadic = (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD)- for name, value in bound.arguments.items():- if signature.parameters[name].kind not in variadic:- bound.arguments[name] = restore(value, hints.get(name))- return list(bound.args[1:]), dict(bound.kwargs)+ by_position = [p.name for p in params+ if p.kind in (inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.POSITIONAL_OR_KEYWORD)]+ restored = [restore(value, hints.get(name)) for value, name in zip(args, by_position)]+ restored += list(args[len(restored):])+ by_name = {p.name for p in params+ if p.kind in (inspect.Parameter.POSITIONAL_OR_KEYWORD, inspect.Parameter.KEYWORD_ONLY)}+ return restored, {k: restore(v, hints.get(k)) if k in by_name else v for k, v in kwargs.items()}def is_async_callable(fn: Any) -> bool:diff --git a/tests/hermes_cli/test_plugin_host_return_types.py b/tests/hermes_cli/test_plugin_host_return_types.pyindex 2c2a8813884..24237e4523f 100644--- a/tests/hermes_cli/test_plugin_host_return_types.py+++ b/tests/hermes_cli/test_plugin_host_return_types.py@@ -136,7 +136,8 @@ class Ledger(ContextEngine):def should_compress(self, prompt_tokens=None):return Falsedef compress(self, messages, current_tokens=None, **kw):- return messages+ self.compress_options = {"current_tokens": current_tokens, **kw}+ return messages[-1:]def register(ctx):ctx.register_context_engine(Ledger())@@ -145,7 +146,9 @@ def register(ctx):@pytest.mark.platforms("any")def test_hosted_context_engine_clone_is_an_independent_engine(tmp_path, monkeypatch):+ from types import SimpleNamespacefrom agent.context_engine import ContextEngine+ from agent.conversation_compression import _resolve_compress_call_home_with_plugin(tmp_path, monkeypatch, "hostledger", CONTEXT_ENGINE_PLUGIN)manager = _load("hostledger")@@ -156,5 +159,13 @@ def test_hosted_context_engine_clone_is_an_independent_engine(tmp_path, monkeypaclone.update_from_response({"prompt_tokens": 1234})assert clone.last_prompt_tokens == 1234assert shared.last_prompt_tokens == 0 # the agent's budget state is its own++ # Core passes the options by keyword; an override taking **kw must receive them as keywords.+ compress, options = _resolve_compress_call(+ SimpleNamespace(context_compressor=clone), approx_tokens=900, focus_topic="auth", force=True,+ memory_context="", bypass_cooldown=False)+ messages = [{"role": "user", "content": "one"}, {"role": "user", "content": "two"}]+ assert compress(messages, **options) == messages[-1:]+ assert clone.compress_options == {"current_tokens": 900, "focus_topic": "auth", "force": True}finally:_shutdown(manager)