Pick the most specific A2ATaskArtifactUpdate subclass for an update.
Returns A2ATextArtifact for text-only artifacts, A2AToolCallArtifact for AG2 tool-call+json extension parts, and the base A2ATaskArtifactUpdate for any other shape.
Source code in autogen/beta/a2a/mappers/events.py
| def parse_artifact_update(update: TaskArtifactUpdateEvent) -> A2ATaskArtifactUpdate:
"""Pick the most specific ``A2ATaskArtifactUpdate`` subclass for an update.
Returns ``A2ATextArtifact`` for text-only artifacts, ``A2AToolCallArtifact``
for AG2 ``tool-call+json`` extension parts, and the base
``A2ATaskArtifactUpdate`` for any other shape.
"""
artifact = update.artifact
parts = list(artifact.parts)
text_only = parts and all(bool(p.text) for p in parts)
if text_only:
return A2ATextArtifact(
update=update,
append=update.append,
last_chunk=update.last_chunk,
text="".join(p.text for p in parts),
)
if len(parts) == 1 and is_data_part_with_mime(parts[0], MIME_TOOL_CALL):
return A2AToolCallArtifact(
update=update,
append=update.append,
last_chunk=update.last_chunk,
call=payload_to_call(part_data_to_python(parts[0])),
)
return A2ATaskArtifactUpdate(
update=update,
append=update.append,
last_chunk=update.last_chunk,
)
|