Skip to content
Open
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
11 changes: 9 additions & 2 deletions packages/kosong/src/kosong/contrib/chat_provider/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import copy
import json
import re
from collections.abc import AsyncIterator, Mapping, Sequence
from typing import TYPE_CHECKING, Any, Literal, Self, TypedDict, Unpack, cast

Expand Down Expand Up @@ -237,7 +238,13 @@ async def generate(
def _use_adaptive_thinking(self) -> bool:
"""Whether to use adaptive thinking (Opus 4.6+) instead of budget-based thinking."""
model = self._model.lower()
return "opus-4.6" in model or "opus-4-6" in model
if "opus" not in model:
return False
match = re.search(r"opus[.-]?(\d+)[.-](\d{1,3})(?!\d)", model)
if match:
major, minor = int(match.group(1)), int(match.group(2))
return (major, minor) >= (4, 6)
return False
Comment on lines 238 to +247
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated model parsing logic is intended to support additional Opus naming variants (e.g., claude-opus-4-7, claude-opus-4.7, aws/claude-opus-4-6) and future minor versions, but the existing snapshot tests only cover claude-opus-4-6-.... Add automated coverage for at least one 4.7 model name and one dotted form (4.7) to prevent regressions in _use_adaptive_thinking() behavior.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that test coverage would be valuable. Will leave that to the maintainers to decide on the preferred test structure for this project.


def with_thinking(self, effort: "ThinkingEffort") -> Self:
thinking_config: ThinkingConfigParam
Expand All @@ -248,7 +255,7 @@ def with_thinking(self, effort: "ThinkingEffort") -> Self:
case "off":
thinking_config = {"type": "disabled"}
case _:
thinking_config = {"type": "adaptive"} # type: ignore[typeddict-item]
thinking_config = {"type": "adaptive", "display": "summarized"} # type: ignore[typeddict-item]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Test snapshot not updated after adding display: summarized to adaptive thinking config

The code now produces {"type": "adaptive", "display": "summarized"} for adaptive thinking (line 258), but the existing test test_anthropic_opus_46_adaptive_thinking at packages/kosong/tests/api_snapshot_tests/test_anthropic.py:522 still asserts body["thinking"] == snapshot({"type": "adaptive"}). This will cause the test to fail because the request body now includes the extra "display": "summarized" key.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

new = self.with_generation_kwargs(thinking=thinking_config)
# Remove the now-unnecessary interleaved-thinking beta header.
if (
Expand Down