77import json
88import logging
99import os
10- from typing import (
11- Any ,
12- AsyncGenerator ,
13- Callable ,
14- Iterable ,
15- Literal ,
16- Optional ,
17- Type ,
18- TypeVar ,
19- Union ,
20- )
10+ from typing import Any , AsyncGenerator , Callable , Iterable , Literal , Optional , Type , TypeVar , Union , cast
2111
2212import boto3
2313from botocore .config import Config as BotocoreConfig
@@ -303,9 +293,9 @@ def _format_bedrock_messages(self, messages: Messages) -> Messages:
303293 https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ToolResultBlock.html
304294 """
305295 cleaned_messages = []
296+
306297 filtered_unknown_members = False
307- # TODO: Replace with systematic model configuration registry (https://github.com/strands-agents/sdk-python/issues/780)
308- is_deepseek = "deepseek" in self .config ["model_id" ].lower ()
298+ dropped_deepseek_reasoning_content = False
309299
310300 for message in messages :
311301 cleaned_content : list [ContentBlock ] = []
@@ -315,9 +305,11 @@ def _format_bedrock_messages(self, messages: Messages) -> Messages:
315305 if "SDK_UNKNOWN_MEMBER" in content_block :
316306 filtered_unknown_members = True
317307 continue
308+
318309 # DeepSeek models have issues with reasoningContent
319310 # TODO: Replace with systematic model configuration registry (https://github.com/strands-agents/sdk-python/issues/780)
320311 if "deepseek" in self .config ["model_id" ].lower () and "reasoningContent" in content_block :
312+ dropped_deepseek_reasoning_content = True
321313 continue
322314
323315 if "toolResult" in content_block :
@@ -352,6 +344,10 @@ def _format_bedrock_messages(self, messages: Messages) -> Messages:
352344 logger .warning (
353345 "Filtered out SDK_UNKNOWN_MEMBER content blocks from messages, consider upgrading boto3 version"
354346 )
347+ if dropped_deepseek_reasoning_content :
348+ logger .debug (
349+ "Filtered DeepSeek reasoningContent content blocks from messages - https://api-docs.deepseek.com/guides/reasoning_model#multi-round-conversation"
350+ )
355351
356352 return cleaned_messages
357353
0 commit comments