diff --git a/lib/crewai/src/crewai/a2a/_compat.py b/lib/crewai/src/crewai/a2a/_compat.py index 093c2a77b..abba2b430 100644 --- a/lib/crewai/src/crewai/a2a/_compat.py +++ b/lib/crewai/src/crewai/a2a/_compat.py @@ -195,7 +195,9 @@ def agent_card_interfaces(agent_card: AgentCard) -> list[AgentInterface]: ``agent_card.additional_interfaces``. In v1.0 everything is in ``supported_interfaces``. """ - return list(agent_card.supported_interfaces) if agent_card.supported_interfaces else [] + return ( + list(agent_card.supported_interfaces) if agent_card.supported_interfaces else [] + ) def agent_card_protocol_version(agent_card: AgentCard) -> str: @@ -266,7 +268,8 @@ def create_client_config( supported_protocol_bindings=supported_transports or ["JSONRPC"], streaming=streaming, polling=polling, - accepted_output_modes=accepted_output_modes or ["text/plain", "application/json"], + accepted_output_modes=accepted_output_modes + or ["text/plain", "application/json"], push_notification_config=push_notification_config, grpc_channel_factory=grpc_channel_factory, ) diff --git a/lib/crewai/src/crewai/a2a/auth/utils.py b/lib/crewai/src/crewai/a2a/auth/utils.py index ef339cdae..389e61119 100644 --- a/lib/crewai/src/crewai/a2a/auth/utils.py +++ b/lib/crewai/src/crewai/a2a/auth/utils.py @@ -176,8 +176,8 @@ def validate_auth_against_agent_card( return for scheme_name in first_security_req.schemes.keys(): - security_scheme_wrapper: SecurityScheme | None = agent_card.security_schemes.get( - scheme_name + security_scheme_wrapper: SecurityScheme | None = ( + agent_card.security_schemes.get(scheme_name) ) if not security_scheme_wrapper: continue diff --git a/lib/crewai/src/crewai/a2a/config.py b/lib/crewai/src/crewai/a2a/config.py index 2e9566f8b..1023509ad 100644 --- a/lib/crewai/src/crewai/a2a/config.py +++ b/lib/crewai/src/crewai/a2a/config.py @@ -568,7 +568,9 @@ class A2AServerConfig(BaseModel): auth: Authentication scheme for A2A endpoints. """ - model_config: ClassVar[ConfigDict] = ConfigDict(extra="forbid", arbitrary_types_allowed=True) + model_config: ClassVar[ConfigDict] = ConfigDict( + extra="forbid", arbitrary_types_allowed=True + ) name: str | None = Field( default=None, diff --git a/lib/crewai/src/crewai/a2a/task_helpers.py b/lib/crewai/src/crewai/a2a/task_helpers.py index 8ad01f406..2d6e8750f 100644 --- a/lib/crewai/src/crewai/a2a/task_helpers.py +++ b/lib/crewai/src/crewai/a2a/task_helpers.py @@ -101,17 +101,13 @@ def extract_task_result_parts(a2a_task: A2ATask) -> list[str]: if a2a_task.status and a2a_task.status.message: msg = a2a_task.status.message - result_parts.extend( - part_text(part) for part in msg.parts if part_is_text(part) - ) + result_parts.extend(part_text(part) for part in msg.parts if part_is_text(part)) if not result_parts and a2a_task.history: for history_msg in reversed(a2a_task.history): if history_msg.role == ROLE_AGENT: result_parts.extend( - part_text(part) - for part in history_msg.parts - if part_is_text(part) + part_text(part) for part in history_msg.parts if part_is_text(part) ) break diff --git a/lib/crewai/src/crewai/a2a/updates/streaming/handler.py b/lib/crewai/src/crewai/a2a/updates/streaming/handler.py index ca2546569..7aef6486c 100644 --- a/lib/crewai/src/crewai/a2a/updates/streaming/handler.py +++ b/lib/crewai/src/crewai/a2a/updates/streaming/handler.py @@ -68,9 +68,7 @@ def _extract_text_from_artifact(artifact: TaskArtifactUpdateEvent) -> list[str]: parts: list[str] = [] if artifact.artifact and artifact.artifact.parts: parts.extend( - part_text(part) - for part in artifact.artifact.parts - if part_is_text(part) + part_text(part) for part in artifact.artifact.parts if part_is_text(part) ) return parts @@ -171,7 +169,9 @@ class StreamingHandler: if is_stream_status_update(chunk): update = chunk.status_update - is_final_update = process_status_update(update, result_parts) + is_final_update = process_status_update( + update, result_parts + ) if ( is_final_update @@ -352,9 +352,8 @@ class StreamingHandler: for p in artifact.parts ) effective_context_id = ( - (current_task.context_id if current_task else None) - or params.context_id - ) + current_task.context_id if current_task else None + ) or params.context_id crewai_event_bus.emit( agent_branch, A2AArtifactReceivedEvent( @@ -362,7 +361,9 @@ class StreamingHandler: artifact_id=artifact.artifact_id, artifact_name=artifact.name, artifact_description=artifact.description, - mime_type="text" if artifact.parts and part_is_text(artifact.parts[0]) else None, + mime_type="text" + if artifact.parts and part_is_text(artifact.parts[0]) + else None, size_bytes=artifact_size, append=artifact_update.append or False, last_chunk=artifact_update.last_chunk or False, diff --git a/lib/crewai/src/crewai/a2a/utils/delegation.py b/lib/crewai/src/crewai/a2a/utils/delegation.py index 23e5d2956..cae2dee19 100644 --- a/lib/crewai/src/crewai/a2a/utils/delegation.py +++ b/lib/crewai/src/crewai/a2a/utils/delegation.py @@ -116,11 +116,13 @@ def _create_file_parts(input_files: dict[str, Any] | None) -> list[Part]: parts: list[Part] = [] for name, file_input in input_files.items(): content_bytes = file_input.read() - parts.append(Part( - raw=content_bytes, - media_type=file_input.content_type or "application/octet-stream", - filename=file_input.filename or name, - )) + parts.append( + Part( + raw=content_bytes, + media_type=file_input.content_type or "application/octet-stream", + filename=file_input.filename or name, + ) + ) return parts @@ -463,7 +465,8 @@ async def _aexecute_a2a_delegation_impl( "endpoint": endpoint, "client_transports": client_transports, "server_transports": [ - iface.protocol_binding for iface in agent_card_interfaces(agent_card) + iface.protocol_binding + for iface in agent_card_interfaces(agent_card) ], }, ) @@ -952,7 +955,8 @@ async def _create_a2a_client( supported_transports=[transport_protocol], streaming=streaming and not use_polling, polling=use_polling, - accepted_output_modes=accepted_output_modes or list(DEFAULT_CLIENT_OUTPUT_MODES), + accepted_output_modes=accepted_output_modes + or list(DEFAULT_CLIENT_OUTPUT_MODES), push_notification_config=push_config, grpc_channel_factory=grpc_channel_factory, ) diff --git a/lib/crewai/src/crewai/a2a/utils/task.py b/lib/crewai/src/crewai/a2a/utils/task.py index 1bfd231e0..91c80cc49 100644 --- a/lib/crewai/src/crewai/a2a/utils/task.py +++ b/lib/crewai/src/crewai/a2a/utils/task.py @@ -416,7 +416,9 @@ async def _execute_impl( ) result_str = str(result) history: list[Message] = [context.message] if context.message else [] - history.append(new_agent_text_message(result_str, context_id=context_id, task_id=task_id)) + history.append( + new_agent_text_message(result_str, context_id=context_id, task_id=task_id) + ) await event_queue.enqueue_event( A2ATask( id=task_id, diff --git a/lib/crewai/src/crewai/a2a/utils/transport.py b/lib/crewai/src/crewai/a2a/utils/transport.py index eb8205914..a9a73a63c 100644 --- a/lib/crewai/src/crewai/a2a/utils/transport.py +++ b/lib/crewai/src/crewai/a2a/utils/transport.py @@ -12,7 +12,11 @@ from typing import Final, Literal from a2a.types import AgentCard, AgentInterface -from crewai.a2a._compat import agent_card_interfaces, agent_card_preferred_transport, agent_card_url +from crewai.a2a._compat import ( + agent_card_interfaces, + agent_card_preferred_transport, + agent_card_url, +) from crewai.events.event_bus import crewai_event_bus from crewai.events.types.a2a_events import A2ATransportNegotiatedEvent @@ -166,7 +170,9 @@ def negotiate_transport( source="client_preferred", ) else: - server_preferred = (agent_card_preferred_transport(agent_card) or JSONRPC_TRANSPORT).upper() + server_preferred = ( + agent_card_preferred_transport(agent_card) or JSONRPC_TRANSPORT + ).upper() if ( server_preferred in client_transports and server_preferred in transport_to_interface diff --git a/lib/crewai/src/crewai/a2a/wrapper.py b/lib/crewai/src/crewai/a2a/wrapper.py index b5b34d5df..f01e8a7b8 100644 --- a/lib/crewai/src/crewai/a2a/wrapper.py +++ b/lib/crewai/src/crewai/a2a/wrapper.py @@ -995,7 +995,9 @@ def _init_delegation_state( reference_task_ids=list(ctx.reference_task_ids), conversation_history=[], agent_card=current_agent_card, - agent_card_dict=agent_card_to_dict(current_agent_card) if current_agent_card else None, + agent_card_dict=agent_card_to_dict(current_agent_card) + if current_agent_card + else None, agent_name=current_agent_card.name if current_agent_card else None, ) @@ -1326,7 +1328,10 @@ def _delegate_to_a2a( if latest_message.context_id is not None: context_id = latest_message.context_id - if a2a_result["status"] in [TASK_STATE_COMPLETED, TASK_STATE_INPUT_REQUIRED]: + if a2a_result["status"] in [ + TASK_STATE_COMPLETED, + TASK_STATE_INPUT_REQUIRED, + ]: trusted_result, task_id, reference_task_ids, remote_notice = ( _handle_task_completion( a2a_result, @@ -1681,7 +1686,10 @@ async def _adelegate_to_a2a( if latest_message.context_id is not None: context_id = latest_message.context_id - if a2a_result["status"] in [TASK_STATE_COMPLETED, TASK_STATE_INPUT_REQUIRED]: + if a2a_result["status"] in [ + TASK_STATE_COMPLETED, + TASK_STATE_INPUT_REQUIRED, + ]: trusted_result, task_id, reference_task_ids, remote_notice = ( _handle_task_completion( a2a_result,