Skip to content

UnifiedMessage

autogen.llm_clients.models.unified_message.UnifiedMessage #

Bases: BaseModel

Unified message format supporting all provider features.

This message format can represent: - Text, images, audio, video - Reasoning blocks (OpenAI o1/o3, Anthropic) - Citations (web search results) - Tool calls and results - Any future content types via GenericContent - Any future role types via extensible role field

The role field uses UserRoleType which provides: - Type-safe enum values for standard roles (UserRoleEnum.USER, etc.) - String literal typing for known roles ("user", "assistant", "system", "tool") - Flexible string fallback for unknown/future provider-specific roles

role instance-attribute #

role

content instance-attribute #

content

name class-attribute instance-attribute #

name = None

metadata class-attribute instance-attribute #

metadata = Field(default_factory=dict)

get_text #

get_text()

Extract all text content as string.

Uses the get_text() method of each content block for unified text extraction.

Source code in autogen/llm_clients/models/unified_message.py
def get_text(self) -> str:
    """Extract all text content as string.

    Uses the get_text() method of each content block for unified text extraction.
    """
    text_parts = []
    for block in self.content:
        block_text = block.get_text()
        if block_text:  # Only include non-empty text
            text_parts.append(block_text)

    return " ".join(text_parts)

get_reasoning #

get_reasoning()

Extract reasoning blocks.

Source code in autogen/llm_clients/models/unified_message.py
def get_reasoning(self) -> list[ReasoningContent]:
    """Extract reasoning blocks."""
    return [b for b in self.content if isinstance(b, ReasoningContent)]

get_citations #

get_citations()

Extract citations.

Source code in autogen/llm_clients/models/unified_message.py
def get_citations(self) -> list[CitationContent]:
    """Extract citations."""
    return [b for b in self.content if isinstance(b, CitationContent)]

get_tool_calls #

get_tool_calls()

Extract tool calls.

Source code in autogen/llm_clients/models/unified_message.py
def get_tool_calls(self) -> list[ToolCallContent]:
    """Extract tool calls."""
    return [b for b in self.content if isinstance(b, ToolCallContent)]

get_content_by_type #

get_content_by_type(content_type)

Get all content blocks of a specific type.

This is especially useful for unknown types handled by GenericContent.

PARAMETER DESCRIPTION
content_type

The type string to filter by (e.g., "text", "reasoning", "reflection")

TYPE: str

RETURNS DESCRIPTION
list[BaseContent]

List of content blocks matching the type

Source code in autogen/llm_clients/models/unified_message.py
def get_content_by_type(self, content_type: str) -> list[BaseContent]:
    """Get all content blocks of a specific type.

    This is especially useful for unknown types handled by GenericContent.

    Args:
        content_type: The type string to filter by (e.g., "text", "reasoning", "reflection")

    Returns:
        List of content blocks matching the type
    """
    return [b for b in self.content if b.type == content_type]

is_standard_role #

is_standard_role()

Check if this message uses a standard role.

RETURNS DESCRIPTION
bool

True if role is one of the standard roles (user, assistant, system, tool),

bool

False if it's a custom/future role

Source code in autogen/llm_clients/models/unified_message.py
def is_standard_role(self) -> bool:
    """Check if this message uses a standard role.

    Returns:
        True if role is one of the standard roles (user, assistant, system, tool),
        False if it's a custom/future role
    """
    # Handle both UserRoleEnum and string types
    if isinstance(self.role, UserRoleEnum):
        return True  # All enum values are standard roles
    # Check if string role matches any enum value
    return self.role in [e.value for e in UserRoleEnum]