Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions integrations/hermes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,17 @@ def _preload_agentmemory_dotenv() -> None:


def _validate_url(base: str) -> bool:
parsed = urlparse(base)
return parsed.scheme in ("http", "https")
if not base:
return False
try:
parsed = urlparse(base)
# .port raises ValueError on a non-numeric or out-of-range port
_ = parsed.port
except ValueError:
return False
if parsed.scheme not in ("http", "https"):
return False
return bool(parsed.hostname)


def _uses_plaintext_bearer_auth(base: str, secret: str = "") -> bool:
Expand Down Expand Up @@ -167,15 +176,9 @@ def name(self) -> str:
return "agentmemory"

def is_available(self) -> bool:
# Hermes contract: no network calls in is_available.
base = os.environ.get("AGENTMEMORY_URL", DEFAULT_BASE_URL)
if not _validate_url(base):
return False
try:
req = Request(f"{base}/agentmemory/health", method="GET")
with urlopen(req, timeout=2):
return True
except Exception:
return False
return _validate_url(base)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

def initialize(self, session_id: str, **kwargs: Any) -> None:
self._base = os.environ.get("AGENTMEMORY_URL", DEFAULT_BASE_URL)
Expand Down