Skip to content
Closed
Show file tree
Hide file tree
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
41 changes: 41 additions & 0 deletions artemis/core/diagnostics/probes/credentials_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ def _mask_key(self, key_str: str) -> str:
return f"{key_str[:6]}...{key_str[-4:]}"
return "***"

@staticmethod
def _config_provider_mismatch() -> str | None:
"""The first agent node whose configured provider lacks credentials, or ``None``."""
try:
from artemis.config.llm import get_default_llm_config

get_default_llm_config().validate_providers()
except Exception as exc: # noqa: BLE001 - config loading has open-ended failure modes
return str(exc)
return None

async def probe(self) -> ProbeResult:
import os

Expand Down Expand Up @@ -162,6 +173,36 @@ async def probe(self) -> ProbeResult:
"api_keys": api_keys_map,
}

# Keys exist, but do they match what the configured agent nodes will actually call? A task fails
# within seconds ("Planner requires GOOGLE_API_KEY") when config/artemis.jsonc names a provider
# whose key is missing, even though some other provider's key is valid.
mismatch = self._config_provider_mismatch() if configured_providers else None
if mismatch:
return ProbeResult(
id=self.probe_id,
category=self.category,
title="Multimodal LLM API Key",
status=ProbeStatus.FAIL,
is_blocker=self.is_blocker,
summary="Key Does Not Match Config",
description=(
f"{mismatch} Configured keys: "
f"{', '.join(p['label'] for p in configured_providers)}."
),
metadata=metadata,
actions=[
ProbeAction(
action_type="hint",
label="Align keys and models",
payload=(
"Add the missing provider key to .env, or point the 'default' block of "
"config/artemis.jsonc (and any node that pins a model) at a provider you "
"have a key for. Then restart the MCP server."
),
)
],
)

# Case 1: Gemini API Key configured (Standard / Recommended)
if gemini_key:
masked = self._mask_key(gemini_key.get_secret_value())
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/core/test_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,3 +513,37 @@ async def test_build_report_does_not_swallow_cancellation():

with pytest.raises(asyncio.CancelledError):
await engine._build_report()


@pytest.mark.asyncio
async def test_llm_credentials_probe_fails_when_keys_do_not_match_configured_models(monkeypatch):
"""A valid key for another provider must not read as "ready": tasks die within seconds."""
from artemis.config import settings

settings.set_api_key("anthropic", "sk-ant-test_key_1234567890", persist_to_env=False)
monkeypatch.setattr(
LLMCredentialsProbe,
"_config_provider_mismatch",
staticmethod(lambda: "Planner requires GOOGLE_API_KEY in .env"),
)

result = await LLMCredentialsProbe().probe()

assert result.status == ProbeStatus.FAIL
assert result.summary == "Key Does Not Match Config"
assert "Planner requires GOOGLE_API_KEY" in result.description
assert "Claude" in result.description # names the keys that are configured


@pytest.mark.asyncio
async def test_llm_credentials_probe_passes_when_config_and_keys_agree(monkeypatch):
from artemis.config import settings

settings.set_api_key("anthropic", "sk-ant-test_key_1234567890", persist_to_env=False)
monkeypatch.setattr(
LLMCredentialsProbe, "_config_provider_mismatch", staticmethod(lambda: None)
)

result = await LLMCredentialsProbe().probe()

assert result.status == ProbeStatus.PASS
Loading