fix: require matrix agent registry in real mode

This commit is contained in:
Mikhail Putilovskij 2026-04-24 13:24:56 +03:00
parent 242f4aadd3
commit 9ccba161a2
2 changed files with 43 additions and 21 deletions

View file

@ -30,7 +30,7 @@ from adapter.matrix.files import (
matrix_msgtype_for_attachment,
resolve_workspace_attachment_path,
)
from adapter.matrix.agent_registry import load_agent_registry
from adapter.matrix.agent_registry import AgentRegistryError, load_agent_registry
from adapter.matrix.handlers import register_matrix_handlers
from adapter.matrix.handlers.auth import handle_invite, provision_workspace_chat
from adapter.matrix.handlers.context_commands import (
@ -125,27 +125,27 @@ def _build_platform_from_env(*, store: StateStore, chat_mgr: ChatManager) -> Pla
if backend == "real":
prototype_state = PrototypeStateStore()
registry_path = os.environ.get("MATRIX_AGENT_REGISTRY_PATH", "").strip()
if registry_path:
registry = load_agent_registry(registry_path)
delegates = {
agent.agent_id: RealPlatformClient(
agent_id=agent.agent_id,
agent_base_url=_agent_base_url_from_env(),
prototype_state=prototype_state,
platform="matrix",
)
for agent in registry.agents
}
return RoutedPlatformClient(
chat_mgr=chat_mgr,
store=store,
delegates=delegates,
if not registry_path:
raise RuntimeError(
"MATRIX_AGENT_REGISTRY_PATH is required when MATRIX_PLATFORM_BACKEND=real"
)
return RealPlatformClient(
agent_id="matrix-bot",
agent_base_url=_agent_base_url_from_env(),
prototype_state=prototype_state,
platform="matrix",
try:
registry = load_agent_registry(registry_path)
except (AgentRegistryError, OSError) as exc:
raise RuntimeError(f"failed to load matrix agent registry: {registry_path}") from exc
delegates = {
agent.agent_id: RealPlatformClient(
agent_id=agent.agent_id,
agent_base_url=_agent_base_url_from_env(),
prototype_state=prototype_state,
platform="matrix",
)
for agent in registry.agents
}
return RoutedPlatformClient(
chat_mgr=chat_mgr,
store=store,
delegates=delegates,
)
return MockPlatformClient()