from __future__ import annotations from typing import Any def resolve_agent_route( config: dict[str, Any], channel_id: str, team_id: str | None = None, user_id: str | None = None, ) -> dict[str, Any]: """Per-channel / Per-team Agent 路由解析。 根据消息来源的频道或团队,路由到不同的 AI Agent。 当配置中未指定路由时,使用默认 Agent。 """ routes = config.get("agent_routes", {}) if team_id: team_key = f"team:{team_id}" if team_key in routes: return routes[team_key] if channel_id: channel_key = f"channel:{channel_id}" if channel_key in routes: return routes[channel_key] if user_id: user_key = f"user:{user_id}" if user_key in routes: return routes[user_key] default_agent = config.get("default_agent_id", "") return {"agent_id": default_agent, "route": "default"} def build_agent_route_map(config: dict[str, Any]) -> dict[str, Any]: """构建 Agent 路由映射表。""" routes = config.get("agent_routes", {}) return { "routes": routes, "default_agent_id": config.get("default_agent_id", ""), "route_count": len(routes), }