惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
MongoDB | Blog
MongoDB | Blog
美团技术团队
H
Help Net Security
G
Google Developers Blog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
M
MIT News - Artificial intelligence
腾讯CDC
IT之家
IT之家
Vercel News
Vercel News
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
I
InfoQ
博客园 - 司徒正美
A
About on SuperTechFans

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(anthropic): omit stale thinking from disabled request...
liuhao1024 · 2026-06-14 · via Recent Commits to openclaw:main

@@ -6,6 +6,10 @@

66

import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";

77

import { getEnvApiKey } from "../llm/env-api-keys.js";

88

import { calculateCost, clampThinkingLevel } from "../llm/model-utils.js";

9+

import {

10+

ANTHROPIC_OMITTED_REASONING_TEXT,

11+

findActiveAnthropicToolTurnAssistantIndex,

12+

} from "../llm/providers/anthropic-thinking-replay.js";

913

import type { AnthropicOptions } from "../llm/providers/anthropic.js";

1014

import type {

1115

AssistantMessageDiagnostic,

@@ -372,11 +376,18 @@ function convertAnthropicMessages(

372376

messages: Context["messages"],

373377

model: AnthropicTransportModel,

374378

isOAuthToken: boolean,

375-

options?: { allowReasoningContentReplay?: boolean },

379+

options?: {

380+

allowReasoningContentReplay?: boolean;

381+

replayThinkingEnabled?: boolean;

382+

},

376383

) {

377384

const params: Array<Record<string, unknown>> = [];

378385

const allowReasoningContentReplay = options?.allowReasoningContentReplay === true;

386+

const replayThinkingEnabled = options?.replayThinkingEnabled !== false;

379387

const transformedMessages = transformTransportMessages(messages, model, normalizeToolCallId);

388+

const activeToolTurnAssistantIndex = replayThinkingEnabled

389+

? -1

390+

: findActiveAnthropicToolTurnAssistantIndex(transformedMessages);

380391

for (let i = 0; i < transformedMessages.length; i += 1) {

381392

const msg = transformedMessages[i];

382393

if (msg.role === "user") {

@@ -428,6 +439,7 @@ function convertAnthropicMessages(

428439

if (msg.role === "assistant") {

429440

const blocks: Array<Record<string, unknown>> = [];

430441

const reasoningContent: string[] = [];

442+

let omittedThinking = false;

431443

for (const block of msg.content) {

432444

if (block.type === "text") {

433445

if (block.text.trim().length > 0) {

@@ -439,16 +451,20 @@ function convertAnthropicMessages(

439451

continue;

440452

}

441453

if (block.type === "thinking") {

454+

const thinkingSignature = block.thinkingSignature?.trim();

455+

const isReasoningContent = thinkingSignature === "reasoning_content";

456+

if (!replayThinkingEnabled && i !== activeToolTurnAssistantIndex && !isReasoningContent) {

457+

omittedThinking = true;

458+

continue;

459+

}

442460

if (block.redacted) {

443461

blocks.push({

444462

type: "redacted_thinking",

445463

data: block.thinkingSignature,

446464

});

447465

continue;

448466

}

449-

const thinkingSignature = block.thinkingSignature?.trim();

450-

const hasNativeThinkingSignature =

451-

Boolean(thinkingSignature) && thinkingSignature !== "reasoning_content";

467+

const hasNativeThinkingSignature = Boolean(thinkingSignature) && !isReasoningContent;

452468

if (block.thinking.trim().length === 0 && !hasNativeThinkingSignature) {

453469

continue;

454470

}

@@ -490,6 +506,9 @@ function convertAnthropicMessages(

490506

});

491507

}

492508

}

509+

if (blocks.length === 0 && omittedThinking) {

510+

blocks.push({ type: "text", text: ANTHROPIC_OMITTED_REASONING_TEXT });

511+

}

493512

if (blocks.length > 0) {

494513

const assistantMsg: Record<string, unknown> = { role: "assistant", content: blocks };

495514

if (reasoningContent.length > 0) {

@@ -899,6 +918,8 @@ function buildAnthropicParams(

899918

isOAuthToken: boolean,

900919

options: AnthropicTransportOptions | undefined,

901920

) {

921+

const fable5 = usesClaudeFable5MessagesContract(model);

922+

const replayThinkingEnabled = fable5 || options?.thinkingEnabled === true;

902923

const maxTokens = resolveAnthropicMessagesMaxTokens({

903924

modelMaxTokens: model.maxTokens,

904925

requestedMaxTokens: options?.maxTokens,

@@ -920,6 +941,7 @@ function buildAnthropicParams(

920941

messages: ensureNonEmptyAnthropicMessages(

921942

convertAnthropicMessages(context.messages, model, isOAuthToken, {

922943

allowReasoningContentReplay: supportsReasoningContentReplay(model),

944+

replayThinkingEnabled,

923945

}),

924946

),

925947

max_tokens: maxTokens,

@@ -961,7 +983,6 @@ function buildAnthropicParams(

961983

if (context.tools) {

962984

params.tools = convertAnthropicTools(context.tools, isOAuthToken);

963985

}

964-

const fable5 = usesClaudeFable5MessagesContract(model);

965986

if (fable5 || model.reasoning || supportsAdaptiveThinking(model)) {

966987

if (fable5 || options?.thinkingEnabled) {

967988

if (supportsAdaptiveThinking(model)) {