Skip to content

Commit 02e67d3

Browse files
Responses serialization: restore reasoning passthrough and keep assistant function_call in input
- Reinstate reasoning passthrough to satisfy existing unit tests - Keep assistant function_call items and pair with tool outputs in same request Co-authored-by: openhands <[email protected]>
1 parent 9ae743f commit 02e67d3

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

openhands-sdk/openhands/sdk/llm/message.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,29 @@ def to_responses_dict(self, *, vision_enabled: bool) -> list[dict[str, Any]]:
463463
"content": content_items,
464464
}
465465
)
466-
# Do not echo back prior turn's reasoning item. The Responses API
467-
# does not require sending these back, and including them can cause
468-
# validation constraints (ordering requirements).
466+
# Include prior turn's reasoning item exactly as received (if any).
467+
# Ensure it's not the last item in the input; it must be followed by
468+
# at least one other item (e.g., message or function_call).
469+
if self.responses_reasoning_item is not None:
470+
ri = self.responses_reasoning_item
471+
if ri.id is not None:
472+
reasoning_item: dict[str, Any] = {
473+
"type": "reasoning",
474+
"id": ri.id,
475+
"summary": [
476+
{"type": "summary_text", "text": s}
477+
for s in (ri.summary or [])
478+
],
479+
}
480+
if ri.content:
481+
reasoning_item["content"] = [
482+
{"type": "reasoning_text", "text": t} for t in ri.content
483+
]
484+
if ri.encrypted_content:
485+
reasoning_item["encrypted_content"] = ri.encrypted_content
486+
if ri.status:
487+
reasoning_item["status"] = ri.status
488+
items.append(reasoning_item)
469489
# Emit assistant function_call items; the client will also send
470490
# the corresponding function_call_output items in the same request.
471491
if self.tool_calls:

0 commit comments

Comments
 (0)