Skip to content
Merged
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
2 changes: 1 addition & 1 deletion models/anthropic/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ resource:
model:
enabled: false
type: plugin
version: 0.3.33
version: 0.3.34
1 change: 1 addition & 0 deletions models/anthropic/models/llm/_position.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- claude-fable-5-1
- claude-opus-5-5
- claude-opus-5
- claude-sonnet-5
- claude-fable-5
Expand Down
161 changes: 161 additions & 0 deletions models/anthropic/models/llm/claude-opus-5-5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# yaml-language-server: $schema=../../schemas/model-schema.json

# References:
# https://platform.claude.com/docs/en/models/opus-5-5/overview
# https://platform.claude.com/docs/en/models/opus-5-5/whats-new-opus-5-5
# https://platform.claude.com/docs/en/build-with-claude/effort
model: claude-opus-5-5
label:
en_US: claude-opus-5-5
model_type: llm
features:
- agent-thought
- vision
- tool-call
- stream-tool-call
- document
- structured-output
model_properties:
mode: chat
context_size: 1000000
parameter_rules:
- name: thinking_display
label:
zh_Hans: 推理内容展示
en_US: Thinking Display
type: string
default: summarized
required: false
options:
- omitted
- summarized
help:
zh_Hans: Claude Opus 5.5 的 adaptive thinking 始终开启。此参数仅控制响应中推理内容的展示方式:omitted 为官方默认值(响应中不返回 thinking 文本);summarized 返回摘要化的推理过程,便于在前端展示思考进度。
en_US: |
Claude Opus 5.5 always runs with adaptive thinking. This only controls how thinking content is exposed in the response: `omitted` is the official default (thinking text not returned); `summarized` returns summarized reasoning so clients can display progress.
- name: effort
label:
zh_Hans: 推理投入等级
en_US: Effort
type: string
default: medium
required: false
options:
- low
- medium
- high
- xhigh
- max
help:
zh_Hans: 通过 output_config.effort 控制推理深度、延迟与成本。medium 为官方默认值;提高 effort 可增强复杂任务的推理能力,low 适合低延迟场景。推理始终开启,较高 effort 需要为 max_tokens 留足空间。
en_US: Controls reasoning depth, latency, and cost via output_config.effort. `medium` is the official default; increase effort for demanding tasks or use `low` for lower latency. Thinking is always on; allow a large max_tokens at higher effort levels.
- name: task_budget
label:
zh_Hans: 任务预算
en_US: Task Budget
type: int
default: 0
min: 0
max: 1000000
required: false
help:
zh_Hans: |
跨完整智能体循环(推理+工具调用+工具结果+最终输出)下发给模型的建议性 token 预算。这是"建议"(模型可见并据此自我调度),不是硬上限;真正的硬上限由 max_tokens 控制。
· 0(默认):不发送该字段 → 模型看不到预算倒计时,按 max_tokens 自由发挥,适合质量优先的开放式任务。这不是"无上限",而是"不启用预算建议"。
· <20000:插件会静默忽略(API 要求最小 20000,避免 400)。
· ≥20000:启用并自动追加 beta 头 `task-budgets-2026-03-13`;预算过紧可能导致模型潦草收尾。
en_US: |
Advisory token budget visible to the model across the full agentic loop (thinking + tool calls + tool results + final output). This is advisory — the hard per-request cap is `max_tokens`.
· 0 (default): field is not sent → model runs without a countdown, bounded only by `max_tokens`. Recommended for open-ended agentic tasks where quality matters more than speed. "0" means "no budget hint", NOT "unlimited".
· <20000: silently ignored by the plugin (API requires a minimum of 20000 and would otherwise return 400).
· ≥20000: enabled and the `task-budgets-2026-03-13` beta header is attached automatically. Overly tight budgets can cause the model to wrap up prematurely.
- name: max_tokens
use_template: max_tokens
required: true
default: 128000
min: 1
max: 128000
- name: prompt_caching_message_flow
label:
zh_Hans: 大消息自动缓存阈值
en_US: Cache Message Flow Threshold
type: int
default: 0
required: false
help:
zh_Hans: 当用户或助手消息的单词数超过此阈值时,自动为该消息添加缓存控制。0 表示禁用。
en_US: If a user or assistant message exceeds this word count, add cache_control automatically. 0 disables the feature.
- name: prompt_caching_ttl
label:
zh_Hans: 缓存有效期
en_US: Cache TTL
type: string
default: 5m
required: true
options:
- 5m
- 1h
help:
zh_Hans: 控制 prompt caching 的 cache_control.ttl。5m 为默认有效期;1h 可延长缓存有效期,但缓存写入成本更高。
en_US: Controls prompt caching cache_control.ttl. 5m is the default duration; 1h extends cache lifetime but has a higher cache write cost.
- name: prompt_caching_system_message
label:
zh_Hans: 缓存系统消息
en_US: Cache System Message
type: boolean
default: true
required: false
help:
zh_Hans: 启用系统消息的提示缓存。<cache></cache>中的内容将自动缓存。
en_US: Enable prompt caching for system messages. Content within <cache></cache> will be cached.
- name: prompt_caching_images
label:
zh_Hans: 缓存图片
en_US: Cache Images
type: boolean
default: true
required: false
help:
zh_Hans: 启用图片的提示缓存。
en_US: Enable prompt caching for images.
- name: prompt_caching_documents
label:
zh_Hans: 缓存文档
en_US: Cache Documents
type: boolean
default: true
required: false
help:
zh_Hans: 启用文档的提示缓存。
en_US: Enable prompt caching for documents.
- name: prompt_caching_tool_definitions
label:
zh_Hans: 缓存工具定义
en_US: Cache Tool Definitions
type: boolean
default: true
required: false
help:
zh_Hans: 启用工具定义的提示缓存。
en_US: Enable prompt caching for tool definitions.
- name: prompt_caching_tool_results
label:
zh_Hans: 缓存工具结果
en_US: Cache Tool Results
type: boolean
default: true
required: false
help:
zh_Hans: 启用工具结果的提示缓存。
en_US: Enable prompt caching for tool results.
- name: response_format
use_template: response_format
- name: json_schema
use_template: json_schema

