Skip to content

Commit 45904ac

Browse files
committed
fix: regenerate a2a_pydantic.py with ruff-compliant output
Generator improvements applied: - Single quotes in __all__ entries - Alphabetically sorted __all__ - Docstring trailing periods (PEP 257) - Deduplicated union types in oneof fields - Smart description quoting (double quotes when containing apostrophes) - isort-compliant import ordering (stdlib, third-party, local) - TYPE_CHECKING for datetime import with model_rebuild() - TYPE_CHECKING before Any in typing imports
1 parent 10a037b commit 45904ac

1 file changed

Lines changed: 72 additions & 64 deletions

File tree

src/a2a/types/a2a_pydantic.py

Lines changed: 72 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
from __future__ import annotations
44

5-
from datetime import datetime
65
from enum import Enum
6+
from typing import TYPE_CHECKING, Any
77

8-
from typing import Any
98

10-
from a2a._base import A2ABaseModel
9+
if TYPE_CHECKING:
10+
from datetime import datetime
11+
1112
from pydantic import Field, field_serializer
1213

14+
from a2a._base import A2ABaseModel
15+
1316

1417
class TaskState(str, Enum):
1518
"""Defines the possible lifecycle states of a `Task`."""
@@ -66,7 +69,7 @@ class SendMessageConfiguration(A2ABaseModel):
6669

6770
accepted_output_modes: list[str] | None = Field(default=None, description='A list of media types the client is prepared to accept for response parts. Agents SHOULD use this to tailor their output.')
6871
task_push_notification_config: TaskPushNotificationConfig = Field(default=None, description='Configuration for the agent to send push notifications for task updates. Task id should be empty when sending this configuration in a `SendMessage` request.')
69-
history_length: int | None = Field(default=None, description='The maximum number of most recent messages from the task\'s history to retrieve in the response. An unset value means the client does not impose any limit. A value of zero is a request to not include any messages. The server MUST NOT return more messages than the provided value, but MAY apply a lower limit.')
72+
history_length: int | None = Field(default=None, description="The maximum number of most recent messages from the task's history to retrieve in the response. An unset value means the client does not impose any limit. A value of zero is a request to not include any messages. The server MUST NOT return more messages than the provided value, but MAY apply a lower limit.")
7073
return_immediately: bool = Field(default=False, description='If `true`, the operation returns immediately after creating the task, even if processing is still in progress. If `false` (default), the operation MUST wait until the task reaches a terminal (`COMPLETED`, `FAILED`, `CANCELED`, `REJECTED`) or interrupted (`INPUT_REQUIRED`, `AUTH_REQUIRED`) state before returning.')
7174

7275
def to_proto_json(self) -> dict:
@@ -81,7 +84,7 @@ class Part(A2ABaseModel):
8184
metadata: dict[str, Any] = Field(default=None, description='Optional. metadata associated with this part.')
8285
filename: str = Field(default='', description='An optional `filename` for the file (e.g., "document.pdf").')
8386
media_type: str = Field(default='', description='The `media_type` (MIME type) of the part content (e.g., "text/plain", "application/json", "image/png"). This field is available for all part types.')
84-
content: str | bytes | str | Any | None = None
87+
content: str | bytes | Any | None = None
8588

8689

8790
def to_proto_json(self) -> dict:
@@ -109,7 +112,7 @@ def to_proto_json(self) -> dict:
109112

110113

111114
class TaskStatus(A2ABaseModel):
112-
"""A container for the status of a task"""
115+
"""A container for the status of a task."""
113116

114117
state: TaskState = Field(..., description='The current state of this task.')
115118
message: Message = Field(default=None, description='A message associated with the status.')
@@ -208,8 +211,8 @@ def to_proto_json(self) -> dict:
208211
class AgentProvider(A2ABaseModel):
209212
"""Represents the service provider of an agent."""
210213

211-
url: str = Field(..., description='A URL for the agent provider\'s website or relevant documentation. Example: "https://ai.google.dev"')
212-
organization: str = Field(..., description='The name of the agent provider\'s organization. Example: "Google"')
214+
url: str = Field(..., description="A URL for the agent provider's website or relevant documentation. Example: \"https://ai.google.dev\"")
215+
organization: str = Field(..., description="The name of the agent provider's organization. Example: \"Google\"")
213216

214217
def to_proto_json(self) -> dict:
215218
"""Serialize to a ProtoJSON-compatible dict (camelCase keys, no None values)."""
@@ -234,13 +237,13 @@ def to_proto_json(self) -> dict:
234237
class AgentSkill(A2ABaseModel):
235238
"""Represents a distinct capability or function that an agent can perform."""
236239

