2020from ..event_loop import streaming
2121from ..tools import convert_pydantic_to_tool_spec
2222from ..tools ._tool_helpers import noop_tool
23- from ..types .content import ContentBlock , Messages
23+ from ..types .content import ContentBlock , Messages , SystemContentBlock
2424from ..types .exceptions import (
2525 ContextWindowOverflowException ,
2626 ModelThrottledException ,
@@ -187,11 +187,11 @@ def get_config(self) -> BedrockConfig:
187187 """
188188 return self .config
189189
190- def format_request (
190+ def _format_request (
191191 self ,
192192 messages : Messages ,
193193 tool_specs : Optional [list [ToolSpec ]] = None ,
194- system_prompt : Optional [str ] = None ,
194+ system_prompt_content : Optional [list [ SystemContentBlock ] ] = None ,
195195 tool_choice : ToolChoice | None = None ,
196196 ) -> dict [str , Any ]:
197197 """Format a Bedrock converse stream request.
@@ -201,6 +201,7 @@ def format_request(
201201 tool_specs: List of tool specifications to make available to the model.
202202 system_prompt: System prompt to provide context to the model.
203203 tool_choice: Selection strategy for tool invocation.
204+ system_prompt_content: System prompt content blocks to provide context to the model.
204205
205206 Returns:
206207 A Bedrock converse stream request.
@@ -211,13 +212,20 @@ def format_request(
211212 )
212213 if has_tool_content :
213214 tool_specs = [noop_tool .tool_spec ]
215+
216+ # Use system_prompt_content directly (copy for mutability)
217+ system_blocks : list [SystemContentBlock ] = system_prompt_content .copy () if system_prompt_content else []
218+ # Add cache point if configured (backwards compatibility)
219+ if cache_prompt := self .config .get ("cache_prompt" ):
220+ warnings .warn (
221+ "cache_prompt is deprecated. Use SystemContentBlock with cachePoint instead." , UserWarning , stacklevel = 3
222+ )
223+ system_blocks .append ({"cachePoint" : {"type" : cache_prompt }})
224+
214225 return {
215226 "modelId" : self .config ["model_id" ],
216227 "messages" : self ._format_bedrock_messages (messages ),
217- "system" : [
218- * ([{"text" : system_prompt }] if system_prompt else []),
219- * ([{"cachePoint" : {"type" : self .config ["cache_prompt" ]}}] if self .config .get ("cache_prompt" ) else []),
220- ],
228+ "system" : system_blocks ,
221229 ** (
222230 {
223231 "toolConfig" : {
@@ -590,6 +598,7 @@ async def stream(
590598 system_prompt : Optional [str ] = None ,
591599 * ,
592600 tool_choice : ToolChoice | None = None ,
601+ system_prompt_content : Optional [list [SystemContentBlock ]] = None ,
593602 ** kwargs : Any ,
594603 ) -> AsyncGenerator [StreamEvent , None ]:
595604 """Stream conversation with the Bedrock model.
@@ -602,6 +611,7 @@ async def stream(
602611 tool_specs: List of tool specifications to make available to the model.
603612 system_prompt: System prompt to provide context to the model.
604613 tool_choice: Selection strategy for tool invocation.
614+ system_prompt_content: System prompt content blocks to provide context to the model.
605615 **kwargs: Additional keyword arguments for future extensibility.
606616
607617 Yields:
@@ -620,7 +630,11 @@ def callback(event: Optional[StreamEvent] = None) -> None:
620630 loop = asyncio .get_event_loop ()
621631 queue : asyncio .Queue [Optional [StreamEvent ]] = asyncio .Queue ()
622632
623- thread = asyncio .to_thread (self ._stream , callback , messages , tool_specs , system_prompt , tool_choice )
633+ # Handle backward compatibility: if system_prompt is provided but system_prompt_content is None
634+ if system_prompt and system_prompt_content is None :
635+ system_prompt_content = [{"text" : system_prompt }]
636+
637+ thread = asyncio .to_thread (self ._stream , callback , messages , tool_specs , system_prompt_content , tool_choice )
624638 task = asyncio .create_task (thread )
625639
626640 while True :
@@ -637,7 +651,7 @@ def _stream(
637651 callback : Callable [..., None ],
638652 messages : Messages ,
639653 tool_specs : Optional [list [ToolSpec ]] = None ,
640- system_prompt : Optional [str ] = None ,
654+ system_prompt_content : Optional [list [ SystemContentBlock ] ] = None ,
641655 tool_choice : ToolChoice | None = None ,
642656 ) -> None :
643657 """Stream conversation with the Bedrock model.
@@ -649,7 +663,7 @@ def _stream(
649663 callback: Function to send events to the main thread.
650664 messages: List of message objects to be processed by the model.
651665 tool_specs: List of tool specifications to make available to the model.
652- system_prompt : System prompt to provide context to the model.
666+ system_prompt_content : System prompt content blocks to provide context to the model.
653667 tool_choice: Selection strategy for tool invocation.
654668
655669 Raises:
@@ -658,7 +672,7 @@ def _stream(
658672 """
659673 try :
660674 logger .debug ("formatting request" )
661- request = self .format_request (messages , tool_specs , system_prompt , tool_choice )
675+ request = self ._format_request (messages , tool_specs , system_prompt_content , tool_choice )
662676 logger .debug ("request=<%s>" , request )
663677
664678 logger .debug ("invoking model" )
0 commit comments