Skip to content
Open
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
5 changes: 4 additions & 1 deletion src/google/adk/a2a/converters/from_adk_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ def convert_event_to_a2a_events(

artifact_id = agents_artifacts.get(agent_name)
if artifact_id:
append = partial
# A prior chunk already created this artifact (append=False), so
# every subsequent chunk -- including the final, non-partial one --
# must append rather than replace it.
append = True
if not partial:
del agents_artifacts[agent_name]
else:
Expand Down
38 changes: 38 additions & 0 deletions tests/unittests/a2a/converters/test_from_adk.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,44 @@ def test_convert_event_to_a2a_events_artifact_update(self):
assert result[0].artifact.parts == [mock_a2a_part]
assert "agent-1" in agents_artifacts # Artifact ID should be stored

def test_convert_event_to_a2a_events_final_chunk_appends(self):
"""The final (non-partial) chunk of a stream must still append, not

replace, the artifact created by the first chunk.
"""
self.mock_event.content = genai_types.Content(
parts=[genai_types.Part(text="hello")], role="model"
)
self.mock_event.author = "agent-1"
self.mock_event.partial = True

agents_artifacts = {}
mock_convert_part = Mock(return_value=[_compat.make_text_part("hello")])

first = convert_event_to_a2a_events(
self.mock_event,
agents_artifacts,
task_id="task-123",
context_id="context-456",
part_converter=mock_convert_part,
)
assert first[0].append is False
artifact_id = first[0].artifact.artifact_id
assert agents_artifacts["agent-1"] == artifact_id

self.mock_event.partial = False
final = convert_event_to_a2a_events(
self.mock_event,
agents_artifacts,
task_id="task-123",
context_id="context-456",
part_converter=mock_convert_part,
)

assert final[0].append is True
assert final[0].artifact.artifact_id == artifact_id
assert "agent-1" not in agents_artifacts

def test_convert_event_to_a2a_events_error(self):
"""Test conversion of event with error to TaskStatusUpdateEvent."""
self.mock_event.error_code = "ERR001"
Expand Down