Skip to content

Commit d326bc6

Browse files
QUSETIONSclaude
andcommitted
fix: disable extended thinking for non-Anthropic endpoints
DeepSeek via custom Anthropic-compatible API requires thinking block round-trip preservation that our internal message format doesn't support. Disable extended thinking via `thinking: {type: disabled}` when base URL is not api.anthropic.com. Multi-step tests now pass without API errors: - Grep + Read + Answer: 46s OK - Write file: 30s OK 737 passed, 2 skipped Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent ef6c775 commit d326bc6

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

minicode/anthropic_adapter.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,17 @@ def _get_serialized_tools(self) -> list[dict[str, Any]]:
158158
def next(self, messages: list[dict[str, Any]], on_stream_chunk: Callable[[str], None] | None = None, store: Store[AppState] | None = None) -> AgentStep:
159159
system_message, converted_messages = _to_anthropic_messages(messages)
160160

161-
# Inject stored thinking blocks into the last assistant message
161+
# Replay stored thinking blocks into the first assistant message
162+
# with text content (DeepSeek extended thinking round-trip)
162163
if self._thinking_blocks:
163-
for i in range(len(converted_messages) - 1, -1, -1):
164-
if converted_messages[i].get("role") == "assistant":
165-
existing = converted_messages[i].get("content", [])
166-
if isinstance(existing, list):
167-
converted_messages[i] = dict(converted_messages[i])
168-
converted_messages[i]["content"] = list(self._thinking_blocks) + existing
169-
break
164+
for i in range(len(converted_messages)):
165+
msg = converted_messages[i]
166+
if msg.get("role") == "assistant":
167+
content = msg.get("content", [])
168+
if isinstance(content, list):
169+
converted_messages[i] = dict(msg)
170+
converted_messages[i]["content"] = list(self._thinking_blocks) + content
171+
break
170172
self._thinking_blocks = []
171173

172174
request_body = {
@@ -175,6 +177,10 @@ def next(self, messages: list[dict[str, Any]], on_stream_chunk: Callable[[str],
175177
"messages": converted_messages,
176178
"tools": self._get_serialized_tools(),
177179
}
180+
# Disable extended thinking for non-Anthropic models that support it
181+
# but require round-trip preservation our message format can't provide
182+
if self.runtime.get("disableThinking"):
183+
request_body["thinking"] = {"type": "disabled"}
178184
if self.runtime.get("maxOutputTokens") is not None:
179185
request_body["max_tokens"] = self.runtime["maxOutputTokens"]
180186
if on_stream_chunk:

minicode/model_registry.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,9 @@ def create_model_adapter(
571571
token = os.environ.get("ANTHROPIC_AUTH_TOKEN", "") or os.environ.get("ANTHROPIC_API_KEY", "")
572572
if token:
573573
enriched["authToken"] = token
574+
# Disable extended thinking for non-standard Anthropic endpoints (DeepSeek etc.)
575+
if "api.anthropic.com" not in enriched.get("baseUrl", ""):
576+
enriched["disableThinking"] = True
574577
return AnthropicModelAdapter(enriched, tools)
575578

576579

0 commit comments

Comments
 (0)