CoolFace
Apppublic

omkarkudalkar23/citationEdge

sourceHugging Faceupdated 2mo agoView on Hugging Face
2likes
a2a_protocol.py33 linesDownload Raw Back to protocols
1"""2Agent-to-Agent (A2A) protocol: direct async calls between agent methods.3Used when agents need to request data synchronously from another agent4rather than through the event queue.5"""6from typing import Any, Callable, Dict, Optional7from utils.logger import get_logger8 9logger = get_logger("a2a_protocol")10 11 12class A2AProtocol:13    """Registry-based direct agent-to-agent call protocol."""14 15    def __init__(self):16        self._registry: Dict[str, Callable] = {}17 18    def register(self, agent_name: str, handler: Callable) -> None:19        self._registry[agent_name] = handler20        logger.debug(f"[A2A] Registered handler for '{agent_name}'")21 22    async def call(self, target: str, method: str, **kwargs) -> Any:23        handler = self._registry.get(target)24        if handler is None:25            raise KeyError(f"[A2A] No handler registered for '{target}'")26        result = handler(method, **kwargs)27        if hasattr(result, "__await__"):28            return await result29        return result30 31    def is_registered(self, agent_name: str) -> bool:32        return agent_name in self._registry33