Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions .changeset/fix-env-model-capabilities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@moonshot-ai/agent-core": patch
"@moonshot-ai/kimi-code": patch
---

Avoid assigning Kimi default model capabilities to non-Kimi env-configured providers.
4 changes: 3 additions & 1 deletion docs/en/configuration/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ For testing you can make Kimi Code use a specific model **without editing `confi
| `KIMI_MODEL_PROVIDER_TYPE` | No | Provider type; one of `kimi`, `anthropic`, `openai` | `kimi` |
| `KIMI_MODEL_BASE_URL` | No | API base URL | `kimi` → `https://api.moonshot.ai/v1`; `openai` → `https://api.openai.com/v1`; `anthropic` → SDK default |
| `KIMI_MODEL_MAX_CONTEXT_SIZE` | No | Max context length in tokens (positive integer) | `262144` (256K) |
| `KIMI_MODEL_CAPABILITIES` | No | Comma-separated capability tags (e.g. `image_in,thinking`); unioned with auto-detected capabilities | `image_in,thinking` |
| `KIMI_MODEL_CAPABILITIES` | No | Comma-separated capability tags (e.g. `image_in,thinking`); unioned with auto-detected capabilities | `kimi` → `image_in,thinking`; other providers → auto-detected |
| `KIMI_MODEL_DISPLAY_NAME` | No | Name shown in `/model` | Falls back to `KIMI_MODEL_NAME` |
| `KIMI_MODEL_MAX_OUTPUT_SIZE` | No | Per-request output cap (`anthropic` only) | Per-model default |
| `KIMI_MODEL_REASONING_KEY` | No | Reasoning field-name override (`openai` only) | Auto-detected |
Expand All @@ -89,6 +89,8 @@ For testing you can make Kimi Code use a specific model **without editing `confi

The synthesized entries use the reserved keys `__kimi_env__` (provider) and `__kimi_env_model__` (model alias). When `KIMI_MODEL_NAME` is set but a required variable is missing or invalid, startup fails with a clear error.

For standard OpenAI and Anthropic model names, leave `KIMI_MODEL_CAPABILITIES` unset so Kimi Code can use provider/model capability detection. Set it explicitly for custom model names or compatible gateways whose capabilities cannot be inferred reliably.

Set `KIMI_MODEL_ADAPTIVE_THINKING=true` when a custom-named Anthropic-compatible endpoint backs a model that supports adaptive thinking but whose model name does not encode a parseable Claude version (so the automatic inference would otherwise fall back to budget-based thinking). Forcing it on for an endpoint that does **not** support adaptive thinking makes the API reject the request, so leave it unset unless you know the backing model supports it.

```sh
Expand Down
4 changes: 3 additions & 1 deletion docs/zh/configuration/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ OAuth 流程默认连接 Kimi 官方的认证与托管端点,下列变量可
| `KIMI_MODEL_PROVIDER_TYPE` | 否 | 供应商类型,可选 `kimi`、`anthropic`、`openai` | `kimi` |
| `KIMI_MODEL_BASE_URL` | 否 | API 基础 URL | `kimi` → `https://api.moonshot.ai/v1`;`openai` → `https://api.openai.com/v1`;`anthropic` → SDK 默认值 |
| `KIMI_MODEL_MAX_CONTEXT_SIZE` | 否 | 最大上下文长度(token 数,正整数) | `262144`(256K) |
| `KIMI_MODEL_CAPABILITIES` | 否 | 逗号分隔的能力标签(如 `image_in,thinking`);与自动探测的能力做并集 | `image_in,thinking` |
| `KIMI_MODEL_CAPABILITIES` | 否 | 逗号分隔的能力标签(如 `image_in,thinking`);与自动探测的能力做并集 | `kimi` → `image_in,thinking`;其他供应商 → 自动探测 |
| `KIMI_MODEL_DISPLAY_NAME` | 否 | 在 `/model` 中显示的名称 | 回退到 `KIMI_MODEL_NAME` |
| `KIMI_MODEL_MAX_OUTPUT_SIZE` | 否 | 单次请求的输出上限(仅 `anthropic`) | 模型默认值 |
| `KIMI_MODEL_REASONING_KEY` | 否 | 推理字段名覆盖(仅 `openai`) | 自动探测 |
Expand All @@ -89,6 +89,8 @@ OAuth 流程默认连接 Kimi 官方的认证与托管端点,下列变量可

合成出的条目使用保留键 `__kimi_env__`(供应商)和 `__kimi_env_model__`(模型别名)。当设置了 `KIMI_MODEL_NAME` 但缺少必填变量或变量取值非法时,启动会以清晰的错误信息失败。

对于标准 OpenAI 和 Anthropic 模型名,保持 `KIMI_MODEL_CAPABILITIES` 未设置即可,让 Kimi Code 使用供应商/模型能力探测。对于自定义模型名或能力无法可靠推断的兼容网关,再显式设置该变量。

