The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(plugins): let auxiliary tasks inherit a base slot at read time
Apostol Apostolovbe3f0fcc1cf7
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 8728a4377a9..fcc56a6928e 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -6269,9 +6269,14 @@ _DEFAULT_AUX_TIMEOUT = 30.0_COMPRESSION_TIMEOUT_FLOOR_SECONDS = 300.0-def _get_auxiliary_task_config(task: str) -> Dict[str, Any]:+def _get_auxiliary_task_config(+ task: str, _seen: Optional[frozenset] = None,+) -> Dict[str, Any]:"""Config dict for auxiliary.<task>, or {} when unavailable. Plugin-registered tasks get their- declared defaults layered under user config (user wins); built-in defaults live in DEFAULT_CONFIG."""+ declared defaults layered under user config (user wins); built-in defaults live in DEFAULT_CONFIG.+ A task registered with ``inherit_from`` also inherits the base task's effective config, resolved+ here at read time so it tracks the base's current settings; precedence is base, then plugin+ defaults, then user config. ``_seen`` is the recursion guard for hand-edited inheritance cycles."""if not task:return {}try:@@ -6283,13 +6288,24 @@ def _get_auxiliary_task_config(task: str) -> Dict[str, Any]:task_config = aux.get(task, {}) if isinstance(aux, dict) else {}if not isinstance(task_config, dict):task_config = {}+ seen = _seen or frozenset()+ # A cycle here means a hand-edited or otherwise malformed registry; fall back to this task's+ # own defaults instead of recursing until the stack blows.+ cyclic = task in seen+ if cyclic:+ logger.warning("Auxiliary task %r has a circular inherit_from chain — ignoring inheritance",+ task)try:from hermes_cli.plugins import get_plugin_auxiliary_tasksfor _entry in get_plugin_auxiliary_tasks():if _entry.get("key") == task:_defaults = _entry.get("defaults") or {}if isinstance(_defaults, dict):- return {**_defaults, **task_config}+ _inherit = _entry.get("inherit_from")+ if cyclic or not _inherit:+ return {**_defaults, **task_config}+ base = _get_auxiliary_task_config(_inherit, seen | {task})+ return {**base, **_defaults, **task_config}breakexcept Exception:pass # plugin discovery failure must not break aux task config readsdiff --git a/hermes_cli/plugins.py b/hermes_cli/plugins.pyindex 7747c86814c..7a55c5b08c0 100644--- a/hermes_cli/plugins.py+++ b/hermes_cli/plugins.py@@ -853,11 +853,17 @@ class PluginContext:def register_auxiliary_task(self, key: str, *, display_name: str, description: str,defaults: Optional[Dict[str, Any]] = None,+ inherit_from: Optional[str] = None,) -> PluginRegistration:"""Register an auxiliary LLM task with its own ``auxiliary.<key>`` config block (picker entry,``AUXILIARY_<KEY>_*`` env bridge, defaults merged into loaded configs). ``defaults`` mayoverride provider/model/base_url/api_key/timeout/extra_body (unknown keys kept verbatim).- Raises ``ValueError`` for an empty/invalid key, a built-in key, or another plugin's key."""+ ``inherit_from`` names a built-in or already-registered auxiliary task whose effective+ configuration becomes the base for this one; it is resolved at read time, so the task tracks+ the base's current config instead of snapshotting it (precedence: inherited base, then+ ``defaults``, then user config in ``auxiliary.<key>``).+ Raises ``ValueError`` for an empty/invalid key, a built-in key, another plugin's key, or an+ ``inherit_from`` that is empty, self-referential, or not a known auxiliary task."""me = self.manifest.nameif not key or not isinstance(key, str):raise ValueError(f"Plugin '{me}' tried to register auxiliary task with invalid key {key!r}")@@ -865,7 +871,8 @@ class PluginContext:raise ValueError(f"Plugin '{me}' auxiliary task key {key!r} "f"must contain only alphanumeric characters and underscores")from hermes_cli.main_provider_setup import _AUX_TASKS as _BUILTIN_AUX_TASKS- if key in {k for k, _name, _desc in _BUILTIN_AUX_TASKS}:+ builtin_aux_keys = {k for k, _name, _desc in _BUILTIN_AUX_TASKS}+ if key in builtin_aux_keys:raise ValueError(f"Plugin '{me}' cannot register auxiliary task {key!r} — that key is reserved "f"for a built-in task. Pick a plugin-namespaced key (e.g. '{me}_{key}').")# Owner is the canonical id ``ctx.llm`` is bound to, so agent/plugin_llm.py can match it.@@ -874,11 +881,27 @@ class PluginContext:if existing is not None and existing.get("plugin") != owner_id:raise ValueError(f"Plugin '{me}' cannot register auxiliary task {key!r} — already registered "f"by plugin '{existing.get('plugin')}'")+ if inherit_from is not None:+ if not isinstance(inherit_from, str) or not inherit_from.strip():+ raise ValueError(f"Plugin '{me}' auxiliary task {key!r} got an invalid inherit_from "+ f"{inherit_from!r} — pass a built-in or plugin auxiliary task key")+ # Same-owner re-registration is allowed, so a self-referential inherit_from would only be+ # caught at read time, as infinite recursion.+ if inherit_from == key:+ raise ValueError(f"Plugin '{me}' auxiliary task {key!r} cannot inherit from itself")+ if inherit_from not in builtin_aux_keys and inherit_from not in self._manager._aux_tasks:+ raise ValueError(f"Plugin '{me}' auxiliary task {key!r} cannot inherit from unknown task "+ f"{inherit_from!r} — use a built-in auxiliary task or one already "+ f"registered by a plugin")# Plugin owns the schema; routing fields are guaranteed present so consumers don't crash.+ # With inheritance the base supplies the shape, so only the plugin's own overrides go here.+ task_defaults = (dict(defaults or {}) if inherit_from else+ {"provider": "auto", "model": "", "base_url": "", "api_key": "", "timeout": 60,+ "extra_body": {}, **(defaults or {})})entry = {"key": key, "display_name": display_name, "description": description,- "defaults": {"provider": "auto", "model": "", "base_url": "", "api_key": "", "timeout": 60,- "extra_body": {}, **(defaults or {})},+ "defaults": task_defaults,+ "inherit_from": inherit_from,"plugin": owner_id, "plugin_key": owner_id,}return self._register_entry("auxiliary_task", key, self._manager._aux_tasks, entry,diff --git a/tests/hermes_cli/test_plugin_auxiliary_tasks.py b/tests/hermes_cli/test_plugin_auxiliary_tasks.pyindex c60a80792a4..ce659dcf4f2 100644--- a/tests/hermes_cli/test_plugin_auxiliary_tasks.py+++ b/tests/hermes_cli/test_plugin_auxiliary_tasks.py@@ -96,3 +96,127 @@ def test_reset_aux_to_auto_resets_plugin_tasks(tmp_path, monkeypatch, patched_macfg = load_config()assert cfg["auxiliary"]["my_aux"]["provider"] == "auto"assert cfg["auxiliary"]["my_aux"]["model"] == ""+++# ── inherit_from: read-time base + precedence ────────────────────────────────+++def aux_home(tmp_path, monkeypatch):+ """Empty HERMES_HOME so DEFAULT_CONFIG is the only source of built-in aux values."""+ from pathlib import Path++ home = tmp_path / ".hermes"+ home.mkdir()+ monkeypatch.setenv("HERMES_HOME", str(home))+ monkeypatch.setattr(Path, "home", lambda: tmp_path)+ return home+++def _register(patched_manager, **kwargs):+ ctx = PluginContext(PluginManifest(name="plug"), patched_manager)+ return ctx.register_auxiliary_task(+ key=kwargs.pop("key"), display_name="Plug Aux", description="d", **kwargs)+++def test_inherit_from_builtin_uses_builtin_defaults(aux_home, patched_manager):+ """An inherited built-in supplies the shape, so the plugin's 60 s default never applies."""+ from agent.auxiliary_client import _get_auxiliary_task_config++ _register(patched_manager, key="plug_aux", inherit_from="mcp")++ cfg = _get_auxiliary_task_config("plug_aux")+ assert cfg["timeout"] == 30 # DEFAULT_CONFIG["auxiliary"]["mcp"], not 60+ assert cfg["provider"] == "auto"+ assert cfg["extra_body"] == {}+ # Keys only the built-in block has survive the merge.+ assert cfg["reasoning_effort"] == ""+++def test_plugin_defaults_override_inherited_base(aux_home, patched_manager):+ from agent.auxiliary_client import _get_auxiliary_task_config++ _register(patched_manager, key="plug_aux", inherit_from="mcp",+ defaults={"timeout": 90, "model": "vendor/plugin"})++ cfg = _get_auxiliary_task_config("plug_aux")+ assert cfg["timeout"] == 90+ assert cfg["model"] == "vendor/plugin"+ assert cfg["provider"] == "auto" # untouched keys still come from the base+++def test_user_config_overrides_base_and_plugin_defaults(aux_home, patched_manager):+ from hermes_cli.config import load_config, save_config+ from agent.auxiliary_client import _get_auxiliary_task_config++ _register(patched_manager, key="plug_aux", inherit_from="mcp",+ defaults={"timeout": 90, "model": "vendor/plugin"})++ cfg = load_config()+ cfg.setdefault("auxiliary", {})["plug_aux"] = {"timeout": 5, "model": "vendor/user"}+ save_config(cfg)++ merged = _get_auxiliary_task_config("plug_aux")+ assert merged["timeout"] == 5 # user beats plugin default and the base+ assert merged["model"] == "vendor/user"+ assert merged["provider"] == "auto" # base still fills what nobody set+++def test_inherit_from_another_plugin_task(aux_home, patched_manager):+ from agent.auxiliary_client import _get_auxiliary_task_config++ _register(patched_manager, key="plug_base", inherit_from="mcp")+ _register(patched_manager, key="plug_child", inherit_from="plug_base",+ defaults={"timeout": 45})++ assert _get_auxiliary_task_config("plug_child")["timeout"] == 45+ assert _get_auxiliary_task_config("plug_child")["reasoning_effort"] == ""+++def test_inheritance_cycle_does_not_recurse(aux_home, patched_manager, caplog):+ """A hand-edited registry with a cycle must warn and fall back, not blow the stack."""+ import logging++ from agent.auxiliary_client import _get_auxiliary_task_config++ _register(patched_manager, key="plug_a", inherit_from="mcp", defaults={"timeout": 90})+ _register(patched_manager, key="plug_b", inherit_from="plug_a")+ patched_manager._aux_tasks["plug_a"]["inherit_from"] = "plug_b" # force the cycle++ with caplog.at_level(logging.WARNING, logger="agent.auxiliary_client"):+ merged = _get_auxiliary_task_config("plug_a")++ # Cycle cut at plug_a: its own defaults, no inherited base.+ assert merged["timeout"] == 90+ assert "reasoning_effort" not in merged+ assert "circular inherit_from" in caplog.text+++# ── inherit_from validation ─────────────────────────────────────────────────+++def test_unknown_inherit_from_raises(patched_manager):+ with pytest.raises(ValueError, match="unknown task"):+ _register(patched_manager, key="plug_aux", inherit_from="not_a_task")+++def test_self_inherit_raises(patched_manager):+ with pytest.raises(ValueError, match="itself"):+ _register(patched_manager, key="plug_aux", inherit_from="plug_aux")+++def test_empty_inherit_from_raises(patched_manager):+ with pytest.raises(ValueError, match="inherit_from"):+ _register(patched_manager, key="plug_aux", inherit_from="")+++def test_registration_without_inherit_from_keeps_fixed_shape(aux_home, patched_manager):+ """No inherit_from → today's fixed-shape defaults and no inheritance at read time."""+ from agent.auxiliary_client import _get_auxiliary_task_config++ reg = _register(patched_manager, key="plug_aux")+ entry = patched_manager._aux_tasks[reg.key]+ assert entry["inherit_from"] is None+ assert entry["defaults"] == {"provider": "auto", "model": "", "base_url": "", "api_key": "",+ "timeout": 60, "extra_body": {}}+ assert _get_auxiliary_task_config("plug_aux") == entry["defaults"]diff --git a/website/docs/developer-guide/plugin-llm-access.md b/website/docs/developer-guide/plugin-llm-access.mdindex 5cb0f9e08c2..4cd458eb701 100644--- a/website/docs/developer-guide/plugin-llm-access.md+++ b/website/docs/developer-guide/plugin-llm-access.md@@ -324,6 +324,24 @@ invocation. `allow_task_override: true` is an explicit operator grant forusing Hermes built-in auxiliary tasks; it does not permit another plugin'stasks. Omit `task=` (or use `"auto"`) to keep the active main provider/model.+`inherit_from` names a built-in or already-registered auxiliary task+whose effective configuration becomes the base for your task, resolved at+read time so the task tracks the base's current settings:++```python+def register(ctx):+ ctx.register_auxiliary_task(+ "classifier",+ display_name="Classifier",+ description="Classify input.",+ inherit_from="mcp", # start from the mcp aux block+ defaults={"timeout": 90}, # ...but give slow classifiers more room+ )+```++Precedence is the inherited base, then the plugin's `defaults`, then+operator configuration in `auxiliary.<task>`.+### Result attributes```python