From c75391dfbb42a961943402503858b9ded12b158f Mon Sep 17 00:00:00 2001 From: Greyson LaLonde Date: Mon, 5 Jan 2026 18:59:50 -0500 Subject: [PATCH] feat: activate polling events --- lib/crewai/src/crewai/a2a/__init__.py | 14 +++++- .../src/crewai/events/event_listener.py | 20 +++++++- .../crewai/events/utils/console_formatter.py | 47 ++++++++++++++++++- 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/lib/crewai/src/crewai/a2a/__init__.py b/lib/crewai/src/crewai/a2a/__init__.py index 352ad445e..e5065ddd9 100644 --- a/lib/crewai/src/crewai/a2a/__init__.py +++ b/lib/crewai/src/crewai/a2a/__init__.py @@ -1,6 +1,18 @@ """Agent-to-Agent (A2A) protocol communication module for CrewAI.""" from crewai.a2a.config import A2AConfig +from crewai.a2a.errors import A2APollingTimeoutError +from crewai.a2a.updates import ( + PollingConfig, + PushNotificationConfig, + StreamingConfig, +) -__all__ = ["A2AConfig"] +__all__ = [ + "A2AConfig", + "A2APollingTimeoutError", + "PollingConfig", + "PushNotificationConfig", + "StreamingConfig", +] diff --git a/lib/crewai/src/crewai/events/event_listener.py b/lib/crewai/src/crewai/events/event_listener.py index 36c37e9c9..bc69211c6 100644 --- a/lib/crewai/src/crewai/events/event_listener.py +++ b/lib/crewai/src/crewai/events/event_listener.py @@ -13,6 +13,8 @@ from crewai.events.types.a2a_events import ( A2ADelegationCompletedEvent, A2ADelegationStartedEvent, A2AMessageSentEvent, + A2APollingStartedEvent, + A2APollingStatusEvent, A2AResponseReceivedEvent, ) from crewai.events.types.agent_events import ( @@ -67,7 +69,6 @@ from crewai.events.types.mcp_events import ( MCPConnectionCompletedEvent, MCPConnectionFailedEvent, MCPConnectionStartedEvent, - MCPToolExecutionCompletedEvent, MCPToolExecutionFailedEvent, MCPToolExecutionStartedEvent, ) @@ -580,6 +581,23 @@ class EventListener(BaseEventListener): event.total_turns, ) + @crewai_event_bus.on(A2APollingStartedEvent) + def on_a2a_polling_started(_: Any, event: A2APollingStartedEvent) -> None: + self.formatter.handle_a2a_polling_started( + event.task_id, + event.polling_interval, + event.endpoint, + ) + + @crewai_event_bus.on(A2APollingStatusEvent) + def on_a2a_polling_status(_: Any, event: A2APollingStatusEvent) -> None: + self.formatter.handle_a2a_polling_status( + event.task_id, + event.state, + event.elapsed_seconds, + event.poll_count, + ) + # ----------- MCP EVENTS ----------- @crewai_event_bus.on(MCPConnectionStartedEvent) diff --git a/lib/crewai/src/crewai/events/utils/console_formatter.py b/lib/crewai/src/crewai/events/utils/console_formatter.py index a395db39f..e0d2c5055 100644 --- a/lib/crewai/src/crewai/events/utils/console_formatter.py +++ b/lib/crewai/src/crewai/events/utils/console_formatter.py @@ -114,7 +114,6 @@ To enable tracing, do any one of these: New streaming sessions will be created on-demand when needed. This method exists for API compatibility with HITL callers. """ - pass def print_panel( self, content: Text, title: str, style: str = "blue", is_flow: bool = False @@ -1417,3 +1416,49 @@ To enable tracing, do any one of these: panel = self.create_panel(content, "❌ MCP Tool Failed", "red") self.print(panel) self.print() + + def handle_a2a_polling_started( + self, + task_id: str, + polling_interval: float, + endpoint: str, + ) -> None: + """Handle A2A polling started event with panel display.""" + content = Text() + content.append("A2A Polling Started\n", style="cyan bold") + content.append("Task ID: ", style="white") + content.append(f"{task_id[:8]}...\n", style="cyan") + content.append("Interval: ", style="white") + content.append(f"{polling_interval}s\n", style="cyan") + + self.print_panel(content, "⏳ A2A Polling", "cyan") + + def handle_a2a_polling_status( + self, + task_id: str, + state: str, + elapsed_seconds: float, + poll_count: int, + ) -> None: + """Handle A2A polling status event with panel display.""" + if state == "completed": + style = "green" + status_indicator = "✓" + elif state == "failed": + style = "red" + status_indicator = "✗" + elif state == "working": + style = "yellow" + status_indicator = "⋯" + else: + style = "cyan" + status_indicator = "•" + + content = Text() + content.append(f"Poll #{poll_count}\n", style=f"{style} bold") + content.append("Status: ", style="white") + content.append(f"{status_indicator} {state}\n", style=style) + content.append("Elapsed: ", style="white") + content.append(f"{elapsed_seconds:.1f}s\n", style=style) + + self.print_panel(content, f"📊 A2A Poll #{poll_count}", style)