The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(relay): name the Relay plugin files in doctor and the startup log
emozilla51aa249efd58
diff --git a/agent/relay_runtime.py b/agent/relay_runtime.pyindex 19e516ae3cc..c2bc16df23f 100644--- a/agent/relay_runtime.py+++ b/agent/relay_runtime.py@@ -162,7 +162,25 @@ class _RelayPluginConfigurationLoadError(RuntimeError):def _activation_requires_managed_execution(activation: Any) -> bool:- """Return whether Relay activated any static or dynamic plugin behavior.+ """Return whether Relay activated any static or dynamic plugin behavior."""+ try:+ report = getattr(activation, "report", None)+ except Exception:+ report = None+ return _report_requires_managed_execution(report)+++def _activation_config_paths(activation: Any) -> list[str]:+ """Return the plugins.toml files an activation loaded, lowest precedence first."""+ try:+ paths = getattr(activation, "report", {}).get("config_paths")+ except Exception:+ return []+ return [str(path) for path in paths] if isinstance(paths, list) else []+++def _report_requires_managed_execution(report: Any) -> bool:+ """Return whether a Relay plugin-host report enables any static or dynamic plugin.Relay owns the report contract. An unfamiliar report stays fail-safe byretaining Hermes managed execution instead of silently bypassing plugins.@@ -170,14 +188,11 @@ def _activation_requires_managed_execution(activation: Any) -> bool:def keep_enabled() -> bool:logger.warning(- "Hermes could not determine whether the Relay activation is empty; keeping managed execution enabled"+ "Hermes could not determine whether the Relay plugin configuration is empty; keeping managed "+ "execution enabled")return True- try:- report = getattr(activation, "report", None)- except Exception:- return keep_enabled()if not isinstance(report, dict):return keep_enabled()resolved = report.get("resolved_config")@@ -292,7 +307,8 @@ class _ProcessRelayPluginConfiguration:if self._state is _RelayPluginConfigurationState.ACTIVE:logger.info("The Relay plugin host is active process-wide and applies to all profiles hosted by this "- "Hermes process."+ "Hermes process. Configuration files: %s",+ "; ".join(_activation_config_paths(self._activation)) or "none reported",)self._owners.add(id(owner))return self._state@@ -1300,17 +1316,23 @@ def _load_nemo_relay() -> Any:def _configured_plugin_inputs() -> Path | None:"""Return the parseable explicit override, or ``None`` to use Relay discovery."""+ config_path = _explicit_plugins_toml()+ if config_path is None and (legacy_vars := configured_legacy_relay_env_vars(os.environ)):+ logger.warning(+ "Legacy NeMo Relay exporter variables are set but no %s was provided. %s no longer configure "+ "Relay exporters; any standard user or system plugins.toml still applies. Run `hermes migrate "+ "relay` (or `hermes update`, which runs it for every profile) to generate %s and select it in .env.",+ RELAY_PLUGINS_CONFIG_ENV,+ ", ".join(legacy_vars),+ get_hermes_home() / "relay-plugins.toml",+ )+ return config_path+++def _explicit_plugins_toml() -> Path | None:+ """Return the file selected by ``HERMES_NEMO_RELAY_PLUGINS_TOML`` after checking that it parses."""configured = os.environ.get(RELAY_PLUGINS_CONFIG_ENV, "").strip()if not configured:- if legacy_vars := configured_legacy_relay_env_vars(os.environ):- logger.warning(- "Legacy NeMo Relay exporter variables are set but no %s was provided. %s no longer configure "- "Relay exporters; any standard user or system plugins.toml still applies. Run `hermes migrate "- "relay` (or `hermes update`, which runs it for every profile) to generate %s and select it in .env.",- RELAY_PLUGINS_CONFIG_ENV,- ", ".join(legacy_vars),- get_hermes_home() / "relay-plugins.toml",- )return Noneconfig_path = Path(configured).expanduser()try:@@ -1325,6 +1347,37 @@ def _configured_plugin_inputs() -> Path | None:) from exc+@dataclass(frozen=True)+class RelayPluginSources:+ """The plugin configuration Relay resolves for this process, as its validator reports it."""++ config_paths: tuple[str, ...] # lowest precedence first+ enabled: bool # whether any static component or dynamic plugin is switched on+ errors: tuple[str, ...] # initialization would refuse the configuration+ warnings: tuple[str, ...]+++def resolve_plugin_sources(relay: Any = None) -> RelayPluginSources:+ """Resolve the plugins.toml layers this process would load, without loading plugin code.++ Relay's validator reads the same layers as initialization but does not take the process-wide host.+ Raises when a file cannot be read or parsed.+ """+ relay = relay or _load_nemo_relay()+ report = relay.plugin.validate({}, additional_plugins_toml=_explicit_plugins_toml())+ diagnostics = [d for d in (report.get("config") or {}).get("diagnostics") or [] if isinstance(d, dict)]+ return RelayPluginSources(+ config_paths=tuple(str(path) for path in report.get("config_paths") or []),+ enabled=_report_requires_managed_execution(report),+ errors=tuple(str(d.get("message")) for d in diagnostics if d.get("level") == "error"),+ # Relay adds one "configuration_inherited" note per discovered file; config_paths already names them.+ warnings=tuple(+ str(d.get("message")) for d in diagnostics+ if d.get("level") == "warning" and d.get("code") != "plugin.configuration_inherited"+ ),+ )++# Relay 0.9 exposes no active-host query; only initialize's two Conflict messages signal one._RELAY_HOST_CONFLICT_MESSAGES = frozenset({diff --git a/hermes_cli/doctor.py b/hermes_cli/doctor.pyindex 95006259000..9b8ffac8402 100644--- a/hermes_cli/doctor.py+++ b/hermes_cli/doctor.py@@ -29,6 +29,7 @@ from hermes_cli.doctor_config import (_check_config_file,_check_env_file,_check_mcp_security,+ _check_relay_plugins,_check_xai_retirement,_check_retired_session_reset,)@@ -121,7 +122,8 @@ DOCTOR_CHECKS = (('External Tools', _check_git_and_rg), (None, _check_terminal_backend), (None, _check_node_and_browser),(None, _check_npm_audit), ('API Connectivity', _check_api_connectivity),('Tool Availability', _check_tool_availability), ('Skills Hub', _check_skills_hub),- ('Memory Provider', _check_memory_provider), (None, _check_profiles),+ ('Memory Provider', _check_memory_provider), ('NeMo Relay Plugins', _check_relay_plugins),+ (None, _check_profiles),)diff --git a/hermes_cli/doctor_config.py b/hermes_cli/doctor_config.pyindex ef6bcd0877b..db9bd4f7db8 100644--- a/hermes_cli/doctor_config.py+++ b/hermes_cli/doctor_config.py@@ -96,6 +96,44 @@ def report_deprecated_config_and_env(raw_config: dict | None = None, env_map: direturn findings+@doctor_check("Relay plugin check failed: {e}")+def _check_relay_plugins(should_fix: bool, f: Finding) -> None:+ """Name the plugins.toml files Relay applies to Hermes, including ones outside the Hermes home."""+ from agent.relay_runtime import resolve_plugin_sources+ try:+ sources = resolve_plugin_sources()+ except ModuleNotFoundError as exc:+ if exc.name != "nemo_relay":+ raise+ check_ok("NeMo Relay is not available on this platform")+ return+ except Exception as exc:+ check_warn("Relay plugin configuration could not be read", "(Hermes runs without Relay plugins)")+ _relay_info_lines(cause for cause in (exc, exc.__cause__) if cause is not None)+ f.manual_issues.append("Fix the Relay plugin configuration shown under NeMo Relay Plugins.")+ return+ if not sources.config_paths:+ check_ok("No Relay plugin files found")+ return+ if sources.errors:+ check_warn("Relay will reject this plugin configuration", "(Hermes runs without Relay plugins)")+ f.manual_issues.append("Fix the Relay plugin configuration shown under NeMo Relay Plugins.")+ else:+ # Validation cannot load dynamic plugins, so Relay reports what it cannot confirm as a warning.+ report = check_warn if sources.warnings else check_ok+ if sources.enabled:+ report("Relay plugins enabled", "(applies to every profile a Hermes process hosts)")+ else:+ report("Relay plugin files found, nothing enabled")+ _relay_info_lines((*sources.config_paths, *sources.errors, *sources.warnings))+++def _relay_info_lines(lines) -> None:+ """Print Relay paths and messages as doctor detail rows, keeping multi-line parser errors indented."""+ for line in lines:+ check_info("\n ".join(part for part in str(line).strip().splitlines() if part.strip()))++def managed_scope_check() -> None:"""Report the active managed scope (resolved dir + pinned key counts); silent when none. A HERMES_MANAGED_DIRoverride is surfaced too — a redirected scope is the documented foot-gun (docs/design/managed-scope.md §7)."""diff --git a/tests/agent/test_relay_runtime_plugins.py b/tests/agent/test_relay_runtime_plugins.pyindex ca4cf767253..2b758eca385 100644--- a/tests/agent/test_relay_runtime_plugins.py+++ b/tests/agent/test_relay_runtime_plugins.py@@ -566,6 +566,22 @@ def test_present_plugins_section_is_validated_even_when_falsey(host.shutdown()+def test_active_log_names_every_loaded_configuration_file(explicit_static_config, caplog):+ report = {+ **ACTIVE_ACTIVATION_REPORT,+ "config_paths": [str(explicit_static_config), "/etc/nemo-relay/plugins.toml"],+ }+ relay = _FakeRelay(activation_report=report)++ with caplog.at_level("INFO"):+ host = relay_runtime.RelayRuntime(relay=relay, profile_key="profile")+ try:+ [line] = [r.getMessage() for r in caplog.records if "active process-wide" in r.getMessage()]+ assert all(path in line for path in report["config_paths"])+ finally:+ host.shutdown()++def test_two_profile_hosts_initialize_once_and_clear_after_final_shutdown(explicit_static_config,caplog,diff --git a/tests/hermes_cli/test_doctor_relay_plugins.py b/tests/hermes_cli/test_doctor_relay_plugins.pynew file mode 100644index 00000000000..21d3818ee9b--- /dev/null+++ b/tests/hermes_cli/test_doctor_relay_plugins.py@@ -0,0 +1,50 @@+"""``hermes doctor`` names the Relay plugin files the runtime actually loads.++Relay discovers user and system ``plugins.toml`` files outside the Hermes home, so doctor is the one+Hermes surface that shows a user which files apply. It must agree with what initialization loads.+"""++import pytest++from agent import relay_runtime+from hermes_cli.doctor_config import _check_relay_plugins++ENABLED_OBSERVABILITY = (+ "version = 1\n\n[[components]]\nkind = \"observability\"\nenabled = true\n\n[components.config]\nversion = 4\n"+)++[email protected]("explicit", [False, True], ids=["discovered", "explicit"])+def test_doctor_lists_the_files_the_runtime_loads(tmp_path, monkeypatch, capsys, explicit):+ relay = pytest.importorskip("nemo_relay")+ if getattr(relay, "_native", None) is None:+ pytest.skip("NeMo Relay native binding is unavailable on this platform")+ user_config = tmp_path / "xdg" / "nemo-relay" / "plugins.toml"+ user_config.parent.mkdir(parents=True)+ user_config.write_text(ENABLED_OBSERVABILITY, encoding="utf-8")+ monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path / "xdg"))+ monkeypatch.setenv("ProgramData", str(tmp_path / "programdata"))+ if explicit:+ selected = tmp_path / "selected.toml"+ selected.write_text(ENABLED_OBSERVABILITY, encoding="utf-8")+ monkeypatch.setenv(relay_runtime.RELAY_PLUGINS_CONFIG_ENV, str(selected))+ else:+ monkeypatch.delenv(relay_runtime.RELAY_PLUGINS_CONFIG_ENV, raising=False)++ _check_relay_plugins(False)+ doctor_output = capsys.readouterr().out++ relay_runtime._reset_for_tests()+ host = relay_runtime.RelayRuntime(relay=relay, profile_key="profile")+ try:+ assert host._plugin_configuration_state is relay_runtime._RelayPluginConfigurationState.ACTIVE+ loaded = relay_runtime._activation_config_paths(relay_runtime._PLUGIN_CONFIGURATION._activation)+ finally:+ host.shutdown()+ relay_runtime._reset_for_tests()++ assert (str(user_config) in loaded) is not explicit+ assert "Relay plugins enabled" in doctor_output+ assert all(path in doctor_output for path in loaded)+ if explicit:+ assert str(user_config) not in doctor_outputdiff --git a/website/docs/developer-guide/relay-shared-metrics.md b/website/docs/developer-guide/relay-shared-metrics.mdindex a3513730737..c5bca3df9a1 100644--- a/website/docs/developer-guide/relay-shared-metrics.md+++ b/website/docs/developer-guide/relay-shared-metrics.md@@ -59,13 +59,23 @@ This choice is read from the profile's own `config.yaml`. A machine-managedconfiguration overlay cannot enable or disable shared metrics on the profile'sbehalf.-Hermes uses Relay's normal process-wide plugin discovery. Without an explicit-selection, Relay loads the user `plugins.toml` and then the machine-wide system-configuration at higher precedence. `HERMES_NEMO_RELAY_PLUGINS_TOML` replaces-the user file with an explicit file; the system configuration still applies-above it. Repository-local configuration is ignored. If an explicitly selected-file cannot be loaded, Hermes reports the error and continues without Relay-plugins rather than falling back to another configuration.+Hermes uses Relay's normal process-wide plugin discovery. Relay reads these+files, lowest precedence first:++| Layer | Linux and macOS | Windows |+|-------|-----------------|---------|+| User | `$XDG_CONFIG_HOME/nemo-relay/plugins.toml`, or `~/.config/nemo-relay/plugins.toml` | `%USERPROFILE%\.config\nemo-relay\plugins.toml` (`XDG_CONFIG_HOME` and then `HOME` take precedence when set) |+| System | `/etc/nemo-relay/plugins.toml` | `%ProgramData%\nemo-relay\plugins.toml` |++`HERMES_NEMO_RELAY_PLUGINS_TOML` replaces the user file with an explicit file;+the system file still applies above it. Repository-local configuration is+ignored. If an explicitly selected file cannot be loaded, Hermes reports the+error and continues without Relay plugins rather than falling back to another+configuration.++Run `hermes doctor` to see which files apply. Its **NeMo Relay Plugins**+section lists each file Relay resolves, whether any plugin is enabled, and any+problem Relay reports, without loading plugin code.## Session-Span Segmentation for Continuous Sessions@@ -111,10 +121,10 @@ Relay plugin configuration is a process-level deployment choice, not a Hermesprofile setting. The first hosted profile triggers lazy initialization, andevery additional profile hosted by that Hermes process shares the resultingstatic middleware, dynamic plugins, subscribers, exporters, and guardrail-policy. After initialization succeeds, Hermes logs:+policy. After initialization succeeds, Hermes logs the files it loaded:```text-The Relay plugin host is active process-wide and applies to all profiles hosted by this Hermes process.+The Relay plugin host is active process-wide and applies to all profiles hosted by this Hermes process. Configuration files: /home/user/.config/nemo-relay/plugins.toml; /etc/nemo-relay/plugins.toml```Profile scopes still preserve causal isolation inside that shared policy.diff --git a/website/docs/user-guide/features/built-in-plugins.md b/website/docs/user-guide/features/built-in-plugins.mdindex cf13ceb6fe5..e7d7bd39ca8 100644--- a/website/docs/user-guide/features/built-in-plugins.md+++ b/website/docs/user-guide/features/built-in-plugins.md@@ -215,7 +215,7 @@ Hermes-prefixed and standard SDK env vars (`LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRNeMo Relay is no longer a bundled Hermes plugin. Do not run `hermes plugins enable observability/nemo_relay`; Hermes core now owns the Relay session, turn, LLM, and tool lifecycles.-Configure Relay middleware or exporters through a standard Relay `plugins.toml`. Hermes loads Relay's user configuration and then its machine-wide system configuration. Set `HERMES_NEMO_RELAY_PLUGINS_TOML` before starting Hermes only when you want an explicit file to replace the user configuration; the system configuration still has higher precedence. The policy is process-wide for every profile hosted by that Hermes process. See the [NeMo Relay observability configuration](https://docs.nvidia.com/nemo/relay/configure-plugins/observability/about) for ATOF, ATIF, and OpenTelemetry options.+Configure Relay middleware or exporters through a standard Relay `plugins.toml`. Hermes loads Relay's user configuration (`~/.config/nemo-relay/plugins.toml`) and then its machine-wide system configuration (`/etc/nemo-relay/plugins.toml`, or `%ProgramData%\nemo-relay\plugins.toml` on Windows). Set `HERMES_NEMO_RELAY_PLUGINS_TOML` before starting Hermes only when you want an explicit file to replace the user configuration; the system configuration still has higher precedence. The policy is process-wide for every profile hosted by that Hermes process. Run `hermes doctor` to see which files apply. See the [NeMo Relay observability configuration](https://docs.nvidia.com/nemo/relay/configure-plugins/observability/about) for ATOF, ATIF, and OpenTelemetry options.The old `HERMES_NEMO_RELAY_ATOF_*` and `HERMES_NEMO_RELAY_ATIF_*` settings no longer configure exporters. When `HERMES_NEMO_RELAY_PLUGINS_TOML` is unset, the gateway warns about remaining legacy variables and `hermes doctor` reports them. Independently discovered Relay user or system exporters still apply.