Create a custom AI artifact type
See the built-in reference for the definition fields and available built-ins.
Register an artifact for a review note
Define a self-contained payload and describe only data carried by that payload.
python
from pydantic import Field
from bloomerp.agents.artifacts.registry import AI_ARTIFACT_REGISTRY
from bloomerp.agents.definition import AIArtifactDescription, AIArtifactPayload, AIArtifactTypeDefinition
class ReviewNotePayload(AIArtifactPayload):
'''Store the note that will be presented with the artifact.'''
title: str = Field(min_length=1)
note: str = Field(min_length=1)
def describe_review_note(payload: ReviewNotePayload) -> AIArtifactDescription:
'''Use the note itself to build the artifact's title and summary.'''
return AIArtifactDescription(title=payload.title, summary=payload.note)
review_note = AIArtifactTypeDefinition[ReviewNotePayload](
id="example.review_note",
label="Review note",
model=ReviewNotePayload,
describe=describe_review_note,
)
AI_ARTIFACT_REGISTRY.register(review_note)Add a new artifact schema version
Extend the previous example with a category. Register version two alongside version one so stored notes still resolve their original payload contract.
python
from pydantic import Field
from bloomerp.agents.artifacts.registry import AI_ARTIFACT_REGISTRY
from bloomerp.agents.definition import AIArtifactDescription, AIArtifactTypeDefinition
class CategorizedReviewNote(ReviewNotePayload):
'''Store an optional category in version two.'''
category: str = Field(default="general")
def describe_categorized_note(payload: CategorizedReviewNote) -> AIArtifactDescription:
'''Include the category in the note summary.'''
return AIArtifactDescription(
title=payload.title,
summary=f"{payload.category}: {payload.note}",
)
categorized_note = AIArtifactTypeDefinition[CategorizedReviewNote](
id="example.review_note",
schema_version=2,
label="Categorized review note",
model=CategorizedReviewNote,
describe=describe_categorized_note,
)
AI_ARTIFACT_REGISTRY.register(categorized_note)