feat: add !agent command and durable user agent selection

Users can now list available agents with !agent and select one by
number. Selection persists in user metadata (selected_agent_id). If the
current room has no agent binding yet, selecting an agent binds it
immediately so the user can start messaging without !new.

Also updates the dispatcher test to reflect that real-mode platform is
now RoutedPlatformClient, not a bare RealPlatformClient.
This commit is contained in:
Mikhail Putilovskij 2026-04-24 13:54:25 +03:00
parent a65227e490
commit 74cf028e8f
7 changed files with 292 additions and 6 deletions

View file

@ -36,7 +36,7 @@ from core.protocol import (
)
from sdk.interface import PlatformError
from sdk.mock import MockPlatformClient
from sdk.real import RealPlatformClient
from adapter.matrix.routed_platform import RoutedPlatformClient
async def test_matrix_dispatcher_registers_custom_handlers():
@ -907,15 +907,20 @@ async def test_prepare_live_sync_returns_next_batch_from_bootstrap_sync():
assert since == "s123"
async def test_build_runtime_uses_real_platform_when_matrix_backend_is_real(monkeypatch):
async def test_build_runtime_uses_routed_platform_when_matrix_backend_is_real(
monkeypatch, tmp_path
):
registry_path = tmp_path / "agents.yaml"
registry_path.write_text(
"agents:\n - id: agent-1\n label: Analyst\n", encoding="utf-8"
)
monkeypatch.setenv("MATRIX_PLATFORM_BACKEND", "real")
monkeypatch.setenv("AGENT_BASE_URL", "http://agent.example")
monkeypatch.setenv("MATRIX_AGENT_REGISTRY_PATH", str(registry_path))
runtime = build_runtime()
assert isinstance(runtime.platform, RealPlatformClient)
assert runtime.platform.agent_base_url == "http://agent.example"
assert runtime.platform.agent_id == "matrix-bot"
assert isinstance(runtime.platform, RoutedPlatformClient)
async def test_matrix_main_closes_platform_without_connecting_root_agent(monkeypatch):