Skip to content
This repository was archived by the owner on Sep 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 16 additions & 12 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,26 @@ shell UI, ACP server mode for IDE integrations, and MCP tool loading.
model/provider (`src/kimi_cli/llm.py`), builds a `Runtime` (`src/kimi_cli/soul/agent.py`),
loads an agent spec, restores `Context`, then constructs `KimiSoul`.
- **Agent specs**: YAML under `src/kimi_cli/agents/` loaded by `src/kimi_cli/agentspec.py`.
Specs can `extend` base agents, select tools by import path, and define fixed subagents.
System prompts live alongside specs; builtin args include `KIMI_NOW`, `KIMI_WORK_DIR`,
`KIMI_WORK_DIR_LS`, `KIMI_AGENTS_MD`, `KIMI_SKILLS` (this file is injected via
`KIMI_AGENTS_MD`).
Specs can `extend` base agents, select tools by import path, and register builtin subagent
types via the `subagents` field. Subagent instances are persisted separately under the session
directory and can be resumed by `agent_id`. System prompts live alongside specs; builtin args
include `KIMI_NOW`, `KIMI_WORK_DIR`, `KIMI_WORK_DIR_LS`, `KIMI_AGENTS_MD`, `KIMI_SKILLS`
(this file is injected via `KIMI_AGENTS_MD`).
- **Tooling**: `src/kimi_cli/soul/toolset.py` loads tools by import path, injects dependencies,
and runs tool calls. Built-in tools live in `src/kimi_cli/tools/` (shell, file, web, todo,
multiagent, dmail, think). MCP tools are loaded via `fastmcp`; CLI management is in
`src/kimi_cli/mcp.py` and stored in the share dir.
- **Subagents**: `LaborMarket` in `src/kimi_cli/soul/agent.py` manages fixed and dynamic
subagents. The Task tool (`src/kimi_cli/tools/multiagent/`) spawns them.
and runs tool calls. Built-in tools live in `src/kimi_cli/tools/` (agent, shell, file, web,
todo, background, dmail, think, plan). MCP tools are loaded via `fastmcp`; CLI management is
in `src/kimi_cli/mcp.py` and stored in the share dir.
- **Subagents**: `LaborMarket` in `src/kimi_cli/soul/agent.py` registers builtin subagent types.
The `Agent` tool (`src/kimi_cli/tools/agent/`) creates or resumes subagent instances, while
`SubagentStore` persists instance metadata, prompts, wire logs, and context under
`session/subagents/<agent_id>/`.
- **Core loop**: `src/kimi_cli/soul/kimisoul.py` is the main agent loop. It accepts user input,
handles slash commands (`src/kimi_cli/soul/slash.py`), appends to `Context`
(`src/kimi_cli/soul/context.py`), calls the LLM (kosong), runs tools, and performs compaction
(`src/kimi_cli/soul/compaction.py`) when needed.
- **Approvals**: `src/kimi_cli/soul/approval.py` mediates user approvals for tool actions; the
soul forwards approval requests over `Wire` for UI handling.
- **Approvals**: `src/kimi_cli/soul/approval.py` is the tool-facing facade. `ApprovalRuntime`
in `src/kimi_cli/approval_runtime/` is the session-level source of truth for pending approvals,
and approval requests are projected onto the root wire stream for Shell/Web style UIs.
- **UI/Wire**: `src/kimi_cli/soul/run_soul` connects `KimiSoul` to a `Wire`
(`src/kimi_cli/wire/`) so UI loops can stream events. UIs live in `src/kimi_cli/ui/`
(shell/print/acp/wire).
Expand All @@ -66,7 +70,7 @@ shell UI, ACP server mode for IDE integrations, and MCP tool loading.
- `src/kimi_cli/app.py`: `KimiCLI.create(...)` and `KimiCLI.run(...)` are the main programmatic
entrypoints; this is what UI layers use.
- `src/kimi_cli/soul/agent.py`: `Runtime` (config, session, builtins), `Agent` (system prompt +
toolset), and `LaborMarket` (subagent registry).
toolset), and `LaborMarket` (builtin subagent type registry).
- `src/kimi_cli/soul/kimisoul.py`: `KimiSoul.run(...)` is the loop boundary; it emits Wire
messages and executes tools via `KimiToolset`.
- `src/kimi_cli/soul/context.py`: conversation history + checkpoints; used by DMail for
Expand Down
6 changes: 3 additions & 3 deletions docs/en/customization/wire-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ If you only need simple non-interactive input/output, [print mode](./print-mode.

## Wire protocol

Wire uses a JSON-RPC 2.0 based protocol for bidirectional communication via stdin/stdout. The current protocol version is `1.5`. Each message is a single line of JSON conforming to the JSON-RPC 2.0 specification.
Wire uses a JSON-RPC 2.0 based protocol for bidirectional communication via stdin/stdout. The current protocol version is `1.6`. Each message is a single line of JSON conforming to the JSON-RPC 2.0 specification.

### Protocol type definitions

Expand Down Expand Up @@ -153,13 +153,13 @@ interface ExternalToolsResult {
**Request example**

```json
{"jsonrpc": "2.0", "method": "initialize", "id": "550e8400-e29b-41d4-a716-446655440000", "params": {"protocol_version": "1.5", "client": {"name": "my-ui", "version": "1.0.0"}, "capabilities": {"supports_question": true}, "external_tools": [{"name": "open_in_ide", "description": "Open file in IDE", "parameters": {"type": "object", "properties": {"path": {"type": "string"}}, "required": ["path"]}}]}}
{"jsonrpc": "2.0", "method": "initialize", "id": "550e8400-e29b-41d4-a716-446655440000", "params": {"protocol_version": "1.6", "client": {"name": "my-ui", "version": "1.0.0"}, "capabilities": {"supports_question": true}, "external_tools": [{"name": "open_in_ide", "description": "Open file in IDE", "parameters": {"type": "object", "properties": {"path": {"type": "string"}}, "required": ["path"]}}]}}
```

**Success response example**

```json
{"jsonrpc": "2.0", "id": "550e8400-e29b-41d4-a716-446655440000", "result": {"protocol_version": "1.5", "server": {"name": "Kimi Code CLI", "version": "1.14.0"}, "slash_commands": [{"name": "init", "description": "Analyze the codebase ...", "aliases": []}], "capabilities": {"supports_question": true}, "external_tools": {"accepted": ["open_in_ide"], "rejected": []}}}
{"jsonrpc": "2.0", "id": "550e8400-e29b-41d4-a716-446655440000", "result": {"protocol_version": "1.6", "server": {"name": "Kimi Code CLI", "version": "1.14.0"}, "slash_commands": [{"name": "init", "description": "Analyze the codebase ...", "aliases": []}], "capabilities": {"supports_question": true}, "external_tools": {"accepted": ["open_in_ide"], "rejected": []}}}
```

If the server does not support the `initialize` method, the client will receive a `-32601 method not found` error and should automatically fall back to no-handshake mode.
Expand Down
4 changes: 2 additions & 2 deletions docs/en/reference/kimi-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ kimi info [--json]
$ kimi info
kimi-cli version: 1.20.0
agent spec versions: 1
wire protocol: 1.5
wire protocol: 1.6
python version: 3.13.1
```

**JSON output**

```sh
$ kimi info --json
{"kimi_cli_version": "1.20.0", "agent_spec_versions": ["1"], "wire_protocol_version": "1.5", "python_version": "3.13.1"}
{"kimi_cli_version": "1.20.0", "agent_spec_versions": ["1"], "wire_protocol_version": "1.6", "python_version": "3.13.1"}
```
4 changes: 2 additions & 2 deletions docs/zh/customization/wire-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ interface ExternalToolsResult {
**请求示例**

```json
{"jsonrpc": "2.0", "method": "initialize", "id": "550e8400-e29b-41d4-a716-446655440000", "params": {"protocol_version": "1.5", "client": {"name": "my-ui", "version": "1.0.0"}, "capabilities": {"supports_question": true}, "external_tools": [{"name": "open_in_ide", "description": "Open file in IDE", "parameters": {"type": "object", "properties": {"path": {"type": "string"}}, "required": ["path"]}}]}}
{"jsonrpc": "2.0", "method": "initialize", "id": "550e8400-e29b-41d4-a716-446655440000", "params": {"protocol_version": "1.6", "client": {"name": "my-ui", "version": "1.0.0"}, "capabilities": {"supports_question": true}, "external_tools": [{"name": "open_in_ide", "description": "Open file in IDE", "parameters": {"type": "object", "properties": {"path": {"type": "string"}}, "required": ["path"]}}]}}
```

**成功响应示例**

```json
{"jsonrpc": "2.0", "id": "550e8400-e29b-41d4-a716-446655440000", "result": {"protocol_version": "1.5", "server": {"name": "Kimi Code CLI", "version": "1.14.0"}, "slash_commands": [{"name": "init", "description": "Analyze the codebase ...", "aliases": []}], "capabilities": {"supports_question": true}, "external_tools": {"accepted": ["open_in_ide"], "rejected": []}}}
{"jsonrpc": "2.0", "id": "550e8400-e29b-41d4-a716-446655440000", "result": {"protocol_version": "1.6", "server": {"name": "Kimi Code CLI", "version": "1.14.0"}, "slash_commands": [{"name": "init", "description": "Analyze the codebase ...", "aliases": []}], "capabilities": {"supports_question": true}, "external_tools": {"accepted": ["open_in_ide"], "rejected": []}}}
```

若 Server 不支持 `initialize` 方法,Client 会收到 `-32601 method not found` 错误,应自动降级到无握手模式。
Expand Down
4 changes: 2 additions & 2 deletions docs/zh/reference/kimi-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ kimi info [--json]
$ kimi info
kimi-cli version: 1.20.0
agent spec versions: 1
wire protocol: 1.5
wire protocol: 1.6
python version: 3.13.1
```

**JSON 输出**

```sh
$ kimi info --json
{"kimi_cli_version": "1.20.0", "agent_spec_versions": ["1"], "wire_protocol_version": "1.5", "python_version": "3.13.1"}
{"kimi_cli_version": "1.20.0", "agent_spec_versions": ["1"], "wire_protocol_version": "1.6", "python_version": "3.13.1"}
```
9 changes: 5 additions & 4 deletions src/kimi_cli/acp/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from kimi_cli.soul.toolset import KimiToolset
from kimi_cli.tools.shell import Params as ShellParams
from kimi_cli.tools.shell import Shell
from kimi_cli.tools.utils import ToolRejectedError, ToolResultBuilder
from kimi_cli.tools.utils import ToolResultBuilder
from kimi_cli.wire.types import DisplayBlock


Expand Down Expand Up @@ -71,12 +71,13 @@ async def __call__(self, params: ShellParams) -> ToolReturnValue:
if not params.command:
return builder.error("Command cannot be empty.", brief="Empty command")

if not await self._approval.request(
approval_result = await self._approval.request(
self.name,
"run shell command",
f"Run command `{params.command}`",
):
return ToolRejectedError()
)
if not approval_result:
return approval_result.rejection_error()

timeout_seconds = float(params.timeout)
timeout_label = f"{timeout_seconds:g}s"
Expand Down
11 changes: 8 additions & 3 deletions src/kimi_cli/agents/default/agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ agent:
system_prompt_args:
ROLE_ADDITIONAL: ""
tools:
- "kimi_cli.tools.multiagent:Task"
# - "kimi_cli.tools.multiagent:CreateSubagent"
- "kimi_cli.tools.agent:Agent"
# - "kimi_cli.tools.dmail:SendDMail"
# - "kimi_cli.tools.think:Think"
- "kimi_cli.tools.ask_user:AskUserQuestion"
Expand All @@ -27,5 +26,11 @@ agent:
- "kimi_cli.tools.plan.enter:EnterPlanMode"
subagents:
coder:
path: ./sub.yaml
path: ./coder.yaml
description: "Good at general software engineering tasks."
Explore:
path: ./explore.yaml
description: "Fast codebase exploration with prompt-enforced read-only behavior."
Plan:

Copilot AI Mar 23, 2026

Copy link

Choose a reason for hiding this comment

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

The built-in subagent type keys here mix casing (coder vs Explore/Plan). Since subagent_type is used as an identifier across the CLI/tool params and the vis UI (where color/type maps use lowercase keys), this inconsistency can lead to hard-to-debug KeyErrors (when users pass explore) and missing UI styling. Consider normalizing type identifiers (e.g., make all keys lowercase, and/or make lookup case-insensitive in LaborMarket.require_builtin_type).

Suggested change
Explore:
path: ./explore.yaml
description: "Fast codebase exploration with prompt-enforced read-only behavior."
Plan:
explore:
path: ./explore.yaml
description: "Fast codebase exploration with prompt-enforced read-only behavior."
plan:

Copilot uses AI. Check for mistakes.
path: ./plan.yaml
description: "Read-only implementation planning and architecture design."
25 changes: 25 additions & 0 deletions src/kimi_cli/agents/default/coder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: 1
agent:
extend: ./agent.yaml
system_prompt_args:
ROLE_ADDITIONAL: |
You are now running as a subagent. All the `user` messages are sent by the main agent. The main agent cannot see your context, it can only see your last message when you finish the task. You must treat the parent agent as your caller. Do not directly ask the end user questions. If something is unclear, explain the ambiguity in your final summary to the parent agent.
when_to_use: |
Use this agent for non-trivial software engineering work that may require reading files, editing code, running commands, and returning a compact but technically complete summary to the parent agent.
allowed_tools:
- "kimi_cli.tools.shell:Shell"
- "kimi_cli.tools.file:ReadFile"
- "kimi_cli.tools.file:ReadMediaFile"
- "kimi_cli.tools.file:Glob"
- "kimi_cli.tools.file:Grep"
- "kimi_cli.tools.file:WriteFile"
- "kimi_cli.tools.file:StrReplaceFile"
- "kimi_cli.tools.web:SearchWeb"
- "kimi_cli.tools.web:FetchURL"
exclude_tools:
- "kimi_cli.tools.agent:Agent"
- "kimi_cli.tools.ask_user:AskUserQuestion"
- "kimi_cli.tools.todo:SetTodoList"
- "kimi_cli.tools.plan:ExitPlanMode"
- "kimi_cli.tools.plan.enter:EnterPlanMode"
subagents:
25 changes: 25 additions & 0 deletions src/kimi_cli/agents/default/explore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: 1
agent:
extend: ./agent.yaml
system_prompt_args:
ROLE_ADDITIONAL: |
You are now running as a subagent. All the `user` messages are sent by the main agent. The main agent cannot see your context, it can only see your last message when you finish the task. You must treat the parent agent as your caller. Do not directly ask the end user questions. If something is unclear, explain the ambiguity in your final summary to the parent agent.
when_to_use: |
Use this agent when you need fast, broad, prompt-enforced read-only exploration across the repository or the web. Prefer it when the task is mostly searching, grepping, reading, and summarizing.
allowed_tools:
- "kimi_cli.tools.shell:Shell"
- "kimi_cli.tools.file:ReadFile"
- "kimi_cli.tools.file:ReadMediaFile"
- "kimi_cli.tools.file:Glob"
- "kimi_cli.tools.file:Grep"
- "kimi_cli.tools.web:SearchWeb"
- "kimi_cli.tools.web:FetchURL"
exclude_tools:
- "kimi_cli.tools.agent:Agent"
- "kimi_cli.tools.ask_user:AskUserQuestion"
- "kimi_cli.tools.todo:SetTodoList"
- "kimi_cli.tools.plan:ExitPlanMode"
- "kimi_cli.tools.plan.enter:EnterPlanMode"
- "kimi_cli.tools.file:WriteFile"
- "kimi_cli.tools.file:StrReplaceFile"
subagents:
25 changes: 25 additions & 0 deletions src/kimi_cli/agents/default/plan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: 1
agent:
extend: ./agent.yaml
system_prompt_args:
ROLE_ADDITIONAL: |
You are now running as a subagent. All the `user` messages are sent by the main agent. The main agent cannot see your context, it can only see your last message when you finish the task. You must treat the parent agent as your caller. Do not directly ask the end user questions. If something is unclear, explain the ambiguity in your final summary to the parent agent.
when_to_use: |
Use this agent when the parent agent needs a step-by-step implementation plan, key file identification, and architectural trade-off analysis before code changes are made.
allowed_tools:
- "kimi_cli.tools.file:ReadFile"
- "kimi_cli.tools.file:ReadMediaFile"
- "kimi_cli.tools.file:Glob"
- "kimi_cli.tools.file:Grep"
- "kimi_cli.tools.web:SearchWeb"
- "kimi_cli.tools.web:FetchURL"
exclude_tools:
- "kimi_cli.tools.agent:Agent"
- "kimi_cli.tools.ask_user:AskUserQuestion"
- "kimi_cli.tools.todo:SetTodoList"
- "kimi_cli.tools.plan:ExitPlanMode"
- "kimi_cli.tools.plan.enter:EnterPlanMode"
- "kimi_cli.tools.shell:Shell"
- "kimi_cli.tools.file:WriteFile"
- "kimi_cli.tools.file:StrReplaceFile"
subagents:
14 changes: 0 additions & 14 deletions src/kimi_cli/agents/default/sub.yaml

This file was deleted.

6 changes: 5 additions & 1 deletion src/kimi_cli/agents/default/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The user's messages may contain questions and/or task descriptions in natural la

When handling the user's request, you may call available tools to accomplish the task. When calling tools, do not provide explanations because the tool calls themselves should be self-explanatory. You MUST follow the description of each tool and its parameters when calling tools.

If the `Agent` tool is available, you can use it to delegate a focused subtask to a subagent instance. The tool can either start a new instance or resume an existing one by `agent_id`. Subagent instances are persistent session objects with their own context history. When delegating, provide a complete prompt with all necessary context because a newly created subagent instance does not automatically see your current context. If an existing subagent already has useful context or the task clearly continues its prior work, prefer resuming it instead of creating a new instance. Default to foreground subagents. Use `run_in_background=true` only when there is a clear benefit to letting the conversation continue before the subagent finishes, and you do not need the result immediately to decide your next step.

You have the capability to output any number of tool calls in a single response. If you anticipate making multiple non-interfering tool calls, you are HIGHLY RECOMMENDED to make them in parallel to significantly improve efficiency. This is very important to your performance.

The results of the tool calls will be returned to you in a tool message. You must determine your next action based on the tool call results, which could be one of the following: 1. Continue working on the task, 2. Inform the user that the task is completed or has failed, or 3. Ask the user for more information.
Expand All @@ -18,7 +20,9 @@ The system may insert information wrapped in `<system>` tags within user or tool

Tool results and user messages may also include `<system-reminder>` tags. Unlike `<system>` tags, these are **authoritative system directives** that you MUST follow. They bear no direct relation to the specific tool results or user messages in which they appear. Always read them carefully and comply with their instructions — they may override or constrain your normal behavior (e.g., restricting you to read-only actions during plan mode).

If the `Shell`, `TaskList`, `TaskOutput`, and `TaskStop` tools are available and you are the root agent, you can use Background Bash for long-running shell commands. Launch it via `Shell` with `run_in_background=true` and a short `description`. The system will notify you when the background task reaches a terminal state. Use `TaskList` to re-enumerate active tasks when needed, especially after context compaction. Use `TaskOutput` to inspect progress or wait for completion, and use `TaskStop` only when you need to cancel the task. For human users in the interactive shell, the only task-management slash command is `/task`. Do not tell users to run `/task list`, `/task output`, `/task stop`, `/tasks`, or any other invented slash subcommands. If you are a subagent or these tools are not available, do not assume you can create or control background tasks.
If the `Shell`, `TaskList`, `TaskOutput`, and `TaskStop` tools are available and you are the root agent, you can use Background Bash for long-running shell commands. Launch it via `Shell` with `run_in_background=true` and a short `description`. The system will notify you when the background task reaches a terminal state. Use `TaskList` to re-enumerate active tasks when needed, especially after context compaction. Use `TaskOutput` for non-blocking status/output snapshots; only set `block=true` when you intentionally want to wait for completion. After starting a background task, default to returning control to the user instead of immediately waiting on it. Use `TaskStop` only when you need to cancel the task. For human users in the interactive shell, the only task-management slash command is `/task`. Do not tell users to run `/task list`, `/task output`, `/task stop`, `/tasks`, or any other invented slash subcommands. If you are a subagent or these tools are not available, do not assume you can create or control background tasks.

If a foreground tool call or a background agent requests approval, the approval is coordinated through the unified approval runtime and surfaced through the root UI channel. Do not assume approvals are local to a single subagent turn.

When responding to the user, you MUST use the SAME language as the user, unless explicitly instructed to do otherwise.

Expand Down
Loading
Loading