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
4 changes: 3 additions & 1 deletion src/google/adk/models/lite_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,9 @@ async def _content_to_message_param(
):
reasoning_texts.append(_decode_inline_text_data(part.inline_data.data))

reasoning_content = _NEW_LINE.join(text for text in reasoning_texts if text)
# Preserve reasoning deltas exactly as received. Injecting separators
# between fragments can corrupt provider-streamed thinking text.
reasoning_content = "".join(text for text in reasoning_texts if text)
return ChatCompletionAssistantMessage(
role=role,
content=final_content,
Expand Down
32 changes: 32 additions & 0 deletions tests/unittests/models/test_litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2127,6 +2127,38 @@ async def test_content_to_message_param_assistant_thought_and_content_message():
assert message["reasoning_content"] == "internal reasoning"


@pytest.mark.asyncio
async def test_content_to_message_param_preserves_chunked_reasoning_deltas():
thought_part_1 = types.Part.from_text(text="Hel")
thought_part_1.thought = True
thought_part_2 = types.Part.from_text(text="lo")
thought_part_2.thought = True
content = types.Content(
role="assistant", parts=[thought_part_1, thought_part_2]
)

message = await _content_to_message_param(content)

assert message["role"] == "assistant"
assert message["content"] is None
assert message["reasoning_content"] == "Hello"


@pytest.mark.asyncio
async def test_content_to_message_param_preserves_reasoning_newlines():
thought_part_1 = types.Part.from_text(text="line 1\n")
thought_part_1.thought = True
thought_part_2 = types.Part.from_text(text="line 2")
thought_part_2.thought = True
content = types.Content(
role="assistant", parts=[thought_part_1, thought_part_2]
)

message = await _content_to_message_param(content)

assert message["reasoning_content"] == "line 1\nline 2"


@pytest.mark.asyncio
async def test_content_to_message_param_function_call():
content = types.Content(
Expand Down
Loading