The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(agent): move memory-provider startup warnings into a sibling
Teknium0147e4416188
diff --git a/agent/agent_init.py b/agent/agent_init.pyindex 454035e37fd..f7b33f58754 100644--- a/agent/agent_init.py+++ b/agent/agent_init.py@@ -37,6 +37,9 @@ from agent.agent_init_ollama import _clamp_compressor_to_ollama_num_ctx, _configfrom agent.primary_runtime_snapshot import _snapshot_primary_runtimefrom agent.process_bootstrap import _install_safe_stdiofrom agent.subdirectory_hints import SubdirectoryHintTracker+from agent.agent_init_memory_warnings import (+ _unavailable_warning_key, _warn_memory_provider_unavailable, _warn_once, _warned_unavailable_providers,+)from agent.think_scrubber import StreamingThinkScrubberfrom agent.tool_guardrails import (ToolCallGuardrailConfig, ToolCallGuardrailController@@ -52,45 +55,6 @@ from utils import base_url_host_matches, is_truthy_valuelogger = logging.getLogger("run_agent")-# Deduped: the gateway builds a fresh AIAgent per message, so it would warn every turn.-_warned_unavailable_providers: set[tuple[str, str]] = set()---def _unavailable_warning_key(name: str) -> tuple[str, str]:- """Once per profile home and provider: one multiplexed gateway/Desktop backend serves several- profiles, and each one running without its memory must be told."""- from hermes_constants import get_hermes_home, hermes_home_key- return hermes_home_key(get_hermes_home()), name---def _warn_once(name: str, message: str, say=None) -> None:- """Log *message* and hand it to the user's sink once per home and provider."""- key = _unavailable_warning_key(name)- if key in _warned_unavailable_providers:- return- _warned_unavailable_providers.add(key)- logger.warning(message)- if say is not None:- say(message)---def _warn_memory_provider_unavailable(name: str, reason: str = "", say=None) -> None:- """Warn once per home and provider that a configured memory provider is unavailable.-- ``is_available()`` is a side-effect-free hot-path check and can't log itself; without this- the provider is silently dropped. ``reason`` (the provider's ``unavailable_reason()`` hint)- can only reach the user here, so it is appended when present. *say* is the agent's- user-facing sink: a log line alone leaves the user running without memory unaware.- """- _warn_once(name, (- f"⚠ Memory provider {name!r} is selected but reports unavailable — external memory "- "is disabled for this session (built-in memory still works). Check the "- "provider's credentials/config with 'hermes memory status'. Note: "- "systemd/gateway services do not inherit ~/.hermes/.env automatically; set "- f"any required variables in the service environment.{f' {reason}' if reason else ''}"- ), say=say)--def _provider_default_routes(provider: str) -> set[str]:"""Return known exact default routes for a canonical provider id."""routes: set[str] = set()@@ -705,7 +669,7 @@ def _init_prompt_cache_config(agent):agent._use_native_cache_layout = Falseagent._cache_ttl = Noneagent._cache_disabled = True- except Exception as exc:+ except Exception as exc: # health: allow BLE001 -- init must survive any config failure; the class is logged# Config values and traceback frames may contain credentials.logger.warning("Agent configuration for prompt_caching.cache_ttl could not be loaded (%s); "@@ -2384,7 +2348,7 @@ def init_agent(try:from hermes_cli.config import load_config_readonly as _load_agent_config_agent_cfg = _load_agent_config()- except Exception as exc:+ except Exception as exc: # health: allow BLE001 -- init must survive any config failure; the class is logged# Config exceptions may contain secrets; omit their message and traceback# even when a caller installs a non-redacting log handler.logger.warning(diff --git a/agent/agent_init_memory_warnings.py b/agent/agent_init_memory_warnings.pynew file mode 100644index 00000000000..b334fe93afd--- /dev/null+++ b/agent/agent_init_memory_warnings.py@@ -0,0 +1,46 @@+"""Startup warnings for a configured memory provider that will not run this session."""++from __future__ import annotations++import logging++logger = logging.getLogger("run_agent")+++# Deduped: the gateway builds a fresh AIAgent per message, so it would warn every turn.+_warned_unavailable_providers: set[tuple[str, str]] = set()+++def _unavailable_warning_key(name: str) -> tuple[str, str]:+ """Once per profile home and provider: one multiplexed gateway/Desktop backend serves several+ profiles, and each one running without its memory must be told."""+ from hermes_constants import get_hermes_home, hermes_home_key+ return hermes_home_key(get_hermes_home()), name+++def _warn_once(name: str, message: str, say=None) -> None:+ """Log *message* and hand it to the user's sink once per home and provider."""+ key = _unavailable_warning_key(name)+ if key in _warned_unavailable_providers:+ return+ _warned_unavailable_providers.add(key)+ logger.warning(message)+ if say is not None:+ say(message)+++def _warn_memory_provider_unavailable(name: str, reason: str = "", say=None) -> None:+ """Warn once per home and provider that a configured memory provider is unavailable.++ ``is_available()`` is a side-effect-free hot-path check and can't log itself; without this+ the provider is silently dropped. ``reason`` (the provider's ``unavailable_reason()`` hint)+ can only reach the user here, so it is appended when present. *say* is the agent's+ user-facing sink: a log line alone leaves the user running without memory unaware.+ """+ _warn_once(name, (+ f"⚠ Memory provider {name!r} is selected but reports unavailable — external memory "+ "is disabled for this session (built-in memory still works). Check the "+ "provider's credentials/config with 'hermes memory status'. Note: "+ "systemd/gateway services do not inherit ~/.hermes/.env automatically; set "+ f"any required variables in the service environment.{f' {reason}' if reason else ''}"+ ), say=say)diff --git a/agent/reasoning_params.py b/agent/reasoning_params.pyindex 30f724a3f8d..38d881a4127 100644--- a/agent/reasoning_params.py+++ b/agent/reasoning_params.py@@ -193,7 +193,7 @@ class ReasoningParamsMixin:try:from hermes_cli.config import load_config_readonlyreturn bool((load_config_readonly().get("model") or {}).get("reasoning_echo"))- except Exception as exc:+ except Exception as exc: # health: allow BLE001 -- a config failure must fall back, not fail init# Log the class, never the config value or exception traceback.logging.getLogger("run_agent").warning("Agent configuration for model.reasoning_echo could not be loaded (%s); "diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.pyindex 1859b5c34c2..04773029122 100644--- a/hermes_cli/config_defaults.py+++ b/hermes_cli/config_defaults.py@@ -1707,10 +1707,8 @@ DEFAULT_CONFIG = {# substitutes it; a bare string is shorthand for append. `replace` wins over `append` if both# are given."platform_hints": {},- # Plugin system. `enabled`/`disabled` lists are written by `hermes plugins enable|disable` and- # deliberately omitted here so an empty default never clobbers a user allow-list. So is- # `disabled_by_update`, which `hermes update` writes for each plugin it had to turn off (read by- # pm.plugin_eviction, which retries those plugins on every update, and by doctor/memory status).+ # Plugin system. `enabled`/`disabled` (`hermes plugins enable|disable`) and `disabled_by_update` (pm.plugin_eviction:+ # plugins an update turned off, retried each update) are omitted so an empty default never clobbers a user's lists."plugins": {# Deadline (seconds) for one plugin Git clone, fetch or checkout. Slow repositories may# need more time; each network operation is capped at one hour.diff --git a/tests/agent/test_memory_provider_unavailable_warning.py b/tests/agent/test_memory_provider_unavailable_warning.pyindex 49e135369f6..653f285a1e2 100644--- a/tests/agent/test_memory_provider_unavailable_warning.py+++ b/tests/agent/test_memory_provider_unavailable_warning.py@@ -8,7 +8,7 @@ service that didn't inherit ``~/.hermes/.env``) used to be dropped silently.import logging-from agent import agent_init+from agent import agent_init_memory_warnings as agent_initdef test_warns_once_and_dedupes(caplog):