from __future__ import annotations from dataclasses import dataclass @dataclass class ConversationRoute: agent_id: str channel_chat_id: str source: str def resolve_agent_route( channel_chat_id: str, configured_bindings: dict[str, str] | None = None, runtime_bindings: dict[str, str] | None = None, default_agent: str = "main", ) -> ConversationRoute: if runtime_bindings and channel_chat_id in runtime_bindings: return ConversationRoute( agent_id=runtime_bindings[channel_chat_id], channel_chat_id=channel_chat_id, source="runtime_binding", ) if configured_bindings and channel_chat_id in configured_bindings: return ConversationRoute( agent_id=configured_bindings[channel_chat_id], channel_chat_id=channel_chat_id, source="configured_binding", ) return ConversationRoute( agent_id=default_agent, channel_chat_id=channel_chat_id, source="default", ) def resolve_configured_binding( channel_chat_id: str, bindings: dict[str, str] | None = None, ) -> str | None: if bindings and channel_chat_id in bindings: return bindings[channel_chat_id] return None def resolve_runtime_binding( channel_chat_id: str, bindings: dict[str, str] | None = None, ) -> str | None: if bindings and channel_chat_id in bindings: return bindings[channel_chat_id] return None