Types
Type definitions and constants for A2A artifact generation.
This module provides common MIME types, artifact types, and other constants used in A2A artifact generation to ensure consistency across the codebase.
Artifact
Bases: BaseModel
Represents an artifact payload used by A2A helpers and executors.
This model standardizes the structure for artifacts generated by tools and passed through the A2A pipeline.
Attributes:
Name | Type | Description |
---|---|---|
artifact_type |
ArtifactType
|
The type of artifact. Defaults to FILE. |
data |
str
|
Base64-encoded content of the artifact. |
name |
str
|
Display name or filename of the artifact. |
description |
str
|
Optional description for the artifact. Defaults to empty string. |
mime_type |
str
|
MIME type of the artifact content. |
metadata |
dict[str, Any] | None
|
Optional per-artifact metadata to pass through. |
validate_base64(v)
classmethod
Validate that 'data' is a valid base64 string.
ArtifactType
Bases: StrEnum
Common artifact types for A2A artifacts.
This class provides constants for artifact types used in the A2A protocol.
MimeType
Bases: StrEnum
Common MIME types for A2A artifacts.
This class provides constants for commonly used MIME types in artifact generation, ensuring consistency and reducing typos across the codebase.
get_extension_from_mime_type(mime_type)
Get file extension from MIME type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mime_type |
str
|
The MIME type to get the extension for. |
required |
Returns:
Type | Description |
---|---|
str | None
|
The file extension (with dot) or None if not found. |
Example
get_extension_from_mime_type("text/csv") '.csv' get_extension_from_mime_type("image/png") '.png' get_extension_from_mime_type("unknown/type") None
get_mime_type_from_filename(filename)
Get MIME type from filename extension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
The filename to get the MIME type for. |
required |
Returns:
Type | Description |
---|---|
str
|
The MIME type string, or application/octet-stream if unknown. |
Example
get_mime_type_from_filename("data.csv") 'text/csv' get_mime_type_from_filename("image.png") 'image/png' get_mime_type_from_filename("unknown.xyz") 'application/octet-stream'