Reject null agent registry fields

This commit is contained in:
Mikhail Putilovskij 2026-04-24 13:05:26 +03:00
parent e801225220
commit 2fb6c10a5a
2 changed files with 31 additions and 4 deletions

View file

@ -29,6 +29,16 @@ class AgentRegistry:
raise AgentRegistryError(f"unknown agent id: {agent_id}") from exc
def _required_text(entry: Mapping[str, object], key: str) -> str:
value = entry.get(key)
if value is None:
raise AgentRegistryError("each agent entry requires id and label")
text = str(value).strip()
if not text:
raise AgentRegistryError("each agent entry requires id and label")
return text
def _load_registry_data(path: str | Path) -> dict[str, object]:
try:
raw = yaml.safe_load(Path(path).read_text(encoding="utf-8"))
@ -52,10 +62,8 @@ def load_agent_registry(path: str | Path) -> AgentRegistry:
for entry in entries:
if not isinstance(entry, Mapping):
raise AgentRegistryError("each agent entry requires id and label")
agent_id = str(entry.get("id", "")).strip()
label = str(entry.get("label", "")).strip()
if not agent_id or not label:
raise AgentRegistryError("each agent entry requires id and label")
agent_id = _required_text(entry, "id")
label = _required_text(entry, "label")
if agent_id in seen:
raise AgentRegistryError(f"duplicate agent id: {agent_id}")
seen.add(agent_id)