forked from a2aproject/a2a-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathartifact.py
More file actions
74 lines (59 loc) · 1.8 KB
/
artifact.py
File metadata and controls
74 lines (59 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Utility functions for creating A2A Artifact objects."""
import uuid
from typing import Any
from a2a.types import Artifact, DataPart, Part, TextPart
def new_artifact(
parts: list[Part],
name: str,
description: str | None = None,
) -> Artifact:
"""Creates a new Artifact object.
Args:
parts: The list of `Part` objects forming the artifact's content.
name: The human-readable name of the artifact.
description: An optional description of the artifact.
Returns:
A new `Artifact` object with a generated artifact_id.
"""
return Artifact(
artifact_id=str(uuid.uuid4()),
parts=parts,
name=name,
description=description,
)
def new_text_artifact(
name: str,
text: str,
description: str | None = None,
) -> Artifact:
"""Creates a new Artifact object containing only a single TextPart.
Args:
name: The human-readable name of the artifact.
text: The text content of the artifact.
description: An optional description of the artifact.
Returns:
A new `Artifact` object with a generated artifact_id.
"""
return new_artifact(
[Part(root=TextPart(text=text))],
name,
description,
)
def new_data_artifact(
name: str,
data: dict[str, Any],
description: str | None = None,
) -> Artifact:
"""Creates a new Artifact object containing only a single DataPart.
Args:
name: The human-readable name of the artifact.
data: The structured data content of the artifact.
description: An optional description of the artifact.
Returns:
A new `Artifact` object with a generated artifact_id.
"""
return new_artifact(
[Part(root=DataPart(data=data))],
name,
description,
)