@@ -107,7 +107,7 @@ def message_to_output_items(cls, message: ChatCompletionMessage) -> list[TRespon
107
107
if hasattr (message , "thinking_blocks" ) and message .thinking_blocks :
108
108
# Store thinking text in content and signature in encrypted_content
109
109
reasoning_item .content = []
110
- signature = None
110
+ signatures : list [ str ] = []
111
111
for block in message .thinking_blocks :
112
112
if isinstance (block , dict ):
113
113
thinking_text = block .get ("thinking" , "" )
@@ -116,15 +116,12 @@ def message_to_output_items(cls, message: ChatCompletionMessage) -> list[TRespon
116
116
Content (text = thinking_text , type = "reasoning_text" )
117
117
)
118
118
# 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 )
121
121
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 )
128
125
129
126
items .append (reasoning_item )
130
127
@@ -518,7 +515,8 @@ def ensure_assistant_message() -> ChatCompletionAssistantMessageParam:
518
515
elif reasoning_item := cls .maybe_reasoning_message (item ):
519
516
# Reconstruct thinking blocks from content (text) and encrypted_content (signature)
520
517
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 []
522
520
523
521
if content_items and preserve_thinking_blocks :
524
522
# Reconstruct thinking blocks from content and signature
@@ -532,9 +530,9 @@ def ensure_assistant_message() -> ChatCompletionAssistantMessageParam:
532
530
"type" : "thinking" ,
533
531
"thinking" : content_item .get ("text" , "" ),
534
532
}
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 )
538
536
pending_thinking_blocks .append (thinking_block )
539
537
540
538
# 8) If we haven't recognized it => fail or ignore
0 commit comments