mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 12:40:03 +08:00
- manager: exponential-backoff retry (send_max_retries), origin-scoped duplicate suppression, _stream_delta coalescing, per-channel send_progress/send_tool_hints gating (global AND channel override) - base: send_delta/supports_streaming protocol, _wants_stream injection - runner: live stream segments per loop round (turn_id:call_id), narration rounds freeze on completion, final reply marked _streamed when delivered - telegram: split API/polling HTTPX pools (pool exhaustion fix), trim legacy nanobot command menu, raise on send failure for manager retry - slack: Socket Mode handshake timeout + WSS diagnostics, send raises - schema: DeliveryOverrides/StreamingSupport mixins on channel configs - partners/network.py: strict SSRF validator for channel media downloads - icons: correct WeCom mark (TDesign outline, official brand palette) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""Async message queue for decoupled channel-agent communication."""
|
|
|
|
import asyncio
|
|
|
|
from deeptutor.partners.bus.events import InboundMessage, OutboundMessage
|
|
|
|
|
|
class MessageBus:
|
|
"""
|
|
Async message bus that decouples chat channels from the agent core.
|
|
|
|
Channels push messages to the inbound queue, and the agent processes
|
|
them and pushes responses to the outbound queue.
|
|
"""
|
|
|
|
def __init__(self):
|
|
self.inbound: asyncio.Queue[InboundMessage] = asyncio.Queue()
|
|
self.outbound: asyncio.Queue[OutboundMessage] = asyncio.Queue()
|
|
|
|
async def publish_inbound(self, msg: InboundMessage) -> None:
|
|
"""Publish a message from a channel to the agent."""
|
|
await self.inbound.put(msg)
|
|
|
|
async def consume_inbound(self) -> InboundMessage:
|
|
"""Consume the next inbound message (blocks until available)."""
|
|
return await self.inbound.get()
|
|
|
|
async def publish_outbound(self, msg: OutboundMessage) -> None:
|
|
"""Publish a response from the agent to channels."""
|
|
await self.outbound.put(msg)
|
|
|
|
async def consume_outbound(self) -> OutboundMessage:
|
|
"""Consume the next outbound message (blocks until available)."""
|
|
return await self.outbound.get()
|
|
|
|
@property
|
|
def inbound_size(self) -> int:
|
|
"""Number of pending inbound messages."""
|
|
return self.inbound.qsize()
|
|
|
|
@property
|
|
def outbound_size(self) -> int:
|
|
"""Number of pending outbound messages."""
|
|
return self.outbound.qsize()
|