Skip to content

The agent that grows with you

fix(observability): preserve configured model attribution

Alex Fourniera0476b360512
diff --git a/hermes_cli/observability/shared_metrics_contract.py b/hermes_cli/observability/shared_metrics_contract.py
index 9af1a8fe755..63c6a706986 100644
--- a/hermes_cli/observability/shared_metrics_contract.py
+++ b/hermes_cli/observability/shared_metrics_contract.py
@@ -363,17 +363,17 @@ def count_bucket(count: int) -> str:
def model_call_fields(kwargs: dict[str, Any]) -> dict[str, str]:
"""Return the terminal model identity and provider route known to Hermes."""
- response_model = kwargs.get("response_model")
- model = (
- response_model
- if isinstance(response_model, str) and response_model.strip()
- else kwargs.get("model")
+ model = _metric_identifier(
+ kwargs.get("response_model"),
+ max_length=MODEL_IDENTIFIER_MAX_LENGTH,
)
- return {
- "model": _metric_identifier(
- model,
+ if model == "unknown":
+ model = _metric_identifier(
+ kwargs.get("model"),
max_length=MODEL_IDENTIFIER_MAX_LENGTH,
- ),
+ )
+ return {
+ "model": model,
"provider": _metric_identifier(
kwargs.get("provider"),
max_length=PROVIDER_IDENTIFIER_MAX_LENGTH,
diff --git a/tests/hermes_cli/test_relay_shared_metrics.py b/tests/hermes_cli/test_relay_shared_metrics.py
index 9dd42d0425e..9cfd36cd6e3 100644
--- a/tests/hermes_cli/test_relay_shared_metrics.py
+++ b/tests/hermes_cli/test_relay_shared_metrics.py
@@ -216,6 +216,24 @@ def test_model_call_fields_report_terminal_model_and_provider_without_a_catalog(
}
+ "response_model",
+ [
+ "contains a space",
+ "x" * (MODEL_IDENTIFIER_MAX_LENGTH + 1),
+ ],
+)
+def test_model_call_fields_fall_back_when_response_model_is_invalid(response_model):
+ assert model_call_fields({
+ "model": "nvidia/nemotron-3-ultra",
+ "response_model": response_model,
+ "provider": "openrouter",
+ }) == {
+ "model": "nvidia/nemotron-3-ultra",
+ "provider": "openrouter",
+ }
+
+
@pytest.mark.parametrize(
("field", "value"),
[