Reject null agent registry fields
This commit is contained in:
parent
e801225220
commit
2fb6c10a5a
2 changed files with 31 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue