From fe77913964d3de0590c681fe3e8557fc6413c95e Mon Sep 17 00:00:00 2001 From: markwallace-microsoft <127216156+markwallace-microsoft@users.noreply.github.com> Date: Tue, 11 Nov 2025 22:14:43 +0000 Subject: [PATCH 1/2] Use the last entry in the task history to avoid empty responses --- python/packages/a2a/agent_framework_a2a/_agent.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/packages/a2a/agent_framework_a2a/_agent.py b/python/packages/a2a/agent_framework_a2a/_agent.py index 68694e3db4..03295129dd 100644 --- a/python/packages/a2a/agent_framework_a2a/_agent.py +++ b/python/packages/a2a/agent_framework_a2a/_agent.py @@ -388,6 +388,18 @@ def _task_to_chat_messages(self, task: Task) -> list[ChatMessage]: if task.artifacts is not None: for artifact in task.artifacts: messages.append(self._artifact_to_chat_message(artifact)) + elif task.history is not None and len(task.history) > 0: + # Include the last history item as the agent response + history_item = task.history[-1] + if isinstance(history_item, Message): + contents = self._a2a_parts_to_contents(history_item.parts) + messages.append( + ChatMessage( + role=Role.ASSISTANT if history_item.role == A2ARole.agent else Role.USER, + contents=contents, + raw_representation=history_item, + ) + ) return messages From 24fb394303c68dd50bc93418eb4754a0cbf331e5 Mon Sep 17 00:00:00 2001 From: markwallace-microsoft <127216156+markwallace-microsoft@users.noreply.github.com> Date: Tue, 11 Nov 2025 22:45:49 +0000 Subject: [PATCH 2/2] History only contains Messages --- python/packages/a2a/agent_framework_a2a/_agent.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/python/packages/a2a/agent_framework_a2a/_agent.py b/python/packages/a2a/agent_framework_a2a/_agent.py index 03295129dd..7fe4649a65 100644 --- a/python/packages/a2a/agent_framework_a2a/_agent.py +++ b/python/packages/a2a/agent_framework_a2a/_agent.py @@ -391,15 +391,14 @@ def _task_to_chat_messages(self, task: Task) -> list[ChatMessage]: elif task.history is not None and len(task.history) > 0: # Include the last history item as the agent response history_item = task.history[-1] - if isinstance(history_item, Message): - contents = self._a2a_parts_to_contents(history_item.parts) - messages.append( - ChatMessage( - role=Role.ASSISTANT if history_item.role == A2ARole.agent else Role.USER, - contents=contents, - raw_representation=history_item, - ) + contents = self._a2a_parts_to_contents(history_item.parts) + messages.append( + ChatMessage( + role=Role.ASSISTANT if history_item.role == A2ARole.agent else Role.USER, + contents=contents, + raw_representation=history_item, ) + ) return messages