Skip to content

Content parts

You might be looking for...

Visual explanation

This visualization should help you understand the class hierarchy of the messages:

Message class hierarchy

Content parts for UserAIMessage

Note

To make this section more readable, we're not showing the full path of the classes, but they can also be imported from the conatus.models.messages module.

UserAIMessageContentPart module-attribute

The content part of a user message.

AI APIs allow a message to consist of multiple parts, such as text and images.

UserAIMessageContentTextPart dataclass

UserAIMessageContentTextPart(
    text: str,
    type: Literal["text"] = "text",
    linked_to_image: bool = False,
)

The content part of a user message that contains text.

ATTRIBUTE DESCRIPTION
text

The text of the user message content part.

TYPE: str

type

The type of the user message content part. Always "text".

TYPE: Literal['text']

linked_to_image

Whether the text content part is linked to an image. This is useful when removing content parts from a message to make it compatible with an AI model that does not support images; that way, you ensure that you don't have dangling text parts that make no sense on their own.

TYPE: bool

all_text property

all_text: str

Get the text of the user message content part.

to_markdown

to_markdown() -> str

Get the text of the user message content part.

Source code in conatus/models/inputs_outputs/content_parts.py
def to_markdown(self) -> str:
    """Get the text of the user message content part."""
    return f"### User message content part\n\n{self.text}"

UserAIMessageContentImagePart dataclass

UserAIMessageContentImagePart(
    image_data: str,
    is_base64: bool,
    detail: Literal["auto", "low", "high"] | None = "auto",
    type: Literal["image"] = "image",
)

The content part of a user message that contains an image.

ATTRIBUTE DESCRIPTION
image_data

The URL of the image or the base64 encoded image data.

TYPE: str

is_base64

Whether the image is base64 encoded.
If True, the image_data field is the base64 encoded image data.
If False, the image_data field is the URL of the image.
Note that URL retrieval is only supported by OpenAI.

TYPE: bool

detail

The detail level of the image.
Only supported by OpenAI.
Learn more in the OpenAI Vision guide.

TYPE: Literal['auto', 'low', 'high'] | None

type

The type of the user message content part. Always "image".

TYPE: Literal['image']

all_text property

all_text: str

Get the text of the user message content part.

to_markdown

to_markdown() -> str

Get the text of the user message content part.

Source code in conatus/models/inputs_outputs/content_parts.py
def to_markdown(self) -> str:
    """Get the text of the user message content part."""
    max_size = 100
    img_repr = (
        f"{self.image_data[:max_size]} (truncated)"
        if self.is_base64 and len(self.image_data) > max_size
        else self.image_data
    )
    return (
        "### User message image content part\n\n"
        + (
            "This image is a URL."
            if not self.is_base64
            else "This image is base64 encoded."
        )
        + f"\n{img_repr}"
    )

Content parts for AssistantAIMessage

Note

To make this section more readable, we're not showing the full path of the classes, but they can also be imported from the conatus.models.messages module.

AssistantAIMessageContentPart module-attribute

The content part of an assistant message.

While some AI providers might do it differently, we split up the content of an assistant message into text and tool calls (and potentially other content parts down the road).

AssistantAIMessageContentTextPart dataclass

AssistantAIMessageContentTextPart(
    text: str,
    uid: str | None = None,
    type: Literal["text"] = "text",
)

The content part of an assistant message that contains text.

ATTRIBUTE DESCRIPTION
text

The text of the assistant message content part.

TYPE: str

uid

The ID of the assistant message content part.
This should be given by the AI provider.

TYPE: str | None

type

The type of the assistant message content part. Always "text".

TYPE: Literal['text']

all_text property

all_text: str

Get the text of the assistant message content part.

all_text_including_reasoning property

all_text_including_reasoning: str

Get the text of the assistant message content part.

to_markdown

to_markdown() -> str

Get the text of the assistant message content part.

Source code in conatus/models/inputs_outputs/content_parts.py
def to_markdown(self) -> str:
    """Get the text of the assistant message content part."""
    return f"### Text\n\n{self.text}"

AssistantAIMessageContentToolCallPart dataclass

AssistantAIMessageContentToolCallPart(
    tool_call: AIToolCall | ComputerUseAction,
    uid: str | None = None,
    type: Literal["tool_call"] = "tool_call",
)