# https://platform.claude.com/docs/en/models/opus-5-5/overview#pricing
pricing:
input: '4.00'
output: '20.00'
unit: '0.000001'
currency: USD
7 changes: 5 additions & 2 deletions models/anthropic/models/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class AnthropicLargeLanguageModel(LargeLanguageModel):
"claude-mythos-5",
)
ALWAYS_ON_ADAPTIVE_THINKING_MODELS: tuple[str, ...] = (
"claude-opus-5-5",
"claude-fable-5",
"claude-mythos-5",
)
Expand Down Expand Up @@ -292,6 +293,8 @@ def _cache_read_multiplier(model: str) -> float:
model_id = (model or "").lower()
if model_id == "claude-fable-5-1":
return 0.025
if model_id == "claude-opus-5-5":
return 0.05
return PromptCachingHandler.CACHE_READ_MULTIPLIER

@staticmethod
Expand Down Expand Up @@ -355,7 +358,7 @@ def get_customizable_model_schema(self, model: str, credentials: dict) -> Option
name="effort",
label=I18nObject(en_us="Effort", zh_hans="推理投入等级"),
type=ParameterType.STRING,
default="high",
default="medium" if model.lower() == "claude-opus-5-5" else "high",
options=["low", "medium", "high", "xhigh", "max"],
),
ParameterRule(
Expand Down Expand Up @@ -480,7 +483,7 @@ def _chat_generate(

disabling_thinking = False
if always_on_adaptive_thinking:
# Fable/Mythos: adaptive thinking is always on and cannot be disabled.
# Opus 5.5/Fable/Mythos: adaptive thinking cannot be disabled.
extra_model_kwargs["thinking"] = {
"type": "adaptive",
"display": thinking_display or "omitted",
Expand Down
2 changes: 1 addition & 1 deletion models/anthropic/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies = [
"anthropic>=1.4.0",
# 0.10.0 introduces get_current_session(), required to resolve the
# current Dify app_id for Anthropic request metadata.
"dify_plugin>=0.10.2",
"dify_plugin>=0.10.2,<0.11.0",
"pillow>=12.3.0",
"requests>=2.34.2",
]
Expand Down
5 changes: 4 additions & 1 deletion models/anthropic/tests/test_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def test_validate_credentials_probes_and_wraps_error() -> None:
("CLAUDE-FABLE-5-1", (True, True, False, True, False)),
("CLAUDE-MYTHOS-5-latest", (True, True, False, True, False)),
("CLAUDE-OPUS-5-latest", (True, False, True, True, True)),
("CLAUDE-OPUS-5-5", (True, True, True, True, True)),
("CLAUDE-SONNET-4-6", (False, False, False, False, False)),
("not-claude-opus-5-latest", (False, False, False, False, False)),
],
Expand All @@ -143,8 +144,10 @@ def test_model_classification(model: str, expected: tuple[bool, ...]) -> None:
) == expected


def test_fable_5_1_cache_read_multiplier() -> None:
def test_model_cache_read_multipliers() -> None:
llm = AnthropicLargeLanguageModel()

assert llm._cache_read_multiplier("claude-fable-5-1") == 0.025
assert llm._cache_read_multiplier("claude-fable-5") == 0.1
assert llm._cache_read_multiplier("claude-opus-5-5") == 0.05
assert llm._cache_read_multiplier("claude-opus-5") == 0.1
59 changes: 59 additions & 0 deletions models/anthropic/tests/test_opus5_parameters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path

import pytest
import yaml
from dify_plugin.entities.model.message import UserPromptMessage

Expand Down Expand Up @@ -171,6 +172,64 @@ def test_opus5_task_budget_sent_with_beta_header(monkeypatch) -> None:
assert payload["extra_headers"] == {"anthropic-beta": "task-budgets-2026-03-13"}


def test_opus5_5_schema_matches_anthropic_docs() -> None:
model_dir = Path(__file__).parents[1] / "models" / "llm"
schema = yaml.safe_load((model_dir / "claude-opus-5-5.yaml").read_text())
rules = {rule["name"]: rule for rule in schema["parameter_rules"]}

assert schema["model"] in yaml.safe_load((model_dir / "_position.yaml").read_text())
assert schema["model_properties"]["context_size"] == 1_000_000
assert "structured-output" in schema["features"]
assert rules["max_tokens"]["max"] == 128_000
assert rules["effort"]["default"] == "medium"
assert rules["effort"]["options"] == ["low", "medium", "high", "xhigh", "max"]
assert rules["thinking_display"]["default"] == "summarized"
assert not {"thinking", "thinking_budget", "temperature", "top_p", "top_k"} & rules.keys()
assert schema["pricing"] == {
"input": "4.00",
"output": "20.00",
"unit": "0.000001",
"currency": "USD",
}

custom_schema = AnthropicLargeLanguageModel().get_customizable_model_schema(
"claude-opus-5-5", {}
)
custom_rules = {rule.name: rule for rule in custom_schema.parameter_rules}
assert "thinking" not in custom_rules
assert custom_rules["effort"].default == "medium"


@pytest.mark.parametrize("thinking", [{}, {"thinking": False}, {"thinking": True}])
def test_opus5_5_always_uses_adaptive_thinking(monkeypatch, thinking) -> None:
json_schema = {"type": "object", "properties": {"answer": {"type": "string"}}}
payload = _capture_payload(
monkeypatch,
{
**thinking,
"max_tokens": 128_000,
"thinking_budget": 1024,
"thinking_display": "summarized",
"effort": "max",
"temperature": 0.5,
"top_p": 0.9,
"top_k": 1,
"task_budget": 64_000,
"json_schema": json_schema,
},
model="claude-opus-5-5",
)

assert payload["thinking"] == {"type": "adaptive", "display": "summarized"}
assert payload["output_config"] == {
"effort": "max",
"task_budget": {"type": "tokens", "total": 64_000},
"format": {"type": "json_schema", "schema": json_schema},
}
assert not {"temperature", "top_p", "top_k", "thinking_budget", "tool_choice"} & payload.keys()
assert payload["extra_headers"] == {"anthropic-beta": "task-budgets-2026-03-13"}


def test_opus5_task_budget_below_minimum_silently_ignored(monkeypatch) -> None:
payload = _capture_payload(
monkeypatch,
Expand Down
4 changes: 2 additions & 2 deletions models/anthropic/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading