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
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# Changelog
# Changelog

## [0.3.17](https://github.com/a2aproject/a2a-python/compare/v0.3.16...v0.3.17) (2025-11-24)


### Features

* **client:** allow specifying `history_length` via call-site `MessageSendConfiguration` in `BaseClient.send_message` ([53bbf7a](https://github.com/a2aproject/a2a-python/commit/53bbf7ae3ad58fb0c10b14da05cf07c0a7bd9651))

## [0.3.16](https://github.com/a2aproject/a2a-python/compare/v0.3.15...v0.3.16) (2025-11-21)


### Bug Fixes

* Ensure metadata propagation for `Task` `ToProto` and `FromProto` conversion ([#557](https://github.com/a2aproject/a2a-python/issues/557)) ([fc31d03](https://github.com/a2aproject/a2a-python/commit/fc31d03e8c6acb68660f6d1924262e16933c5d50))

## [0.3.15](https://github.com/a2aproject/a2a-python/compare/v0.3.14...v0.3.15) (2025-11-19)

Expand Down
13 changes: 12 additions & 1 deletion src/a2a/client/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ async def send_message(
self,
request: Message,
*,
configuration: MessageSendConfiguration | None = None,
context: ClientCallContext | None = None,
request_metadata: dict[str, Any] | None = None,
extensions: list[str] | None = None,
Expand All @@ -59,14 +60,15 @@ async def send_message(

Args:
request: The message to send to the agent.
configuration: Optional per-call overrides for message sending behavior.
context: The client call context.
request_metadata: Extensions Metadata attached to the request.
extensions: List of extensions to be activated.

Yields:
An async iterator of `ClientEvent` or a final `Message` response.
"""
config = MessageSendConfiguration(
base_config = MessageSendConfiguration(
accepted_output_modes=self._config.accepted_output_modes,
blocking=not self._config.polling,
push_notification_config=(
Expand All @@ -75,6 +77,15 @@ async def send_message(
else None
),
)
if configuration is not None:
update_data = configuration.model_dump(
exclude_unset=True,
by_alias=False,
)
config = base_config.model_copy(update=update_data)
else:
config = base_config

params = MessageSendParams(
message=request, configuration=config, metadata=request_metadata
)
Expand Down
2 changes: 2 additions & 0 deletions src/a2a/utils/proto_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def task(cls, task: types.Task) -> a2a_pb2.Task:
if task.history
else None
),
metadata=cls.metadata(task.metadata),
)

@classmethod
Expand Down Expand Up @@ -660,6 +661,7 @@ def task(cls, task: a2a_pb2.Task) -> types.Task:
status=cls.task_status(task.status),
artifacts=[cls.artifact(a) for a in task.artifacts],
history=[cls.message(h) for h in task.history],
metadata=cls.metadata(task.metadata),
)

@classmethod
Expand Down
76 changes: 76 additions & 0 deletions tests/client/test_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
AgentCapabilities,
AgentCard,
Message,
MessageSendConfiguration,
Part,
Role,
Task,
Expand Down Expand Up @@ -125,3 +126,78 @@ async def test_send_message_non_streaming_agent_capability_false(
assert not mock_transport.send_message_streaming.called
assert len(events) == 1
assert events[0][0].id == 'task-789'


@pytest.mark.asyncio
async def test_send_message_callsite_config_overrides_non_streaming(
base_client: BaseClient, mock_transport: MagicMock, sample_message: Message
):
base_client._config.streaming = False
mock_transport.send_message.return_value = Task(
id='task-cfg-ns-1',
context_id='ctx-cfg-ns-1',
status=TaskStatus(state=TaskState.completed),
)

cfg = MessageSendConfiguration(
history_length=2,
blocking=False,
accepted_output_modes=['application/json'],
)
events = [
event
async for event in base_client.send_message(
sample_message, configuration=cfg
)
]

mock_transport.send_message.assert_called_once()
assert not mock_transport.send_message_streaming.called
assert len(events) == 1
task, _ = events[0]
assert task.id == 'task-cfg-ns-1'

params = mock_transport.send_message.call_args[0][0]
assert params.configuration.history_length == 2
assert params.configuration.blocking is False
assert params.configuration.accepted_output_modes == ['application/json']


@pytest.mark.asyncio
async def test_send_message_callsite_config_overrides_streaming(
base_client: BaseClient, mock_transport: MagicMock, sample_message: Message
):
base_client._config.streaming = True
base_client._card.capabilities.streaming = True

async def create_stream(*args, **kwargs):
yield Task(
id='task-cfg-s-1',
context_id='ctx-cfg-s-1',
status=TaskStatus(state=TaskState.completed),
)

mock_transport.send_message_streaming.return_value = create_stream()

cfg = MessageSendConfiguration(
history_length=0,
blocking=True,
accepted_output_modes=['text/plain'],
)
events = [
event
async for event in base_client.send_message(
sample_message, configuration=cfg
)
]

mock_transport.send_message_streaming.assert_called_once()
assert not mock_transport.send_message.called
assert len(events) == 1
task, _ = events[0]
assert task.id == 'task-cfg-s-1'

params = mock_transport.send_message_streaming.call_args[0][0]
assert params.configuration.history_length == 0
assert params.configuration.blocking is True
assert params.configuration.accepted_output_modes == ['text/plain']
28 changes: 28 additions & 0 deletions tests/utils/test_proto_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def sample_task(sample_message: types.Message) -> types.Task:
],
)
],
metadata={'source': 'test'},
)


Expand Down Expand Up @@ -508,3 +509,30 @@ def test_large_integer_roundtrip_with_utilities(self):
assert final_result['nested']['another_large'] == 12345678901234567890
assert isinstance(final_result['nested']['another_large'], int)
assert final_result['nested']['normal'] == 'text'

def test_task_conversion_roundtrip(
self, sample_task: types.Task, sample_message: types.Message
):
"""Test conversion of Task to proto and back."""
proto_task = proto_utils.ToProto.task(sample_task)
assert isinstance(proto_task, a2a_pb2.Task)

roundtrip_task = proto_utils.FromProto.task(proto_task)
assert roundtrip_task.id == 'task-1'
assert roundtrip_task.context_id == 'ctx-1'
assert roundtrip_task.status == types.TaskStatus(
state=types.TaskState.working, message=sample_message
)
assert roundtrip_task.history == [sample_message]
assert roundtrip_task.artifacts == [
types.Artifact(
artifact_id='art-1',
description='',
metadata={},
name='',
parts=[
types.Part(root=types.TextPart(text='Artifact content'))
],
)
]
assert roundtrip_task.metadata == {'source': 'test'}
Loading