The content part of an assistant message that contains a tool call.

ATTRIBUTE DESCRIPTION
tool_call

The tool call of the assistant message content part.

TYPE: AIToolCall | ComputerUseAction

uid

The ID of the assistant message content part.
This should be given by the AI provider.

TYPE: str | None

type

The type of the assistant message content part. Always "tool_call".

TYPE: Literal['tool_call']

all_text property

all_text: None

Get the text of the tool call.

all_text_including_reasoning property

all_text_including_reasoning: None

Get the text of the tool call.

to_markdown

to_markdown() -> str

Get the text of the tool call.

Source code in conatus/models/inputs_outputs/content_parts.py
def to_markdown(self) -> str:
    """Get the text of the tool call."""
    if isinstance(self.tool_call, AIToolCall):
        requires_local_execution = self.tool_call.requires_local_execution
        name = self.tool_call.name
    else:
        requires_local_execution = True
        name = '"computer_use"'
    arguments_as_str = self.tool_call.arguments_as_str

    return (
        "### Tool call"
        + (
            " (executed server-side)"
            if not requires_local_execution
            else ""
        )
        + "\n\n"
        + f"Name: {name}\n"
        + f"Arguments: {arguments_as_str}\n"
        + f"Tool call ID: {self.tool_call.call_id}\n"
        + f"UID: {self.uid}"
    )

complete

complete() -> Self

Convert an incomplete tool call to a complete tool call.

In our case, we don't need to do anything.

RETURNS DESCRIPTION
Self

The complete tool call.

Source code in conatus/models/inputs_outputs/content_parts.py
def complete(self) -> Self:
    """Convert an incomplete tool call to a complete tool call.

    In our case, we don't need to do anything.

    Returns:
        The complete tool call.
    """
    return self

AssistantAIMessageContentRefusalPart dataclass

AssistantAIMessageContentRefusalPart(
    refusal: str,
    uid: str | None = None,
    type: Literal["refusal"] = "refusal",
)

The content part of an assistant message that contains a refusal.

ATTRIBUTE DESCRIPTION
refusal

The refusal of the assistant message content part.

TYPE: str

uid

The ID of the assistant message content part.
This should be given by the AI provider.

TYPE: str | None

type

The type of the assistant message content part. Always "refusal".

TYPE: Literal['refusal']

all_text property

all_text: str

Get the text of the refusal.

all_text_including_reasoning property

all_text_including_reasoning: str

Get the text of the refusal.

to_markdown

to_markdown() -> str

Get the text of the refusal.

Source code in conatus/models/inputs_outputs/content_parts.py
def to_markdown(self) -> str:
    """Get the text of the refusal."""
    return f"### Refusal\n\n{self.refusal}"

AssistantAIMessageContentReasoningPart dataclass

AssistantAIMessageContentReasoningPart(
    reasoning: str,
    uid: str | None = None,
    is_redacted: bool = False,
    model_name: str | None = None,
    index: int | None = None,
    type: Literal["reasoning"] = "reasoning",
)

The content part of an assistant message that contains reasoning.

ATTRIBUTE DESCRIPTION
reasoning

The reasoning of the assistant message content part.

TYPE: str

uid

The ID of the assistant message content part.
This should be given by the AI provider.

TYPE: str | None

is_redacted

Whether the reasoning is redacted. Supported by Anthropic.

TYPE: bool

model_name

The name of the model that produced the reasoning. This is important when switching between models.

TYPE: str | None

index

The index of the assistant message content part.
This is useful when streaming. Supported by Anthropic and OpenAI.

TYPE: int | None

type

The type of the assistant message content part. Always "reasoning".

TYPE: Literal['reasoning']

all_text property

all_text: None

Get the text of the reasoning.

By default, we don't include the reasoning in the text.

all_text_including_reasoning property

all_text_including_reasoning: str

Get the text of the reasoning.

By default, we don't include the reasoning in the text.

to_markdown

to_markdown() -> str

Get the text of the reasoning.

Source code in conatus/models/inputs_outputs/content_parts.py
def to_markdown(self) -> str:
    """Get the text of the reasoning."""
    return f"### Reasoning\n\n{self.reasoning}"