Skip to content

Comments

feat: enhance security (TLS), standardization (JSON Schema), and performance (uvloop)#721

Open
Fankouzu wants to merge 1 commit intoa2aproject:mainfrom
Fankouzu:feat/security-and-standardization
Open

feat: enhance security (TLS), standardization (JSON Schema), and performance (uvloop)#721
Fankouzu wants to merge 1 commit intoa2aproject:mainfrom
Fankouzu:feat/security-and-standardization

Conversation

@Fankouzu
Copy link

This PR introduces significant enhancements to the A2A Python SDK to improve security, robustness, and performance.

Key features:

  1. TLS/SSL Support: Added a dedicated TLS configuration module and integrated it into REST and gRPC transports for secure agent-to-agent communication.
  2. JSON Schema Validation: Implemented schema validation for core protocol message types, ensuring strict compliance and better error detection.
  3. Performance Optimization: Added optional uvloop integration for high-throughput asynchronous operations.
  4. Configuration Integration: Updated client factories and configurations to natively support these new features.

@Fankouzu Fankouzu requested a review from a team as a code owner February 22, 2026 11:16
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Fankouzu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly upgrades the A2A Python SDK by integrating critical features that enhance its security, robustness, and performance. It introduces a comprehensive TLS/SSL configuration system to secure agent-to-agent communication, implements JSON Schema validation for strict protocol message compliance, and provides optional uvloop integration to optimize asynchronous operations. These additions are seamlessly integrated into the SDK's client configuration and transport layers, making the A2A SDK more reliable and efficient.

Highlights

  • Enhanced Security with TLS/SSL: Integrated TLS configuration for secure HTTP and gRPC communication, including client and server-side setup and mTLS support.
  • Standardized Data with JSON Schema Validation: Implemented schema validation for core protocol messages to ensure strict compliance and better error detection.
  • Optimized Performance with uvloop: Added optional uvloop integration to significantly boost asynchronous operations for high-throughput scenarios.
  • Centralized Configuration: Updated client factories and configurations to seamlessly support the new TLS and validation features, making them easily accessible via ClientConfig.
Changelog
  • pyproject.toml
    • Added jsonschema as a core dependency.
    • Introduced performance extra dependency for uvloop.
    • Introduced tls extra dependency for cryptography.
    • Included performance and tls extras in the all dependency group.
  • src/a2a/init.py
    • Updated the module docstring to describe the new TLS, JSON Schema validation, and uvloop features.
    • Exported new client, performance, types, and validation modules in __all__.
  • src/a2a/client/init.py
    • Imported TLSConfig, create_grpc_channel_factory, and create_server_ssl_context from the new a2a.client.tls module.
    • Added these new TLS-related objects to the __all__ export list.
  • src/a2a/client/client.py
    • Added TYPE_CHECKING import for type hinting.
    • Introduced tls_config and validate_messages attributes to ClientConfig.
    • Added get_httpx_client method to ClientConfig to create an httpx.AsyncClient with TLS configuration.
    • Added get_grpc_channel_factory method to ClientConfig to create a gRPC channel factory with TLS configuration.
  • src/a2a/client/client_factory.py
    • Modified _register_defaults to use the ClientConfig's get_httpx_client method for JsonRpcTransport and RestTransport initialization, allowing TLS configuration to be applied.
  • src/a2a/client/tls.py
    • New file: Defined TLSConfig dataclass for managing TLS/SSL settings.
    • Implemented create_ssl_context within TLSConfig to generate ssl.SSLContext objects.
    • Provided create_httpx_client method in TLSConfig to configure httpx.AsyncClient instances.
    • Added create_grpc_credentials and create_grpc_channel_factory functions for gRPC TLS integration.
    • Included create_server_ssl_context for server-side TLS setup.
  • src/a2a/client/transports/grpc.py
    • Updated the create method of GrpcTransport to utilize ClientConfig's tls_config for creating secure gRPC channels if a custom factory is not provided.
  • src/a2a/performance.py
    • New file: Introduced functions to check uvloop availability and installation status.
    • Provided install_uvloop and uninstall_uvloop functions to manage the event loop policy.
    • Implemented run_with_uvloop for executing coroutines with uvloop and UvloopRunner as a context manager.
    • Added get_event_loop_optimization_info and optimize_event_loop for runtime information and automatic optimization.
  • src/a2a/validation.py
    • New file: Defined ValidationError for schema validation failures.
    • Implemented get_schema_for_type to generate JSON Schemas from Pydantic models.
    • Provided get_protocol_schemas, get_request_schemas, get_response_schemas, and get_event_schemas for schema retrieval.
    • Created validate_message, validate_request, and validate_response functions for message validation.
    • Introduced MessageValidator class for reusable and cached validation.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces significant and valuable enhancements to the A2A Python SDK, focusing on security with TLS/SSL support, performance via uvloop integration, and robustness through JSON Schema validation. The new modules (tls.py, performance.py, validation.py) are well-structured and the integration into the client configuration and factories is clean.

