feat: activate polling events

This commit is contained in:
Greyson LaLonde
2026-01-05 18:59:50 -05:00
parent f478004e11
commit c75391dfbb
3 changed files with 78 additions and 3 deletions

View File

@@ -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",
]

View File

@@ -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)

View File

@@ -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)