Skip to content

Message Structures

This section covers the base message structures used in the system.

core.protocol.message.BaseMessage

Bases: BaseModel, Generic[T]

Source code in src/argentic/core/protocol/message.py
class BaseMessage(BaseModel, Generic[T]):
    type: str
    source: Optional[str] = None
    timestamp: float = Field(default_factory=time.time)
    data: Optional[T] = None
    message_id: str = Field(default_factory=lambda: str(uuid4()))

    def model_dump_json(self, **kwargs: Any) -> str:
        # Pydantic's model_dump_json is suitable for this
        return super().model_dump_json(**kwargs)

    @classmethod
    def model_validate_json(cls, json_data: Union[str, bytes, bytearray], **kwargs: Any):
        # Pydantic's model_validate_json is suitable for this
        return super().model_validate_json(json_data, **kwargs)