My review has identified a few areas for improvement:

  • In src/a2a/client/tls.py, the SSL context creation can be modernized to use newer, non-deprecated APIs for setting the minimum TLS version.
  • In src/a2a/validation.py, there is some duplicated code in the validate_request and validate_response functions that should be removed.
  • Also in validate_request, the error reporting can be improved to provide more context when validation fails.

Overall, this is a great set of changes that significantly improves the SDK's capabilities. Addressing these minor points will further enhance the code quality.

Comment on lines +268 to +281

errors: list[dict[str, Any]] = []

for model_type in request_types:
try:
return validate_message(data, model_type, strict=False)
except ValidationError:
continue

raise ValidationError(
'Data does not match any known A2A request type',
errors=errors,
instance=data,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This block of code is a duplicate of the preceding block (lines 255-267). This redundant code should be removed.

Comment on lines +315 to +325

for model_type in response_types:
try:
return validate_message(data, model_type, strict=False)
except ValidationError:
continue

raise ValidationError(
'Data does not match any known A2A response type',
instance=data,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This block of code is a duplicate of the preceding block (lines 305-314). This redundant code should be removed.

Comment on lines +57 to +63
protocol_map = {
'TLSv1_2': ssl.PROTOCOL_TLSv1_2,
'TLSv1_3': ssl.PROTOCOL_TLS_CLIENT,
}
protocol = protocol_map.get(self.min_version, ssl.PROTOCOL_TLS_CLIENT)

context = ssl.SSLContext(protocol)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation for setting the TLS protocol version uses a map with deprecated constants like ssl.PROTOCOL_TLSv1_2. A more modern and clearer approach for Python 3.10+ is to use ssl.PROTOCOL_TLS_CLIENT and set the minimum_version on the SSL context. This improves security configurability and code clarity.

Suggested change
protocol_map = {
'TLSv1_2': ssl.PROTOCOL_TLSv1_2,
'TLSv1_3': ssl.PROTOCOL_TLS_CLIENT,
}
protocol = protocol_map.get(self.min_version, ssl.PROTOCOL_TLS_CLIENT)
context = ssl.SSLContext(protocol)
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
version_map = {
'TLSv1_2': ssl.TLSVersion.TLSv1_2,
'TLSv1_3': ssl.TLSVersion.TLSv1_3,
}
if min_version_enum := version_map.get(self.min_version):
context.minimum_version = min_version_enum

Comment on lines +223 to +229
protocol_map = {
'TLSv1_2': ssl.PROTOCOL_TLSv1_2,
'TLSv1_3': ssl.PROTOCOL_TLS_SERVER,
}
protocol = protocol_map.get(min_version, ssl.PROTOCOL_TLS_SERVER)

context = ssl.SSLContext(protocol)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to create_ssl_context, this function uses a protocol map with deprecated constants. It's better to use ssl.PROTOCOL_TLS_SERVER and configure minimum_version for better clarity and to align with modern Python ssl module practices.

Suggested change
protocol_map = {
'TLSv1_2': ssl.PROTOCOL_TLSv1_2,
'TLSv1_3': ssl.PROTOCOL_TLS_SERVER,
}
protocol = protocol_map.get(min_version, ssl.PROTOCOL_TLS_SERVER)
context = ssl.SSLContext(protocol)
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
version_map = {
'TLSv1_2': ssl.TLSVersion.TLSv1_2,
'TLSv1_3': ssl.TLSVersion.TLSv1_3,
}
if min_version_enum := version_map.get(min_version):
context.minimum_version = min_version_enum

Comment on lines +257 to +261
for model_type in request_types:
try:
return validate_message(data, model_type, strict=False)
except ValidationError:
continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When validation against a specific model_type fails, the ValidationError is caught, but no information about the failure is collected. The errors list remains empty, which makes the final ValidationError less helpful for debugging. It would be beneficial to collect details about why each validation failed.

Suggested change
for model_type in request_types:
try:
return validate_message(data, model_type, strict=False)
except ValidationError:
continue
for model_type in request_types:
try:
return validate_message(data, model_type, strict=False)
except ValidationError as e:
errors.append({'type': model_type.__name__, 'message': str(e), 'details': e.errors})
continue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant