CoolFace
Apppublic

omkarkudalkar23/citationEdge

sourceHugging Faceupdated 2mo agoView on Hugging Face
2likes
base_protocol.py34 linesDownload Raw Back to protocols
1from abc import ABC, abstractmethod2from dataclasses import dataclass, field3from datetime import datetime4from typing import Any, Dict, Optional5from utils.helpers import generate_id6 7 8@dataclass9class Message:10    """Inter-agent message envelope."""11    sender: str12    recipient: str13    msg_type: str          # e.g. "task_complete", "error", "data"14    payload: Dict[str, Any] = field(default_factory=dict)15    msg_id: str = field(default_factory=lambda: generate_id("msg"))16    timestamp: str = field(default_factory=lambda: datetime.utcnow().isoformat())17    job_id: Optional[str] = None18 19 20class BaseProtocol(ABC):21    """Abstract base for all inter-agent communication protocols."""22 23    @abstractmethod24    async def send(self, message: Message) -> None:25        """Publish a message."""26 27    @abstractmethod28    async def receive(self, recipient: str, timeout: float = 30.0) -> Optional[Message]:29        """Receive the next message for a given recipient."""30 31    @abstractmethod32    async def broadcast(self, message: Message, recipients: list) -> None:33        """Broadcast a message to multiple recipients."""34