Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
python-version-file: .python-version
- name: Install uv
uses: astral-sh/setup-uv@v6
uses: astral-sh/setup-uv@v7
- name: Add uv to PATH
run: |
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v5

- name: Install uv
uses: astral-sh/setup-uv@v6
uses: astral-sh/setup-uv@v7

- name: "Set up Python"
uses: actions/setup-python@v6
Expand All @@ -26,7 +26,7 @@ jobs:
run: uv build

- name: Upload distributions
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: release-dists
path: dist/
Expand All @@ -40,7 +40,7 @@ jobs:

steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v5
uses: actions/download-artifact@v6
with:
name: release-dists
path: dist/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
echo "MYSQL_TEST_DSN=mysql+aiomysql://a2a:a2a_password@localhost:3306/a2a_test" >> $GITHUB_ENV
- name: Install uv for Python ${{ matrix.python-version }}
uses: astral-sh/setup-uv@v6
uses: astral-sh/setup-uv@v7
with:
python-version: ${{ matrix.python-version }}
- name: Add uv to PATH
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-a2a-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
python-version: '3.10'
- name: Install uv
uses: astral-sh/setup-uv@v6
uses: astral-sh/setup-uv@v7
- name: Configure uv shell
run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Install dependencies (datamodel-code-generator)
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [0.3.12](https://github.com/a2aproject/a2a-python/compare/v0.3.11...v0.3.12) (2025-11-12)


### Bug Fixes

* **grpc:** Add `extensions` to `Artifact` converters. ([#523](https://github.com/a2aproject/a2a-python/issues/523)) ([c03129b](https://github.com/a2aproject/a2a-python/commit/c03129b99a663ae1f1ae72f20e4ead7807ede941))

## [0.3.11](https://github.com/a2aproject/a2a-python/compare/v0.3.10...v0.3.11) (2025-11-07)


### Bug Fixes

* add metadata to send message request ([12b4a1d](https://github.com/a2aproject/a2a-python/commit/12b4a1d565a53794f5b55c8bd1728221c906ed41))

## [0.3.10](https://github.com/a2aproject/a2a-python/compare/v0.3.9...v0.3.10) (2025-10-21)


Expand Down
89 changes: 78 additions & 11 deletions scripts/generate_types.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,105 @@
# Treat unset variables as an error.
set -euo pipefail

REMOTE_URL="https://raw.githubusercontent.com/a2aproject/A2A/refs/heads/main/specification/json/a2a.json"
# A2A specification version to use
# Can be overridden via environment variable: A2A_SPEC_VERSION=v1.2.0 ./generate_types.sh
# Or via command-line flag: ./generate_types.sh --version v1.2.0 output.py
# Use a specific git tag, branch name, or commit SHA
# Examples: "v1.0.0", "v1.2.0", "main", "abc123def"
A2A_SPEC_VERSION="${A2A_SPEC_VERSION:-v0.3.0}"

# Build URL based on version format
# Tags use /refs/tags/, branches use /refs/heads/, commits use direct ref
build_remote_url() {
local version="$1"
local base_url="https://raw.githubusercontent.com/a2aproject/A2A"
local spec_path="specification/json/a2a.json"
local url_part

if [[ "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# Looks like a version tag (v1.0.0, v1.2.3)
url_part="refs/tags/${version}"
elif [[ "$version" =~ ^[0-9a-f]{7,40}$ ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Git commit SHAs are case-insensitive, though they are usually represented in lowercase. It would be more robust to allow uppercase hex characters in the regex to handle SHAs that might contain them.

Suggested change
elif [[ "$version" =~ ^[0-9a-f]{7,40}$ ]]; then
elif [[ "$version" =~ ^[0-9a-fA-F]{7,40}$ ]]; then

# Looks like a commit SHA (7+ hex chars)
url_part="${version}"
else
# Assume it's a branch name (main, develop, etc.)
url_part="refs/heads/${version}"
fi
echo "${base_url}/${url_part}/${spec_path}"
}

REMOTE_URL=$(build_remote_url "$A2A_SPEC_VERSION")

GENERATED_FILE=""
INPUT_FILE=""

# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--input-file)
INPUT_FILE="$2"
shift 2
;;
*)
GENERATED_FILE="$1"
shift 1
;;
--input-file)
INPUT_FILE="$2"
shift 2
;;
--version)
A2A_SPEC_VERSION="$2"
REMOTE_URL=$(build_remote_url "$A2A_SPEC_VERSION")
shift 2
;;
*)
GENERATED_FILE="$1"
shift 1
;;
esac
done

if [ -z "$GENERATED_FILE" ]; then
echo "Error: Output file path must be provided." >&2
echo "Usage: $0 [--input-file <path>] <output-file-path>"
cat >&2 <<EOF
Error: Output file path must be provided.
Usage: $0 [--input-file <path>] [--version <version>] <output-file-path>
Options:
--input-file <path> Use a local JSON schema file instead of fetching from remote
--version <version> Specify A2A spec version (default: v0.3.0)
Can be a git tag (v1.0.0), branch (main), or commit SHA
Environment variables:
A2A_SPEC_VERSION Override default spec version
Examples:
$0 src/a2a/types.py
$0 --version v1.2.0 src/a2a/types.py
$0 --input-file local/a2a.json src/a2a/types.py
A2A_SPEC_VERSION=main $0 src/a2a/types.py
EOF
exit 1
fi

echo "Running datamodel-codegen..."
declare -a source_args
if [ -n "$INPUT_FILE" ]; then
echo " - Source File: $INPUT_FILE"
if [ ! -f "$INPUT_FILE" ]; then
echo "Error: Input file does not exist: $INPUT_FILE" >&2
exit 1
fi
source_args=("--input" "$INPUT_FILE")
else
echo " - A2A Spec Version: $A2A_SPEC_VERSION"
echo " - Source URL: $REMOTE_URL"

# Validate that the remote URL is accessible
echo " - Validating remote URL..."
if ! curl --fail --silent --head "$REMOTE_URL" >/dev/null 2>&1; then
cat >&2 <<EOF
Error: Unable to access A2A specification at version '$A2A_SPEC_VERSION'
URL: $REMOTE_URL
The version may not exist. Available versions can be found at:
https://github.com/a2aproject/A2A/tags
EOF
exit 1
fi

source_args=("--url" "$REMOTE_URL")
fi
echo " - Output File: $GENERATED_FILE"
Expand Down
7 changes: 6 additions & 1 deletion src/a2a/client/base_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections.abc import AsyncIterator
from typing import Any

from a2a.client.client import (
Client,
Expand Down Expand Up @@ -47,6 +48,7 @@ async def send_message(
request: Message,
*,
context: ClientCallContext | None = None,
request_metadata: dict[str, Any] | None = None,
) -> AsyncIterator[ClientEvent | Message]:
"""Sends a message to the agent.

Expand All @@ -57,6 +59,7 @@ async def send_message(
Args:
request: The message to send to the agent.
context: The client call context.
request_metadata: Extensions Metadata attached to the request.

Yields:
An async iterator of `ClientEvent` or a final `Message` response.
Expand All @@ -70,7 +73,9 @@ async def send_message(
else None
),
)
params = MessageSendParams(message=request, configuration=config)
params = MessageSendParams(
message=request, configuration=config, metadata=request_metadata
)

if not self._config.streaming or not self._card.capabilities.streaming:
response = await self._transport.send_message(
Expand Down
1 change: 1 addition & 0 deletions src/a2a/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ async def send_message(
request: Message,
*,
context: ClientCallContext | None = None,
request_metadata: dict[str, Any] | None = None,
) -> AsyncIterator[ClientEvent | Message]:
"""Sends a message to the server.

Expand Down
5 changes: 4 additions & 1 deletion src/a2a/utils/proto_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def make_dict_serializable(value: Any) -> Any:
Returns:
A serializable value.
"""
if isinstance(value, (str, int, float, bool)) or value is None:
if isinstance(value, str | int | float | bool) or value is None:
return value
if isinstance(value, dict):
return {k: make_dict_serializable(v) for k, v in value.items()}
Expand Down Expand Up @@ -140,6 +140,7 @@ def message(cls, message: types.Message | None) -> a2a_pb2.Message | None:
task_id=message.task_id or '',
role=cls.role(message.role),
metadata=cls.metadata(message.metadata),
extensions=message.extensions or [],
)

@classmethod
Expand Down Expand Up @@ -239,6 +240,7 @@ def artifact(cls, artifact: types.Artifact) -> a2a_pb2.Artifact:
metadata=cls.metadata(artifact.metadata),
name=artifact.name,
parts=[cls.part(p) for p in artifact.parts],
extensions=artifact.extensions or [],
)

@classmethod
Expand Down Expand Up @@ -695,6 +697,7 @@ def artifact(cls, artifact: a2a_pb2.Artifact) -> types.Artifact:
metadata=cls.metadata(artifact.metadata),
name=artifact.name,
parts=[cls.part(p) for p in artifact.parts],
extensions=artifact.extensions or None,
)

@classmethod
Expand Down
12 changes: 10 additions & 2 deletions tests/client/test_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,14 @@ async def create_stream(*args, **kwargs):

mock_transport.send_message_streaming.return_value = create_stream()

events = [event async for event in base_client.send_message(sample_message)]
meta = {'test': 1}
stream = base_client.send_message(sample_message, request_metadata=meta)
events = [event async for event in stream]

mock_transport.send_message_streaming.assert_called_once()
assert (
mock_transport.send_message_streaming.call_args[0][0].metadata == meta
)
assert not mock_transport.send_message.called
assert len(events) == 1
assert events[0][0].id == 'task-123'
Expand All @@ -92,9 +97,12 @@ async def test_send_message_non_streaming(
status=TaskStatus(state=TaskState.completed),
)

events = [event async for event in base_client.send_message(sample_message)]
meta = {'test': 1}
stream = base_client.send_message(sample_message, request_metadata=meta)
events = [event async for event in stream]

mock_transport.send_message.assert_called_once()
assert mock_transport.send_message.call_args[0][0].metadata == meta
assert not mock_transport.send_message_streaming.called
assert len(events) == 1
assert events[0][0].id == 'task-456'
Expand Down
Loading