Skip to content

Commit 538a326

Browse files
Python: Use the last entry in the task history to avoid empty responses (microsoft#2101)
* Use the last entry in the task history to avoid empty responses * History only contains Messages
1 parent 07037d7 commit 538a326

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

  • python/packages/a2a/agent_framework_a2a

python/packages/a2a/agent_framework_a2a/_agent.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,17 @@ def _task_to_chat_messages(self, task: Task) -> list[ChatMessage]:
388388
if task.artifacts is not None:
389389
for artifact in task.artifacts:
390390
messages.append(self._artifact_to_chat_message(artifact))
391+
elif task.history is not None and len(task.history) > 0:
392+
# Include the last history item as the agent response
393+
history_item = task.history[-1]
394+
contents = self._a2a_parts_to_contents(history_item.parts)
395+
messages.append(
396+
ChatMessage(
397+
role=Role.ASSISTANT if history_item.role == A2ARole.agent else Role.USER,
398+
contents=contents,
399+
raw_representation=history_item,
400+
)
401+
)
391402

392403
return messages
393404

0 commit comments

Comments
 (0)