当某个自定义命名的 Anthropic 兼容端点背后的模型支持 adaptive thinking、但其模型名无法解析出可识别的 Claude 版本(否则自动推断会回退到 budget 模式)时,设置 `KIMI_MODEL_ADAPTIVE_THINKING=true`。若对**不支持** adaptive thinking 的端点强制开启,API 会直接拒绝请求;因此在不确定背后模型是否支持时,请保持该变量为未设置。

```sh
Expand Down
9 changes: 6 additions & 3 deletions packages/agent-core/src/config/env-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ const DEFAULT_BASE_URL: Partial<Record<ProviderType, string>> = {
/** Default context window (256K) used when KIMI_MODEL_MAX_CONTEXT_SIZE is unset. */
const DEFAULT_MAX_CONTEXT_SIZE = 262144;

/** Default capabilities when KIMI_MODEL_CAPABILITIES is unset (kimi models support both). */
const DEFAULT_CAPABILITIES = ['image_in', 'thinking'];
/** Default capabilities when KIMI_MODEL_CAPABILITIES is unset. */
const DEFAULT_CAPABILITIES_BY_TYPE: Partial<Record<ProviderType, string[]>> = {
kimi: ['image_in', 'thinking'],
};

type Env = Readonly<Record<string, string | undefined>>;

Expand Down Expand Up @@ -119,7 +121,8 @@ export function applyEnvModelConfig(config: KimiConfig, env: Env = process.env):
maxOutputRaw !== undefined
? parsePositiveInt(maxOutputRaw, 'KIMI_MODEL_MAX_OUTPUT_SIZE')
: undefined;
const capabilities = parseCapabilities(env['KIMI_MODEL_CAPABILITIES']) ?? DEFAULT_CAPABILITIES;
const capabilities =
parseCapabilities(env['KIMI_MODEL_CAPABILITIES']) ?? DEFAULT_CAPABILITIES_BY_TYPE[type];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve image support for OpenAI o-series env models

When KIMI_MODEL_PROVIDER_TYPE=openai is used with a standard o-series model such as o3, leaving capabilities unset now makes resolveModelCapabilities rely entirely on the registry; that registry matches all /^o\d/ models to OPENAI_REASONING_CAPABILITY with image_in: false (packages/kosong/src/providers/capability-registry.ts lines 48-55 and 113-114). Since ReadMediaFileTool is only installed when modelCapabilities.image_in || modelCapabilities.video_in is true, image input becomes unavailable for OpenAI env-configured o3 unless users manually set KIMI_MODEL_CAPABILITIES, even though OpenAI documents o3 as supporting image input (https://platform.openai.com/docs/models/o3).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

@Fengzdadi Fengzdadi May 31, 2026

Choose a reason for hiding this comment

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

Addressed in 7bdafcb: OpenAI reasoning+vision capability detection now covers o3, dated o3 snapshots, o3-pro, o4-mini, and GPT-5-family names through the provider capability registry. o3-mini remains image_in: false. Provider capability tests cover these cases.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Don’t make /model turn detected thinking off

For env-configured OpenAI/Anthropic models where KIMI_MODEL_CAPABILITIES is omitted, this now stores capabilities: undefined; however /model bases thinkingAvailability only on the alias’ capabilities (or adaptiveThinking), not on ProviderManager’s detected capabilities. In a session using a standard thinking model such as o3 or Claude 4, simply opening /model and pressing Enter treats thinking as unsupported and performModelSwitch calls setThinking('off'), disabling thinking even though runtime detection would report it as supported.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

@Fengzdadi Fengzdadi May 31, 2026

Choose a reason for hiding this comment

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

Addressed in 7bdafcb: /model now treats missing alias capabilities as unknown rather than unsupported, so opening the selector and pressing Enter no longer forces thinking off. Provider detection remains in the runtime capability registry instead of env-model.ts.

const displayName = trimmed(env['KIMI_MODEL_DISPLAY_NAME']);
const reasoningKey = trimmed(env['KIMI_MODEL_REASONING_KEY']);
const adaptiveThinking = parseBooleanVar(
Expand Down
12 changes: 12 additions & 0 deletions packages/agent-core/test/config/env-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ describe('applyEnvModelConfig', () => {
expect(anthropic?.baseUrl).toBeUndefined();
});

it('does not default non-Kimi env models to Kimi capabilities', () => {
expect(
apply({ ...MIN, KIMI_MODEL_PROVIDER_TYPE: 'openai' })
.models?.[ENV_MODEL_ALIAS_KEY]?.capabilities,
).toBeUndefined();

expect(
apply({ ...MIN, KIMI_MODEL_PROVIDER_TYPE: 'anthropic' })
.models?.[ENV_MODEL_ALIAS_KEY]?.capabilities,
).toBeUndefined();
});

it('rejects unsupported provider types', () => {
expectConfigInvalid(() =>
apply({ ...MIN, KIMI_MODEL_PROVIDER_TYPE: 'google-genai' }),
Expand Down
Loading