@@ -107,7 +107,7 @@ def message_to_output_items(cls, message: ChatCompletionMessage) -> list[TRespon
107107 if hasattr (message , "thinking_blocks" ) and message .thinking_blocks :
108108 # Store thinking text in content and signature in encrypted_content
109109 reasoning_item .content = []
110- signature = None
110+ signatures : list [ str ] = []
111111 for block in message .thinking_blocks :
112112 if isinstance (block , dict ):
113113 thinking_text = block .get ("thinking" , "" )
@@ -116,15 +116,12 @@ def message_to_output_items(cls, message: ChatCompletionMessage) -> list[TRespon
116116 Content (text = thinking_text , type = "reasoning_text" )
117117 )
118118 # Store the signature if present
119- if block .get ("signature" ):
120- signature = block . get ( " signature" )
119+ if signature := block .get ("signature" ):
120+ signatures . append ( signature )
121121
122- # Store only the last signature in encrypted_content
123- # If there are multiple thinking blocks, this should be a problem.
124- # In practice, there should only be one signature for the entire reasoning step.
125- # Tested with: claude-sonnet-4-20250514
126- if signature :
127- reasoning_item .encrypted_content = signature
122+ # Store the signatures in encrypted_content with newline delimiter
123+ if signatures :
124+ reasoning_item .encrypted_content = "\n " .join (signatures )
128125
129126 items .append (reasoning_item )
130127
@@ -518,7 +515,8 @@ def ensure_assistant_message() -> ChatCompletionAssistantMessageParam:
518515 elif reasoning_item := cls .maybe_reasoning_message (item ):
519516 # Reconstruct thinking blocks from content (text) and encrypted_content (signature)
520517 content_items = reasoning_item .get ("content" , [])
521- signature = reasoning_item .get ("encrypted_content" )
518+ encrypted_content = reasoning_item .get ("encrypted_content" )
519+ signatures = encrypted_content .split ("\n " ) if encrypted_content else []
522520
523521 if content_items and preserve_thinking_blocks :
524522 # Reconstruct thinking blocks from content and signature
@@ -532,9 +530,9 @@ def ensure_assistant_message() -> ChatCompletionAssistantMessageParam:
532530 "type" : "thinking" ,
533531 "thinking" : content_item .get ("text" , "" ),
534532 }
535- # Add signature if available
536- if signature :
537- thinking_block ["signature" ] = signature
533+ # Add signatures if available
534+ if signatures :
535+ thinking_block ["signature" ] = signatures . pop ( 0 )
538536 pending_thinking_blocks .append (thinking_block )
539537
540538 # 8) If we haven't recognized it => fail or ignore
0 commit comments