237-
id: str = Field(..., description='A unique identifier for the agent\'s skill.')
240+
id: str = Field(..., description="A unique identifier for the agent's skill.")
238241
name: str = Field(..., description='A human-readable name for the skill.')
239242
description: str = Field(..., description='A detailed description of the skill.')
240-
tags: list[str] = Field(..., description='A set of keywords describing the skill\'s capabilities.')
243+
tags: list[str] = Field(..., description="A set of keywords describing the skill's capabilities.")
241244
examples: list[str] | None = Field(default=None, description='Example prompts or scenarios that this skill can handle.')
242-
input_modes: list[str] | None = Field(default=None, description='The set of supported input media types for this skill, overriding the agent\'s defaults.')
243-
output_modes: list[str] | None = Field(default=None, description='The set of supported output media types for this skill, overriding the agent\'s defaults.')
245+
input_modes: list[str] | None = Field(default=None, description="The set of supported input media types for this skill, overriding the agent's defaults.")
246+
output_modes: list[str] | None = Field(default=None, description="The set of supported output media types for this skill, overriding the agent's defaults.")
244247
security_requirements: list[SecurityRequirement] | None = Field(default=None, description='Security schemes necessary for this skill.')
245248

246249
def to_proto_json(self) -> dict:
@@ -250,7 +253,7 @@ def to_proto_json(self) -> dict:
250253

251254

252255
class AgentCard(A2ABaseModel):
253-
"""A self-describing manifest for an agent. It provides essential metadata including the agent's identity, capabilities, skills, supported communication methods, and security requirements. Next ID: 20"""
256+
"""A self-describing manifest for an agent. It provides essential metadata including the agent's identity, capabilities, skills, supported communication methods, and security requirements. Next ID: 20."""
254257

255258
name: str = Field(..., description='A human readable name for the agent. Example: "Recipe Agent"')
256259
description: str = Field(..., description='A human-readable description of the agent, assisting users and other agents in understanding its purpose. Example: "Agent that helps users with recipes and cooking."')
@@ -278,7 +281,7 @@ class AgentExtension(A2ABaseModel):
278281

279282
uri: str = Field(default='', description='The unique URI identifying the extension.')
280283
description: str = Field(default='', description='A human-readable description of how this agent uses the extension.')
281-
required: bool = Field(default=False, description='If true, the client must understand and comply with the extension\'s requirements.')
284+
required: bool = Field(default=False, description="If true, the client must understand and comply with the extension's requirements.")
282285
params: dict[str, Any] = Field(default=None, description='Optional. Extension-specific configuration parameters.')
283286

284287
def to_proto_json(self) -> dict:
@@ -323,7 +326,7 @@ def to_proto_json(self) -> dict:
323326

324327

325328
class SecurityScheme(A2ABaseModel):
326-
"""Defines a security scheme that can be used to secure an agent's endpoints. This is a discriminated union type based on the OpenAPI 3.2 Security Scheme Object. See: https://spec.openapis.org/oas/v3.2.0.html#security-scheme-object"""
329+
"""Defines a security scheme that can be used to secure an agent's endpoints. This is a discriminated union type based on the OpenAPI 3.2 Security Scheme Object. See: https://spec.openapis.org/oas/v3.2.0.html#security-scheme-object."""
327330

328331
scheme: APIKeySecurityScheme | HTTPAuthSecurityScheme | OAuth2SecurityScheme | OpenIdConnectSecurityScheme | MutualTlsSecurityScheme | None = None
329332

@@ -389,7 +392,7 @@ class OpenIdConnectSecurityScheme(A2ABaseModel):
389392
"""Defines a security scheme using OpenID Connect."""
390393

391394
description: str = Field(default='', description='An optional description for the security scheme.')
392-
open_id_connect_url: str = Field(..., description='The [OpenID Connect Discovery URL](https://openid.net/specs/openid-connect-discovery-1_0.html) for the OIDC provider\'s metadata.')
395+
open_id_connect_url: str = Field(..., description="The [OpenID Connect Discovery URL](https://openid.net/specs/openid-connect-discovery-1_0.html) for the OIDC provider's metadata.")
393396

394397
def to_proto_json(self) -> dict:
395398
"""Serialize to a ProtoJSON-compatible dict (camelCase keys, no None values)."""
@@ -495,7 +498,7 @@ class GetTaskRequest(A2ABaseModel):
495498

496499
tenant: str = Field(default='', description='Optional. Tenant ID, provided as a path parameter.')
497500
id: str = Field(..., description='The resource ID of the task to retrieve.')
498-
history_length: int | None = Field(default=None, description='The maximum number of most recent messages from the task\'s history to retrieve. An unset value means the client does not impose any limit. A value of zero is a request to not include any messages. The server MUST NOT return more messages than the provided value, but MAY apply a lower limit.')
501+
history_length: int | None = Field(default=None, description="The maximum number of most recent messages from the task's history to retrieve. An unset value means the client does not impose any limit. A value of zero is a request to not include any messages. The server MUST NOT return more messages than the provided value, but MAY apply a lower limit.")
499502

