fix(ai): enable thinking for effort-based models when 'auto' is selected

When the user selects 'auto' thinking level for an effort-based reasoning
model (Kimi, Doubao) that has thinkingLevelMap but no thinkingFormat,
the previous code fell through to `return undefined`, causing pi-agent-core
to treat it as 'off' and send reasoning_effort:'none' to the API —
silently disabling thinking.

pi-ai's clampThinkingLevel only covers EXTENDED_THINKING_LEVELS (no 'auto'),
so 'auto' cannot be forwarded verbatim. Return 'high' instead, matching
the behavior for thinkingFormat models, to at least enable reasoning.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
diguaandClaude Sonnet 4.6 committed 2026-05-31 10:28:29 +08:00
1 parent 7558eed5a5
commit 334544880f
1 file changed
+8 -1
+8 -1
View File
@@ -91,7 +91,11 @@ export async function runAgentCore(options: AgentCoreOptions): Promise<AgentCore
// - 'default'/undefined → strip reasoning from piModel so pi-ai sends a plain request
// with NO reasoning params at all (model uses its native default behavior).
// - 'off' → pi-ai sends disable signals (thinking:{type:'disabled'} / enable_thinking:false)
// - 'auto' → for thinkingFormat models, use 'high' to enable; others no params
// - 'auto' → for thinkingFormat models or effort-based models with thinkingLevelMap,
// use 'high' to enable; others no params.
// Note: pi-ai's clampThinkingLevel only covers EXTENDED_THINKING_LEVELS (no 'auto'),
// so 'auto' cannot be forwarded verbatim for effort-based models like Kimi/Doubao.
// Returning 'high' ensures reasoning is at least enabled.
// - Other levels → clamp to what pi-agent-core accepts.
const isDefault = !options.thinkingLevel || options.thinkingLevel === 'default'
const effectiveModel = isDefault
@@ -105,6 +109,9 @@ export async function runAgentCore(options: AgentCoreOptions): Promise<AgentCore
if (!piModel.reasoning) return 'off'
const compat = piModel.compat as Record<string, unknown> | undefined
if (compat?.thinkingFormat) return 'high'
// Effort-based reasoning models (e.g., Kimi, Doubao) have a thinkingLevelMap but no
// thinkingFormat. pi-ai's clampThinkingLevel can't pass 'auto' through, so use 'high'.
if (piModel.thinkingLevelMap) return 'high'
return undefined
}
return clampThinkingLevel(piModel, level as Exclude<typeof level, 'default' | 'auto'>)