The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(shared-metrics): class connector errors from the wire's execute families
Siddharth Balyaneaff548aeccb
diff --git a/hermes_cli/observability/shared_metrics_contract.py b/hermes_cli/observability/shared_metrics_contract.pyindex 7dd0f90579b..af270d79bfd 100644--- a/hermes_cli/observability/shared_metrics_contract.py+++ b/hermes_cli/observability/shared_metrics_contract.py@@ -1816,30 +1816,31 @@ def tool_error_class(kwargs: dict[str, Any], outcome: str | None = None) -> str:return _TOOL_ERROR_TYPES.get(error_type, "exception" if error_type else "unknown")-# The tool gateway's execute codes (product family: the user or the model can fix it; backend: the-# gateway or the vendor failed). An unlisted code falls back to its family.+# The tool gateway's execute codes (``tools.connectors.gateway.wire.EXECUTE_ERROR_CODES``) by class;+# a code not listed here keeps ``tool_error`` unless its family is backend._CONNECTOR_CODE_CLASSES = {**dict.fromkeys(("CONNECTION_REQUIRED", "CONNECTION_EXPIRED"), "connection_required"),"TOOL_NOT_ALLOWED": "not_allowed",**dict.fromkeys(("ALIAS_REQUIRED", "ALIAS_UNKNOWN"), "alias"),"INVALID_ARGUMENTS": "invalid_arguments",- **dict.fromkeys((- "PROVIDER_ERROR", "PROVIDER_RATE_LIMITED", "PROVIDER_TIMEOUT", "POLICY_UNAVAILABLE", "GATEWAY_ERROR",- ), "connector_backend"),}_CONNECTOR_FAMILY_CLASSES = {"backend": "connector_backend"}def connector_error_class(kwargs: dict[str, Any]) -> str | None:- """The class of a failed connector entry from its result's ``error.code`` (``error.family`` for an- unlisted code); None when the call is not a connector call or its result names no code."""+ """The class of a failed connector entry from its result's ``error.code``; None when the call is+ not a connector call or its result names no code."""if not _norm(kwargs.get("tool_name")).startswith(CONNECTOR_NAME_PREFIX):return Noneerror = _result_error(kwargs.get("result"))code = str(error.get("code") or "").strip().upper()if not code:return None- return _CONNECTOR_CODE_CLASSES.get(code) or _CONNECTOR_FAMILY_CLASSES.get(_norm(error.get("family")))+ # Late import: the wire module pulls pydantic, which the contract does not need at import.+ from tools.connectors.gateway.wire import execute_error_family++ family = execute_error_family(code, error.get("family") if isinstance(error.get("family"), str) else None)+ return _CONNECTOR_FAMILY_CLASSES.get(family or "") or _CONNECTOR_CODE_CLASSES.get(code)def _result_error(result: Any) -> dict[str, Any]:diff --git a/tests/hermes_cli/test_shared_metrics_connectors.py b/tests/hermes_cli/test_shared_metrics_connectors.pyindex 2676929be88..9ccbe64ba33 100644--- a/tests/hermes_cli/test_shared_metrics_connectors.py+++ b/tests/hermes_cli/test_shared_metrics_connectors.py@@ -42,6 +42,13 @@ def test_a_failed_connector_entry_is_classed_by_its_gateway_code(code, family, eassert expected in contract.TOOL_ERROR_CLASSES+def test_every_classed_code_is_a_gateway_execute_code():+ from tools.connectors.gateway.wire import EXECUTE_ERROR_CODES++ assert set(contract._CONNECTOR_CODE_CLASSES) <= set(EXECUTE_ERROR_CODES)+ assert all(EXECUTE_ERROR_CODES[code][0] == "product" for code in contract._CONNECTOR_CODE_CLASSES)++def test_connector_and_bridge_calls_are_named_without_a_slug():connector = {"tool_name": "connectors__gmail__SEND_EMAIL", "toolset": "other"}assert contract.tool_metric_name(connector) == "connector"