Skip to content

Commit 7ef2f0d

Browse files
committed
feat(agent-core-v2): add custom agent identity
Add an `[identity]` config section (`name`, optional `slug`, both also settable through `KIMI_CODE_IDENTITY_NAME` / `KIMI_CODE_IDENTITY_SLUG`) that sets the identity the agent presents: the name it calls itself in the system prompt, the `User-Agent` product token sent to third-party providers, and the client name announced to MCP servers. Leaving it unset changes nothing. Until now every one of these was fixed, which left no way to run the agent as part of another product — an internal deployment, a fork with its own branding, an embedding host. The identity resolves inside the engine rather than being seeded by each host, so it applies to every launch surface — including headless runs, which today seed no display name at all and fall through to the built-in default. Two deliberate asymmetries: - The display name is a filling value with a fallback chain (config > host-declared > the consumer's own default); the slug is a rewriting value with two states only, so with no identity configured the rewriting paths are equivalent to not existing. - The rewrite happens in the outbound header assembly, the one layer that knows which vendor it is building for. Vendors declaring `hostHeaders: 'full'` keep the host's own product token, which that header set is built around and which backends key on; the configured identity applies to the third-party path. Resolution is lazy throughout: config loads asynchronously, and a constructor snapshot would freeze the pre-load value under some startup orderings. A name that folds away to nothing under slug normalization (a CJK-only name, say) falls back to a neutral token rather than reaching the User-Agent builder, which rejects a blank product.
1 parent 3ff467e commit 7ef2f0d

34 files changed

Lines changed: 730 additions & 16 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@moonshot-ai/kimi-code": minor
3+
---
4+
5+
Add a custom agent identity: the new `[identity]` section in `config.toml` (`name`, optional `slug`, also settable via `KIMI_CODE_IDENTITY_NAME` / `KIMI_CODE_IDENTITY_SLUG`) sets the name the agent calls itself in the system prompt, the `User-Agent` product token sent to third-party providers, and the client name announced to MCP servers.
6+
7+
Add a `builtin_product_skills` field (also settable via `KIMI_CODE_BUILTIN_PRODUCT_SKILLS`) that controls whether the built-in skills documenting Kimi Code itself — `update-config`, `custom-theme`, `mcp-config`, `check-kimi-code-docs`, `import-from-cc-codex` — are offered to the model. Enabled by default; turning it off trims their names and descriptions from the system prompt.

docs/en/configuration/config-files.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Fields in the config file fall into two categories: **top-level scalars** that d
103103
| `merge_all_available_skills` | `boolean` | `true` | Whether to merge Agent Skills from all available directories |
104104
| `extra_skill_dirs` | `array<string>` || Extra skill search directories, layered on top of the default directories |
105105
| `extra_agent_dirs` | `array<string>` || Extra custom agent search directories, layered on top of the default directories |
106+
| `builtin_product_skills` | `boolean` | `true` | Whether the built-in skills that document Kimi Code itself are offered to the model: `update-config`, `custom-theme`, `mcp-config`, `check-kimi-code-docs`, and `import-from-cc-codex`. Turning them off trims their names and descriptions from the system prompt, at the cost of the guided flows for those tasks |
106107
| `telemetry` | `boolean` | `true` | Whether anonymous telemetry is enabled; disabled only when explicitly set to `false` |
107108
| `providers` | `table` | `{}` | API provider table → [`providers`](#providers) |
108109
| `models` | `table` || Model alias table → [`models`](#models) |
@@ -114,6 +115,7 @@ Fields in the config file fall into two categories: **top-level scalars** that d
114115
| `services` | `table` || Built-in external service configuration → [`services`](#services) |
115116
| `permission` | `table` || Initial permission rules → [`permission`](#permission) |
116117
| `hooks` | `array<table>` || Lifecycle hooks; see [Hooks](../customization/hooks.md) |
118+
| `identity` | `table` || Custom agent identity → [`identity`](#identity) |
117119

118120
The following sections cover each of the nested tables in turn: `providers`, `models`, `thinking`, `loop_control`, `background`, `tools`, `image`, `services`, and `permission`.
119121

@@ -285,6 +287,25 @@ In print mode (`kimi -p "<prompt>"`), Kimi Code stays alive after the main agent
285287

286288
`startup_timeout_ms` and `tool_timeout_ms` can be overridden by the `KIMI_MCP_STARTUP_TIMEOUT_MS` and `KIMI_MCP_TOOL_TIMEOUT_MS` environment variables respectively, which take higher priority than `config.toml`. See [MCP](../customization/mcp.md) for the full MCP server configuration.
287289

290+
## `identity`
291+
292+
Customizes how the agent identifies itself. Leave it unset and nothing changes.
293+
294+
| Field | Type | Default | Description |
295+
| --- | --- | --- | --- |
296+
| `name` | `string` || Display name the agent calls itself in the system prompt (fills the `${product_name}` slot, including in your own `SYSTEM.md` and agent files) |
297+
| `slug` | `string` | derived from `name` | Machine identifier used in protocol fields: the `User-Agent` product token sent to third-party providers, and the client name announced to MCP servers. Derived from `name` when omitted: lowercased, with every run of non-alphanumeric characters folded to `-` |
298+
299+
```toml
300+
[identity]
301+
name = "Acme Dev Agent"
302+
slug = "acme-dev" # optional
303+
```
304+
305+
Both fields can be set through the `KIMI_CODE_IDENTITY_NAME` and `KIMI_CODE_IDENTITY_SLUG` environment variables, which take higher priority than `config.toml` and are never written back to it — convenient for containers and CI, where writing a config file is awkward.
306+
307+
A name that contains no ASCII letters or digits (for example a purely Chinese name) leaves nothing to derive a slug from and falls back to `agent`; write `slug` explicitly if you need a specific protocol token.
308+
288309
## `tools`
289310

290311
`tools` is the global tool switch: it applies to every agent in all sessions and intersects with each agent's own `tools` / `disallowedTools` policy.

docs/en/configuration/env-vars.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ Switches that control the behavior of subsystems such as telemetry, background t
128128
| `KIMI_CODE_PLUGIN_MARKETPLACE_URL` | Override the plugin marketplace JSON loaded by `/plugins`; useful for dev loopback servers, staging CDN files, or alternate marketplace directories | `https://code.kimi.com/kimi-code/plugins/marketplace.json`; also accepts `http://`, `file://` URLs, and local paths |
129129
| `KIMI_CODE_AGENT_SWARM_MAX_CONCURRENCY` | Cap how many AgentSwarm subagents run concurrently during the initial ramp; leave unset for no cap | Positive integer; invalid values fail fast |
130130
| `KIMI_SUBAGENT_TIMEOUT_MS` | Maximum wall-clock time (ms) a single subagent (`Agent` / `AgentSwarm`) may run; takes higher priority than `[subagent] timeout_ms` in `config.toml` (default `7200000`, i.e. 2 hours) | Positive integer; invalid values fall back to the config or default |
131+
| `KIMI_CODE_IDENTITY_NAME` | Display name the agent calls itself in the system prompt; takes higher priority than `[identity] name` in `config.toml` and is never written back to it | Any non-empty string; blank values read as unset |
132+
| `KIMI_CODE_IDENTITY_SLUG` | Protocol identifier for the `User-Agent` product token sent to third-party providers and the MCP client name; takes higher priority than `[identity] slug`. Derived from the name when unset | Any non-empty string; normalized to lowercase with non-alphanumeric runs folded to `-` |
133+
| `KIMI_CODE_BUILTIN_PRODUCT_SKILLS` | Whether the built-in skills documenting Kimi Code itself are offered to the model; takes higher priority than `builtin_product_skills` in `config.toml` (default enabled) | Truthy: `1`/`true`/`yes`/`on`; falsy: `0`/`false`/`no`/`off` |
131134
| `KIMI_CODE_EXPERIMENTAL_SECONDARY_MODEL` | Enable the experimental secondary-model feature in every launch mode, including the interactive TUI; the master `KIMI_CODE_EXPERIMENTAL_FLAG=1` also enables it | Truthy: `1`/`true`/`yes`/`on`; falsy: `0`/`false`/`no`/`off` |
132135
| `KIMI_SECONDARY_MODEL` | Secondary model; takes higher priority than [`[secondary_model] model`](./config-files.md#secondary-model) in `config.toml`. When the secondary-model experiment is enabled, newly spawned subagents (`Agent` / `AgentSwarm`) bind to it by default instead of inheriting the main agent's model | The alias of a configured `[models]` entry, e.g. `kimi-code/kimi-k2.5`; blank values are ignored |
133136
| `KIMI_SECONDARY_EFFORT` | Thinking effort for the secondary model; takes higher priority than `[secondary_model] default_effort` in `config.toml` and applies only when both the model and its experiment are enabled | An effort value, e.g. `low`; blank values are ignored |

docs/en/customization/skills.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ The Kimi-specific user Skill directory moves with `KIMI_CODE_HOME`, so isolated
8181
extra_skill_dirs = ["~/team-skills", ".agents/team-skills"]
8282
```
8383

84-
**Built-in Skills** are distributed with the CLI and have the lowest priority. They provide out-of-the-box workflows for common tasks — for example, configuring MCP servers, customizing the TUI theme, and editing config files. See [Built-in skill commands](../reference/slash-commands.md#built-in-skill-commands) for the full list.
84+
**Built-in Skills** are distributed with the CLI and have the lowest priority. They provide out-of-the-box workflows for common tasks — for example, configuring MCP servers, customizing the TUI theme, and editing config files. See [Built-in skill commands](../reference/slash-commands.md#built-in-skill-commands) for the full list. Those describing Kimi Code itself can be turned off with the top-level [`builtin_product_skills`](../configuration/config-files.md#top-level-fields) field.
8585

8686
## Invoking a Skill
8787

docs/zh/configuration/config-files.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ timeout = 5
103103
| `merge_all_available_skills` | `boolean` | `true` | 是否合并所有目录中的 Agent Skills |
104104
| `extra_skill_dirs` | `array<string>` || 额外 Skill 搜索目录,叠加到默认目录之上 |
105105
| `extra_agent_dirs` | `array<string>` || 额外自定义 Agent 搜索目录,叠加到默认目录之上 |
106+
| `builtin_product_skills` | `boolean` | `true` | 是否向模型提供介绍 Kimi Code 自身的内置 Skills:`update-config``custom-theme``mcp-config``check-kimi-code-docs``import-from-cc-codex`。关闭后它们的名称和描述不再进入系统提示词,代价是失去这些任务的引导流程 |
106107
| `telemetry` | `boolean` | `true` | 是否启用匿名遥测;显式设为 `false` 时关闭 |
107108
| `providers` | `table` | `{}` | API 供应商表 → [`providers`](#providers) |
108109
| `models` | `table` || 模型别名表 → [`models`](#models) |
@@ -114,6 +115,7 @@ timeout = 5
114115
| `services` | `table` || 内置外部服务配置 → [`services`](#services) |
115116
| `permission` | `table` || 初始权限规则 → [`permission`](#permission) |
116117
| `hooks` | `array<table>` || 生命周期 hook,详见 [Hooks](../customization/hooks.md) |
118+
| `identity` | `table` || 自定义 Agent 身份 → [`identity`](#identity) |
117119

118120
以下各节对 `providers``models``thinking``loop_control``background``image``services``permission` 等嵌套表逐一展开。
119121

@@ -285,6 +287,25 @@ max_output_size = 8192
285287

286288
`startup_timeout_ms``tool_timeout_ms` 可分别被环境变量 `KIMI_MCP_STARTUP_TIMEOUT_MS``KIMI_MCP_TOOL_TIMEOUT_MS` 覆盖,优先级高于配置文件。MCP server 的完整配置方式见 [MCP](../customization/mcp.md)
287289

290+
## `identity`
291+
292+
自定义 Agent 的身份标识。不设置时行为完全不变。
293+
294+
| 字段 | 类型 | 默认值 | 说明 |
295+
| --- | --- | --- | --- |
296+
| `name` | `string` || Agent 在系统提示词中的自称(填充 `${product_name}` 变量,你自己的 `SYSTEM.md` 和 agent 文件同样适用) |
297+
| `slug` | `string` |`name` 派生 | 协议字段中使用的机器标识:发给第三方 provider 的 `User-Agent` 产品名,以及连接 MCP 服务器时声明的客户端名。省略时由 `name` 派生:转小写,连续的非字母数字字符折叠为 `-` |
298+
299+
```toml
300+
[identity]
301+
name = "Acme Dev Agent"
302+
slug = "acme-dev" # 可选
303+
```
304+
305+
两个字段都可以通过 `KIMI_CODE_IDENTITY_NAME``KIMI_CODE_IDENTITY_SLUG` 环境变量设置,优先级高于 `config.toml`,且不会被写回配置文件——适合不便写配置文件的容器和 CI 场景。
306+
307+
如果名称中不含任何 ASCII 字母或数字(例如纯中文名称),就无法派生出 slug,此时回退为 `agent`;需要特定协议标识请显式填写 `slug`
308+
288309
## `tools`
289310

290311
`tools` 设置全局工具开关,对所有会话中的每个 Agent 生效,并在 Agent 自身的 `tools` / `disallowedTools` 策略之上再取一次交集。

docs/zh/configuration/env-vars.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ kimi
128128
| `KIMI_CODE_PLUGIN_MARKETPLACE_URL` | 覆盖 `/plugins` 加载的 plugin marketplace JSON,适合 dev loopback server、测试 CDN 文件或替换 marketplace 目录 | `https://code.kimi.com/kimi-code/plugins/marketplace.json`;也接受 `http://``file://` URL 和本地路径 |
129129
| `KIMI_CODE_AGENT_SWARM_MAX_CONCURRENCY` | 限制 AgentSwarm 初始提升并发阶段可同时运行的子 Agent 数量;不设置表示不限制 | 正整数;非法值会立即失败 |
130130
| `KIMI_SUBAGENT_TIMEOUT_MS` | 单个子 Agent(`Agent` / `AgentSwarm`)可运行的最长时间(毫秒);优先级高于 `config.toml``[subagent] timeout_ms`(默认 `7200000`,即 2 小时) | 正整数;非法值回退到配置或默认值 |
131+
| `KIMI_CODE_IDENTITY_NAME` | Agent 在系统提示词中的自称,优先级高于 `config.toml``[identity] name`,且不会被写回配置文件 | 任意非空字符串;空值视为未设置 |
132+
| `KIMI_CODE_IDENTITY_SLUG` | 协议标识,用于发给第三方 provider 的 `User-Agent` 产品名和 MCP 客户端名,优先级高于 `[identity] slug`。未设置时由名称派生 | 任意非空字符串;会转小写并将连续非字母数字字符折叠为 `-` |
133+
| `KIMI_CODE_BUILTIN_PRODUCT_SKILLS` | 是否向模型提供介绍 Kimi Code 自身的内置 Skills,优先级高于 `config.toml``builtin_product_skills`(默认开启) | 真值:`1`/`true`/`yes`/`on`;假值:`0`/`false`/`no`/`off` |
131134
| `KIMI_CODE_EXPERIMENTAL_SECONDARY_MODEL` | 在包括交互式 TUI 在内的所有启动方式下启用实验性的次主力模型功能;master `KIMI_CODE_EXPERIMENTAL_FLAG=1` 也会启用本功能 | 真值:`1`/`true`/`yes`/`on`;假值:`0`/`false`/`no`/`off` |
132135
| `KIMI_SECONDARY_MODEL` | 次主力模型;优先级高于 `config.toml`[`[secondary_model] model`](./config-files.md#secondary-model)。次主力模型实验功能启用后,新派生的子 Agent 默认绑定该模型,而不再继承主 Agent 的模型 | `[models]` 中已配置条目的别名,如 `kimi-code/kimi-k2.5`;空白值被忽略 |
133136
| `KIMI_SECONDARY_EFFORT` | 次主力模型的 thinking effort;优先级高于 `config.toml``[secondary_model] default_effort`,仅在次主力模型及其实验功能均启用时生效 | effort 取值,如 `low`;空白值被忽略 |

docs/zh/customization/skills.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Kimi 专属用户级 Skill 目录会随 `KIMI_CODE_HOME` 移动,因此隔离
8181
extra_skill_dirs = ["~/team-skills", ".agents/team-skills"]
8282
```
8383

84-
**内置 Skills** 随 CLI 一起分发,优先级最低。它们为常见任务提供开箱即用的工作流,例如配置 MCP server、定制 TUI 主题和编辑配置文件。完整列表详见[内置 Skill 命令](../reference/slash-commands.md#内置-skill-命令)
84+
**内置 Skills** 随 CLI 一起分发,优先级最低。它们为常见任务提供开箱即用的工作流,例如配置 MCP server、定制 TUI 主题和编辑配置文件。完整列表详见[内置 Skill 命令](../reference/slash-commands.md#内置-skill-命令)其中介绍 Kimi Code 自身的部分可以通过顶层 [`builtin_product_skills`](../configuration/config-files.md#顶层字段) 字段关闭。
8585

8686
## 调用 Skill
8787

packages/agent-core-v2/docs/config-manifest.toml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
# commented "# field: type" lines describe the remaining schema fields.
99
# Values resolve as: default -> config.toml -> env overlay -> memory.
1010

11-
# Index (22 sections · 3 overlay(s))
11+
# Index (24 sections · 3 overlay(s))
1212
# background src/agent/task/configSection.ts
13+
# builtinProductSkills src/app/skillCatalog/configSection.ts
1314
# cron src/app/cron/configSection.ts
1415
# defaultPermissionMode src/agent/permissionMode/configSection.ts
1516
# defaultPlanMode src/agent/plan/configSection.ts
1617
# experimental src/app/flag/flag.ts
1718
# extraAgentDirs src/workspace/workspaceAgentProfileLoader/configSection.ts
1819
# extraSkillDirs src/app/skillCatalog/configSection.ts
1920
# hooks src/agent/externalHooks/configSection.ts
21+
# identity src/app/agentIdentity/configSection.ts
2022
# image src/agent/media/configSection.ts
2123
# loopControl src/agent/loop/configSection.ts
2224
# mcp src/app/mcpConfig/configSection.ts
@@ -55,6 +57,17 @@
5557
# print_background_mode: "exit" | "drain" | "steer"
5658
# print_max_turns: integer
5759

60+
# ##########################################################################
61+
# builtinProductSkills (config.toml: builtin_product_skills)
62+
# owner: src/app/skillCatalog/configSection.ts
63+
# scope: core
64+
# hooks: stripEnv
65+
# env:
66+
# <- KIMI_CODE_BUILTIN_PRODUCT_SKILLS (custom parse)
67+
# ##########################################################################
68+
69+
builtin_product_skills = true
70+
5871
# ##########################################################################
5972
# cron
6073
# owner: src/app/cron/configSection.ts
@@ -134,6 +147,20 @@ extra_skill_dirs = []
134147
# command: string
135148
# timeout: integer
136149

150+
# ##########################################################################
151+
# identity
152+
# owner: src/app/agentIdentity/configSection.ts
153+
# scope: core
154+
# hooks: stripEnv
155+
# env:
156+
# name <- KIMI_CODE_IDENTITY_NAME (custom parse)
157+
# slug <- KIMI_CODE_IDENTITY_SLUG (custom parse)
158+
# ##########################################################################
159+
160+
[identity]
161+
# name: string
162+
# slug: string
163+
137164
# ##########################################################################
138165
# image
139166
# owner: src/agent/media/configSection.ts

0 commit comments

Comments
 (0)