"""双 Agent 内部消息总线 — asyncio.Queue 封装"""

from __future__ import annotations

import asyncio
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from tool_agent.models import AgentMessage


class MessageBus:
    """Router Agent 与 Tool Agent 之间的异步消息队列"""

    def __init__(self) -> None:
        self._to_tool: asyncio.Queue[AgentMessage] = asyncio.Queue()
        self._to_router: asyncio.Queue[AgentMessage] = asyncio.Queue()

    async def send_to_tool(self, message: AgentMessage) -> None:
        await self._to_tool.put(message)

    async def send_to_router(self, message: AgentMessage) -> None:
        await self._to_router.put(message)

    async def recv_as_tool(self) -> AgentMessage:
        return await self._to_tool.get()

    async def recv_as_router(self) -> AgentMessage:
        return await self._to_router.get()
