Skip to content

agentix.content

content

Multimodal content parts for :class:~agentix.types.Message.

A message's content is either a plain str (the common case, unchanged) or a list of parts — text interleaved with media. Parts are framework-agnostic; each provider adapter translates them into that vendor's block format and raises a clear error for anything the provider can't accept.

Four part types::

TextPart("describe this")
ImagePart.from_path("cat.png")          # base64-encoded, mime inferred
DocumentPart.from_url("https://…/x.pdf")
AudioPart.from_bytes(raw, "audio/wav")

A media part holds exactly one of inline data (base64) or a remote url. Build them with the from_* constructors rather than the raw fields.

TextPart dataclass

TextPart(text: str)

A run of text within a multimodal message.

BinaryPart dataclass

BinaryPart(
    data: str | None = None,
    url: str | None = None,
    media_type: str = "",
    filename: str | None = None,
)

Base for media parts. Carries exactly one of data (base64) or url.

Prefer the constructors: :meth:from_path, :meth:from_bytes, :meth:from_base64, :meth:from_url.

from_path classmethod

from_path(path: str | PathLike[str]) -> T

Read a local file, base64-encode it, and infer its MIME type.

to_bytes

to_bytes() -> bytes

Decode inline data to raw bytes (raises for URL-only parts).

data_uri

data_uri() -> str

data:<media_type>;base64,<data> (raises for URL-only parts).

ImagePart dataclass

ImagePart(
    data: str | None = None,
    url: str | None = None,
    media_type: str = "",
    filename: str | None = None,
)

Bases: BinaryPart

An image (PNG/JPEG/GIF/WebP) for vision-capable models.

DocumentPart dataclass

DocumentPart(
    data: str | None = None,
    url: str | None = None,
    media_type: str = "",
    filename: str | None = None,
)

Bases: BinaryPart

A document (typically a PDF) for document-capable models.

AudioPart dataclass

AudioPart(
    data: str | None = None,
    url: str | None = None,
    media_type: str = "",
    filename: str | None = None,
)

Bases: BinaryPart

An audio clip for audio-capable models.

part_to_dict

part_to_dict(part: ContentPart) -> dict[str, Any]

Serialize a content part to a JSON-able dict (used by the codec).

part_from_dict

part_from_dict(d: dict[str, Any]) -> ContentPart

Reconstruct a content part from :func:part_to_dict output.