Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion astrbot/core/provider/sources/openai_responses_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ class ProviderOpenAIResponses(ProviderOpenAIOfficial):
"""OpenAI-compatible stateless Responses API provider adapter."""

_REASONING_STATE_TYPE = "openai_responses_reasoning"
_REASONING_REPLAY_SAFE_KEYS = frozenset(
{
"type",
"id",
"summary",
"content",
"encrypted_content",
}
)

def __init__(self, provider_config: dict, provider_settings: dict) -> None:
"""Initialize the Responses API client.
Expand Down Expand Up @@ -129,7 +138,11 @@ def _convert_chat_messages_to_response_input(
and isinstance(state.get("items"), list)
):
restored_items = [
item
{
key: value
for key, value in item.items()
if key in self._REASONING_REPLAY_SAFE_KEYS
}
for item in state["items"]
if isinstance(item, dict)
]
Expand Down
65 changes: 64 additions & 1 deletion tests/test_openai_responses_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def test_convert_chat_history_preserves_response_items_and_function_calls():
reasoning_item = {
"id": "rs_1",
"type": "reasoning",
"status": "completed",
"summary": [],
"encrypted_content": "encrypted-reasoning",
}
Expand Down Expand Up @@ -148,6 +147,70 @@ def test_convert_chat_history_preserves_response_items_and_function_calls():
]


def test_convert_chat_history_filters_nonportable_reasoning_replay_fields():
provider = _make_provider()
reasoning_state = json.dumps(
{
"type": provider._REASONING_STATE_TYPE,
"items": [
{
"id": "rs_1",
"type": "reasoning",
"status": "completed",
"summary": [],
"content": [
{
"type": "reasoning_text",
"text": "prior reasoning",
}
],
"encrypted_content": "encrypted-reasoning",
"provider_specific": "provider-only-value",
}
],
}
)

response_input = provider._convert_chat_messages_to_response_input(
[
{
"role": "assistant",
"content": [
{
"type": "think",
"think": "prior reasoning",
"encrypted": reasoning_state,
},
{
"type": "text",
"text": "prior answer",
},
],
}
]
)

assert response_input == [
{
"id": "rs_1",
"type": "reasoning",
"summary": [],
"content": [
{
"type": "reasoning_text",
"text": "prior reasoning",
}
],
"encrypted_content": "encrypted-reasoning",
},
{
"type": "message",
"role": "assistant",
"content": "prior answer",
},
]


def test_deepseek_converts_plain_reasoning_history_to_reasoning_item():
provider = _make_provider(
{
Expand Down