GenericContent
autogen.llm_clients.models.content_blocks.GenericContent #
Bases: BaseContent
Handles content blocks we don't have specific types for yet.
This is the KEY to forward compatibility: - When a provider adds a new content type (e.g., "reflection", "video_analysis") - We don't have a specific class defined yet - GenericContent catches it and preserves ALL fields using Pydantic's native extra='allow' - Users can access fields via attribute access or helper methods - Later we can add a specific typed class without breaking anything
Example
Provider returns new "reflection" type#
reflection = GenericContent( type="reflection", reflection="Upon reviewing...", confidence=0.87, corrections=["fix1", "fix2"] )
Access fields immediately#
print(reflection.type) # "reflection" print(reflection.reflection) # "Upon reviewing..." (attribute access) print(reflection.confidence) # 0.87 (attribute access)
Extract all fields#
print(reflection.get_all_fields()) # All fields as dict print(reflection.get_extra_fields()) # Only unknown fields
data property #
Backward compatibility: access extra fields as .data
Deprecated: Use get_extra_fields() or model_extra instead.
get #
Dict-style get for any field (defined or extra).
Example
content.get("reflection", "N/A") content.get("confidence", 0.0)
Source code in autogen/llm_clients/models/content_blocks.py
get_all_fields #
Get all fields (defined + extra) as a single dict.
This is equivalent to model_dump() but more explicitly named.
Example
all_data = content.get_all_fields()
Source code in autogen/llm_clients/models/content_blocks.py
get_extra_fields #
Get only the extra (unknown) fields.
Example
extras = content.get_extra_fields() for key, value in extras.items(): print(f"{key}: {value}")
Source code in autogen/llm_clients/models/content_blocks.py
has_field #
Check if field exists (defined or extra).
Example
if content.has_field("reflection"): print(content.reflection)
get_text #
Extract text representation of content block.
Override in subclasses to provide specific text extraction logic. Default returns empty string for content blocks without text.