@@ -859,18 +859,28 @@ def _process_response(self, response: responses.Response) -> ModelResponse:
859
859
for item in response .output :
860
860
if isinstance (item , responses .ResponseReasoningItem ):
861
861
signature = item .encrypted_content
862
- for summary in item .summary :
863
- # We use the same id for all summaries so that we can merge them on the round trip.
864
- # We only need to store the signature once.
862
+ if item .summary :
863
+ for summary in item .summary :
864
+ # We use the same id for all summaries so that we can merge them on the round trip.
865
+ items .append (
866
+ ThinkingPart (
867
+ content = summary .text ,
868
+ id = item .id ,
869
+ signature = signature ,
870
+ provider_name = self .system if signature else None ,
871
+ )
872
+ )
873
+ # We only need to store the signature once.
874
+ signature = None
875
+ elif signature :
865
876
items .append (
866
877
ThinkingPart (
867
- content = summary . text ,
878
+ content = '' ,
868
879
id = item .id ,
869
880
signature = signature ,
870
- provider_name = self .system if signature else None ,
881
+ provider_name = self .system ,
871
882
)
872
883
)
873
- signature = None
874
884
# NOTE: We don't currently handle the raw CoT from gpt-oss `reasoning_text`: https://cookbook.openai.com/articles/gpt-oss/handle-raw-cot
875
885
# If you need this, please file an issue.
876
886
elif isinstance (item , responses .ResponseOutputMessage ):
@@ -1122,20 +1132,20 @@ async def _map_messages( # noqa: C901
1122
1132
# We don't currently track built-in tool calls from OpenAI
1123
1133
pass
1124
1134
elif isinstance (item , ThinkingPart ):
1125
- if reasoning_item is not None and item .id == reasoning_item ['id' ]:
1135
+ if reasoning_item is None or reasoning_item ['id' ] != item .id :
1136
+ reasoning_item = responses .ResponseReasoningItemParam (
1137
+ id = item .id or _utils .generate_tool_call_id (),
1138
+ summary = [],
1139
+ encrypted_content = item .signature if item .provider_name == self .system else None ,
1140
+ type = 'reasoning' ,
1141
+ )
1142
+ openai_messages .append (reasoning_item )
1143
+
1144
+ if item .content :
1126
1145
reasoning_item ['summary' ] = [
1127
1146
* reasoning_item ['summary' ],
1128
1147
Summary (text = item .content , type = 'summary_text' ),
1129
1148
]
1130
- continue
1131
-
1132
- reasoning_item = responses .ResponseReasoningItemParam (
1133
- id = item .id or _utils .generate_tool_call_id (),
1134
- summary = [Summary (text = item .content , type = 'summary_text' )],
1135
- encrypted_content = item .signature if item .provider_name == self .system else None ,
1136
- type = 'reasoning' ,
1137
- )
1138
- openai_messages .append (reasoning_item )
1139
1149
else :
1140
1150
assert_never (item )
1141
1151
else :
0 commit comments