Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/packages/core/agent_framework/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1932,7 +1932,9 @@ def text(self) -> str:
Remarks:
This property concatenates the text of all TextContent objects in Content.
"""
return " ".join(content.text for content in self.contents if content.type == "text") # type: ignore[misc]
return " ".join(
content.text for content in self.contents if content.type == "text" and content.text is not None
)


AgentRunInputs = str | Content | Message | Sequence[str | Content | Message]
Expand Down
17 changes: 17 additions & 0 deletions python/packages/core/tests/core/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2562,6 +2562,23 @@ def test_chat_message_complex_content_serialization():
assert reconstructed.contents[2].type == "function_result"


def test_message_text_handles_none_text_contents() -> None:
"""Message.text should filter out text content whose text is None without raising TypeError."""
msg = Message(
role="assistant",
contents=[
Content("text", text=None),
Content.from_text("Hello"),
Content("text", text=None),
Content.from_text("world"),
],
)
assert msg.text == "Hello world"

empty_msg = Message(role="user", contents=[Content("text", text=None)])
assert empty_msg.text == ""


def test_message_roundtrip_preserves_compaction_annotation_dict() -> None:
message = Message(
role="assistant",
Expand Down
Loading