|
| 1 | +# A2A Protocol Backward Compatibility (v0.3) |
| 2 | + |
| 3 | +This directory (`src/a2a/compat/v0_3/`) provides the foundational types and translation layers necessary for modern `v1.0` clients and servers to interoperate with legacy `v0.3` A2A systems. |
| 4 | + |
| 5 | +## Data Representations |
| 6 | + |
| 7 | +To support cross-version compatibility across JSON, REST, and gRPC, this directory manages three distinct data representations: |
| 8 | + |
| 9 | +### 1. Legacy v0.3 Pydantic Models (`types.py`) |
| 10 | +This file contains Python [Pydantic](https://docs.pydantic.dev/) models generated from the legacy v0.3 JSON schema. |
| 11 | +* **Purpose**: This is the "pivot" format. Legacy JSON-RPC and REST implementations natively serialize to/from these models. It acts as the intermediary between old wire formats and the modern SDK. |
| 12 | + |
| 13 | +### 2. Legacy v0.3 Protobuf Bindings (`a2a_v0_3_pb2.py`) |
| 14 | +This module contains the native Protobuf bindings for the legacy v0.3 gRPC protocol. |
| 15 | +* **Purpose**: To decode incoming bytes from legacy gRPC clients or encode outbound bytes to legacy gRPC servers. |
| 16 | +* **Note**: It is generated into the `a2a.v1` package namespace. |
| 17 | + |
| 18 | +### 3. Current v1.0 Protobuf Bindings (`a2a.types.a2a_pb2`) |
| 19 | +This is the central source of truth for the modern SDK (`v1.0`). All legacy payloads must ultimately be translated into these `v1.0` core objects to be processed by the modern `AgentExecutor`. |
| 20 | +* **Note**: It is generated into the `lf.a2a.v1` package namespace. |
| 21 | +--- |
| 22 | + |
| 23 | +## Transformation Utilities |
| 24 | + |
| 25 | +Payloads arriving from legacy clients undergo a phased transformation to bridge the gap between versions. |
| 26 | + |
| 27 | +### Legacy gRPC ↔ Legacy Pydantic: `proto_utils.py` |
| 28 | +This module handles the mapping between legacy `v0.3` gRPC Protobuf objects and legacy `v0.3` Pydantic models. |
| 29 | +This is a copy of the `a2a.types.proto_utils` module from 0.3 release. |
| 30 | + |
| 31 | +```python |
| 32 | +from a2a.compat.v0_3 import a2a_v0_3_pb2 |
| 33 | +from a2a.compat.v0_3 import types as types_v03 |
| 34 | +from a2a.compat.v0_3 import proto_utils |
| 35 | + |
| 36 | +# 1. Receive legacy bytes over the wire |
| 37 | +legacy_pb_msg = a2a_v0_3_pb2.Message() |
| 38 | +legacy_pb_msg.ParseFromString(wire_bytes) |
| 39 | + |
| 40 | +# 2. Convert to intermediate Pydantic representation |
| 41 | +pydantic_msg: types_v03.Message = proto_utils.FromProto.message(legacy_pb_msg) |
| 42 | +``` |
| 43 | + |
| 44 | +### Legacy Pydantic ↔ Modern v1.0 Protobuf: `conversions.py` |
| 45 | +This module structurally translates between legacy `v0.3` Pydantic objects and modern `v1.0` Core Protobufs. |
| 46 | + |
| 47 | +```python |
| 48 | +from a2a.types import a2a_pb2 as pb2_v10 |
| 49 | +from a2a.compat.v0_3 import conversions |
| 50 | + |
| 51 | +# 3. Convert the legacy Pydantic object into a modern v1.0 Protobuf |
| 52 | +core_pb_msg: pb2_v10.Message = conversions.to_core_message(pydantic_msg) |
| 53 | + |
| 54 | +``` |
0 commit comments