500503
def to_proto_json(self) -> dict:
501504
"""Serialize to a ProtoJSON-compatible dict (camelCase keys, no None values)."""
@@ -511,7 +514,7 @@ class ListTasksRequest(A2ABaseModel):
511514
status: TaskState = Field(default=None, description='Filter tasks by their current status state.')
512515
page_size: int | None = Field(default=None, description='The maximum number of tasks to return. The service may return fewer than this value. If unspecified, at most 50 tasks will be returned. The minimum value is 1. The maximum value is 100.')
513516
page_token: str = Field(default='', description='A page token, received from a previous `ListTasks` call. `ListTasksResponse.next_page_token`. Provide this to retrieve the subsequent page.')
514-
history_length: int | None = Field(default=None, description='The maximum number of messages to include in each task\'s history.')
517+
history_length: int | None = Field(default=None, description="The maximum number of messages to include in each task's history.")
515518
status_timestamp_after: datetime = Field(default=None, description='Filter tasks which have a status updated after the provided timestamp in ISO 8601 format (e.g., "2023-10-27T10:00:00Z"). Only tasks with a status timestamp time greater than or equal to this value will be returned.')
516519
include_artifacts: bool | None = Field(default=None, description='Whether to include artifacts in the returned tasks. Defaults to false to reduce payload size.')
517520

@@ -657,50 +660,55 @@ def to_proto_json(self) -> dict:
657660

658661

659662
__all__ = [
660-
"TaskState",
661-
"Role",
662-
"AuthenticationInfo",
663-
"TaskPushNotificationConfig",
664-
"SendMessageConfiguration",
665-
"Part",
666-
"Message",
667-
"TaskStatus",
668-
"Task",
669-
"Artifact",
670-
"TaskStatusUpdateEvent",
671-
"TaskArtifactUpdateEvent",
672-
"AgentInterface",
673-
"AgentProvider",
674-
"AgentCapabilities",
675-
"AgentSkill",
676-
"AgentCard",
677-
"AgentExtension",
678-
"AgentCardSignature",
679-
"StringList",
680-
"SecurityRequirement",
681-
"SecurityScheme",
682-
"APIKeySecurityScheme",
683-
"HTTPAuthSecurityScheme",
684-
"OAuthFlows",
685-
"OAuth2SecurityScheme",
686-
"OpenIdConnectSecurityScheme",
687-
"MutualTlsSecurityScheme",
688-
"AuthorizationCodeOAuthFlow",
689-
"ClientCredentialsOAuthFlow",
690-
"ImplicitOAuthFlow",
691-
"PasswordOAuthFlow",
692-
"DeviceCodeOAuthFlow",
693-
"SendMessageRequest",
694-
"GetTaskRequest",
695-
"ListTasksRequest",
696-
"ListTasksResponse",
697-
"CancelTaskRequest",
698-
"GetTaskPushNotificationConfigRequest",
699-
"DeleteTaskPushNotificationConfigRequest",
700-
"SubscribeToTaskRequest",
701-
"ListTaskPushNotificationConfigsRequest",
702-
"GetExtendedAgentCardRequest",
703-
"SendMessageResponse",
704-
"StreamResponse",
705-
"ListTaskPushNotificationConfigsResponse",
663+
'APIKeySecurityScheme',
664+
'AgentCapabilities',
665+
'AgentCard',
666+
'AgentCardSignature',
667+
'AgentExtension',
668+
'AgentInterface',
669+
'AgentProvider',
670+
'AgentSkill',
671+
'Artifact',
672+
'AuthenticationInfo',
673+
'AuthorizationCodeOAuthFlow',
674+
'CancelTaskRequest',
675+
'ClientCredentialsOAuthFlow',
676+
'DeleteTaskPushNotificationConfigRequest',
677+
'DeviceCodeOAuthFlow',
678+
'GetExtendedAgentCardRequest',
679+
'GetTaskPushNotificationConfigRequest',
680+
'GetTaskRequest',
681+
'HTTPAuthSecurityScheme',
682+
'ImplicitOAuthFlow',
683+
'ListTaskPushNotificationConfigsRequest',
684+
'ListTaskPushNotificationConfigsResponse',
685+
'ListTasksRequest',
686+
'ListTasksResponse',
687+
'Message',
688+
'MutualTlsSecurityScheme',
689+
'OAuth2SecurityScheme',
690+
'OAuthFlows',
691+
'OpenIdConnectSecurityScheme',
692+
'Part',
693+
'PasswordOAuthFlow',
694+
'Role',
695+
'SecurityRequirement',
696+
'SecurityScheme',
697+
'SendMessageConfiguration',
698+
'SendMessageRequest',
699+
'SendMessageResponse',
700+
'StreamResponse',
701+
'StringList',
702+
'SubscribeToTaskRequest',
703+
'Task',
704+
'TaskArtifactUpdateEvent',
705+
'TaskPushNotificationConfig',
706+
'TaskState',
707+
'TaskStatus',
708+
'TaskStatusUpdateEvent',
706709
]
710+
711+
712+
# Rebuild models that use TYPE_CHECKING imports (forward references)
713+
TaskStatus.model_rebuild()
714+
ListTasksRequest.model_rebuild()

0 commit comments

Comments
 (0)