Skip to content

Commit be7f61d

Browse files
committed
test: Add test for thinking_blocks field placement
- Verify thinking_blocks is NOT a top-level Message field - Verify thinking_blocks exists only in provider_specific_fields - Verify reasoning_content is the standard OpenAI-compatible field - Ensures Agents SDK doesn't see duplicate reasoning content
1 parent 7799471 commit be7f61d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_handler.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,47 @@ def test_streaming_chunks_have_stable_ids():
460460
response_two = iterator.chunk_parser(chunk=second_chunk)
461461

462462
assert response_one.id == response_two.id == iterator.response_id
463+
464+
465+
def test_thinking_blocks_only_in_provider_fields():
466+
"""Test that thinking_blocks is only in provider_specific_fields, not as top-level field"""
467+
import litellm
468+
from litellm.types.llms.openai import ChatCompletionThinkingBlock
469+
470+
# Create a message with thinking blocks using the public API
471+
thinking_blocks = [
472+
ChatCompletionThinkingBlock(
473+
type="thinking",
474+
thinking="Let me think about this...",
475+
)
476+
]
477+
478+
# Create message the way Anthropic transformation does
479+
message = litellm.Message(
480+
content="Here is my response",
481+
role="assistant",
482+
provider_specific_fields={
483+
"citations": None,
484+
"thinking_blocks": thinking_blocks,
485+
},
486+
reasoning_content="Let me think about this...",
487+
)
488+
489+
# Verify thinking_blocks is NOT a top-level attribute (or is None if it exists)
490+
# After our fix, the Message constructor should not set thinking_blocks as top-level
491+
assert not hasattr(message, "thinking_blocks") or message.thinking_blocks is None, \
492+
f"thinking_blocks should not be a top-level field, got: {getattr(message, 'thinking_blocks', 'NO ATTR')}"
493+
494+
# Verify thinking_blocks exists in provider_specific_fields
495+
assert message.provider_specific_fields is not None, \
496+
"provider_specific_fields should exist"
497+
assert "thinking_blocks" in message.provider_specific_fields, \
498+
"thinking_blocks should be in provider_specific_fields"
499+
assert message.provider_specific_fields["thinking_blocks"] == thinking_blocks, \
500+
"thinking_blocks in provider_specific_fields should match input"
501+
502+
# Verify reasoning_content exists as standard field
503+
assert message.reasoning_content is not None, \
504+
"reasoning_content should exist as standard OpenAI field"
505+
assert message.reasoning_content == "Let me think about this...", \
506+
"reasoning_content should contain the thinking text"

0 commit comments

Comments
 (0)