Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def from_function_call_content_and_result(
res = result.items[0].data_uri
elif isinstance(result.items[0], FunctionResultContent):
res = result.items[0].result
res = str(result)
else:
res = str(result)
Comment on lines 144 to +148
else:
res = result
return cls(
Expand Down
19 changes: 19 additions & 0 deletions python/tests/unit/contents/test_function_result_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ def test_from_fcc_and_result(result: any):
assert frc.metadata == {"test": "test", "test2": "test2"}


def test_from_fcc_and_result_preserves_image_and_nested_content():
# When the result is a ChatMessageContent whose first item is an
# ImageContent or a nested FunctionResultContent, that item's data must be
# surfaced - not overwritten by str(result).
fcc = FunctionCallContent(id="test", name="test-function", arguments="{}")

img = ImageContent(data=b"\x89PNG\r\n", mime_type="image/png", data_format="base64")
frc_img = FunctionResultContent.from_function_call_content_and_result(
fcc, ChatMessageContent(role="tool", items=[img])
)
assert frc_img.result == img.data_uri

nested = FunctionResultContent(id="n", name="p-f", result={"k": "v"})
frc_nested = FunctionResultContent.from_function_call_content_and_result(
fcc, ChatMessageContent(role="tool", items=[nested])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test for the new else fallback path (line 147-148 in function_result_content.py). When result.items[0] is not TextContent, ImageContent, or FunctionResultContent (e.g., a FunctionCallContent), the code now falls through to res = str(result). No existing test exercises this branch.

Suggested change
fcc, ChatMessageContent(role="tool", items=[nested])
assert frc_nested.result == {"k": "v"}
# Verify the else-branch fallback: unrecognized item types use str(result)
fcc_item = FunctionCallContent(id="fc", name="other-fn")
frc_fallback = FunctionResultContent.from_function_call_content_and_result(
fcc, ChatMessageContent(role="tool", items=[fcc_item])
)
assert frc_fallback.result == str(ChatMessageContent(role="tool", items=[fcc_item]))

)
assert frc_nested.result == {"k": "v"}


def test_to_cmc():
frc = FunctionResultContent(id="test", name="test-function", result="test-result")
cmc = frc.to_chat_message_content()
Expand Down
Loading