@@ -64,10 +64,11 @@ def new_artifact(
6464 parts : list [Part ],
6565 name : str ,
6666 description : str | None = None ,
67+ artifact_id : str | None = None ,
6768) -> Artifact :
6869 """Creates a new Artifact object."""
6970 return Artifact (
70- artifact_id = str (uuid .uuid4 ()),
71+ artifact_id = artifact_id or str (uuid .uuid4 ()),
7172 parts = parts ,
7273 name = name ,
7374 description = description ,
@@ -78,12 +79,14 @@ def new_text_artifact(
7879 name : str ,
7980 text : str ,
8081 description : str | None = None ,
82+ artifact_id : str | None = None ,
8183) -> Artifact :
8284 """Creates a new Artifact object containing only a single text Part."""
8385 return new_artifact (
8486 [Part (text = text )],
8587 name ,
8688 description ,
89+ artifact_id = artifact_id ,
8790 )
8891
8992
@@ -97,6 +100,8 @@ def get_artifact_text(artifact: Artifact, delimiter: str = '\n') -> str:
97100
98101def new_task_from_user_message (user_message : Message ) -> Task :
99102 """Creates a new Task object from an initial user message."""
103+ if user_message .role != Role .ROLE_USER :
104+ raise ValueError ('Message must be from a user' )
100105 if not user_message .parts :
101106 raise ValueError ('Message parts cannot be empty' )
102107 for part in user_message .parts :
@@ -173,13 +178,14 @@ def new_text_artifact_update_event( # noqa: PLR0913
173178 text : str ,
174179 append : bool = False ,
175180 last_chunk : bool = False ,
181+ artifact_id : str | None = None ,
176182) -> TaskArtifactUpdateEvent :
177183 """Creates a TaskArtifactUpdateEvent with a single text artifact."""
178184 return TaskArtifactUpdateEvent (
179185 task_id = task_id ,
180186 context_id = context_id ,
181- artifact = Artifact (
182- artifact_id = str ( uuid . uuid4 ()), name = name , parts = [ Part ( text = text )]
187+ artifact = new_text_artifact (
188+ name = name , text = text , artifact_id = artifact_id
183189 ),
184190 append = append ,
185191 last_chunk = last_chunk ,
0 commit comments