File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1717 create_task_obj ,
1818)
1919from a2a .utils .message import (
20+ get_data_parts ,
21+ get_file_parts ,
2022 get_message_text ,
2123 get_text_parts ,
2224 new_agent_parts_message ,
3739 'build_text_artifact' ,
3840 'completed_task' ,
3941 'create_task_obj' ,
42+ 'get_data_parts' ,
43+ 'get_file_parts' ,
4044 'get_message_text' ,
4145 'get_text_parts' ,
4246 'new_agent_parts_message' ,
Original file line number Diff line number Diff line change 22
33import uuid
44
5+ from typing import Any
6+
57from a2a .types import (
8+ DataPart ,
9+ FilePart ,
10+ FileWithBytes ,
11+ FileWithUri ,
612 Message ,
713 Part ,
814 Role ,
@@ -70,6 +76,30 @@ def get_text_parts(parts: list[Part]) -> list[str]:
7076 return [part .root .text for part in parts if isinstance (part .root , TextPart )]
7177
7278
79+ def get_data_parts (parts : list [Part ]) -> list [dict [str , Any ]]:
80+ """Extracts dictionary data from all DataPart objects in a list of Parts.
81+
82+ Args:
83+ parts: A list of `Part` objects.
84+
85+ Returns:
86+ A list of dictionaries containing the data from any `DataPart` objects found.
87+ """
88+ return [part .root .data for part in parts if isinstance (part .root , DataPart )]
89+
90+
91+ def get_file_parts (parts : list [Part ]) -> list [FileWithBytes | FileWithUri ]:
92+ """Extracts file data from all FilePart objects in a list of Parts.
93+
94+ Args:
95+ parts: A list of `Part` objects.
96+
97+ Returns:
98+ A list of `FileWithBytes` or `FileWithUri` objects containing the file data from any `FilePart` objects found.
99+ """
100+ return [part .root .file for part in parts if isinstance (part .root , FilePart )]
101+
102+
73103def get_message_text (message : Message , delimiter : str = '\n ' ) -> str :
74104 """Extracts and joins all text content from a Message's parts.
75105
You can’t perform that action at this time.
0 commit comments