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 4 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: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Only write entries that are worth mentioning to users.

## Unreleased

- Core: Add `Agent` tool for subagent delegation — the agent can now spawn persistent subagent instances with three built-in types (`coder`, `explore`, `plan`) to handle focused subtasks; each instance maintains its own context history within the session and can run in foreground or background with automatic result summarization
- Core: Unified approval runtime — approval requests from both foreground tool calls and background subagents are now coordinated through a single runtime and surfaced through the root UI channel; rejection responses can include feedback text to guide the model's next attempt
- Shell: Add interactive approval request panel — a new inline panel displays tool call details (diffs, shell commands) with options to approve once, approve for session, reject, or reject with written feedback to instruct the model on what to do instead
- Wire: Bump protocol version to 1.6 — `SubagentEvent` now includes `agent_id`, `subagent_type`, and `parent_tool_call_id` fields; `ApprovalRequest` includes source metadata (`source_kind`, `source_id`); `ApprovalResponse` supports a `feedback` field
- Vis: Add agents panel — new "Agents" tab in `kimi vis` to inspect subagent instances, view their events, and filter the wire timeline by agent scope
- Core: Change `TaskOutput` `block` parameter default from `true` to `false` — `TaskOutput` now returns a non-blocking status/output snapshot by default; set `block=true` only when you intentionally want to wait for task completion
- Shell: Show the current working directory, git branch, dirty state, and ahead/behind sync status directly in the prompt toolbar
- Shell: Surface active background bash task counts in the toolbar, rotate shortcut tips on a timer, and gracefully truncate the toolbar on narrow terminals to avoid overflow
- Web: Fix tool execution status synchronization on cancel and approval — tools now correctly transition to `output-denied` state when generation is stopped, and show the loading spinner (instead of checkmark) while executing after approval
Expand Down
14 changes: 13 additions & 1 deletion docs/en/configuration/data-locations.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,23 @@ Session state file, stores the session's runtime state, including:
- `plan_mode`: Plan mode on/off status
- `plan_session_id`: Unique identifier for the current plan session, used to associate the plan file
- `plan_slug`: The file path identifier for the plan (the slug in `~/.kimi/plans/<slug>.md`), preserved so restarts resume the same file
- `dynamic_subagents`: Dynamically created subagent definitions
- `subagent_instances`: Subagent instance state and metadata
- `additional_dirs`: Additional workspace directories added via `--add-dir` or `/add-dir`

When resuming a session, Kimi Code CLI reads this file to restore the session state. This file uses atomic writes to prevent data corruption on crash.

### `subagents/<agent_id>/`

Each subagent instance created via the `Agent` tool has its own storage directory under the session directory, containing:

- `context.jsonl`: Subagent conversation history
- `wire.jsonl`: Subagent Wire event log
- `meta.json`: Instance metadata (status, type, creation time, etc.)
- `prompt.txt`: Last executed prompt
- `output`: Execution output

When resuming a session, subagent instance context and state are automatically restored, allowing continuation via the `resume` parameter.

## Plan files

Plan mode plan files are stored in the `~/.kimi/plans/` directory. Each plan session corresponds to a randomly named Markdown file (e.g. `<slug>.md`).
Expand Down
63 changes: 29 additions & 34 deletions docs/en/customization/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ kimi --agent okabe

The default agent, suitable for general use. Enabled tools:

`Task`, `AskUserQuestion`, `SetTodoList`, `Shell`, `ReadFile`, `ReadMediaFile`, `Glob`, `Grep`, `WriteFile`, `StrReplaceFile`, `SearchWeb`, `FetchURL`, `EnterPlanMode`, `ExitPlanMode`, `TaskList`, `TaskOutput`, `TaskStop`
`Agent`, `AskUserQuestion`, `SetTodoList`, `Shell`, `ReadFile`, `ReadMediaFile`, `Glob`, `Grep`, `WriteFile`, `StrReplaceFile`, `SearchWeb`, `FetchURL`, `EnterPlanMode`, `ExitPlanMode`, `TaskList`, `TaskOutput`, `TaskStop`

### `okabe`

Expand Down Expand Up @@ -106,67 +106,71 @@ ${MY_VAR}

## Defining subagents in agent files

Subagents can handle specific types of tasks. After defining subagents in an agent file, the main agent can launch them via the `Task` tool:
Subagents can handle specific types of tasks. After defining subagents in an agent file, the main agent can launch them via the `Agent` tool:

```yaml
version: 1
agent:
extend: default
subagents:
coder:
path: ./coder-sub.yaml
path: ./coder.yaml
description: "Handle coding tasks"
reviewer:
path: ./reviewer-sub.yaml
path: ./reviewer.yaml
description: "Code review expert"
```

Subagent files are also standard agent format, typically inheriting from the main agent and excluding certain tools:
Subagent files are also standard agent format, typically inheriting from the main agent:

```yaml
# coder-sub.yaml
# coder.yaml
version: 1
agent:
extend: ./agent.yaml # Inherit from main agent
system_prompt_args:
ROLE_ADDITIONAL: |
You are now running as a subagent...
exclude_tools:
- "kimi_cli.tools.multiagent:Task" # Exclude Task tool to avoid nesting
```

## Built-in subagent types

The default agent configuration includes three built-in subagent types, each with different tool policies and use cases:

| Type | Purpose | Available tools |
|------|---------|----------------|
| `coder` | General software engineering: read/write files, run commands, search code | `Shell`, `ReadFile`, `Glob`, `Grep`, `WriteFile`, `StrReplaceFile`, `SearchWeb`, `FetchURL` |
| `explore` | Fast read-only codebase exploration: search, read, summarize | `Shell`, `ReadFile`, `Glob`, `Grep`, `SearchWeb`, `FetchURL` (no write tools) |
| `plan` | Implementation planning and architecture design: analyze files, create plans | `ReadFile`, `Glob`, `Grep`, `SearchWeb`, `FetchURL` (no Shell, no write tools) |
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved

All subagent types are prohibited from nesting the `Agent` tool (subagents cannot create their own subagents). The `Agent` tool is only available to the root agent.

## How subagents run

Subagents launched via the `Task` tool run in an isolated context and return results to the main agent when complete. Advantages of this approach:
Subagents launched via the `Agent` tool run in an isolated context and return results to the main agent when complete. Each subagent instance maintains its own context history and metadata under `subagents/<agent_id>/` in the session directory, and can be resumed across multiple invocations. Advantages of this approach:

- Isolated context, avoiding pollution of main agent's conversation history
- Multiple independent tasks can be processed in parallel
- Subagents can have targeted system prompts

## Dynamic subagent creation

`CreateSubagent` is an advanced tool that allows AI to dynamically define new subagent types at runtime (not enabled by default). Dynamically created subagents are persisted with the session state and automatically restored when resuming the session. To use it, add to your agent file:

```yaml
agent:
tools:
- "kimi_cli.tools.multiagent:CreateSubagent"
```
- Persistent instances preserve context across multiple calls

## Built-in tools list

The following are all built-in tools in Kimi Code CLI.

### `Task`
### `Agent`

- **Path**: `kimi_cli.tools.multiagent:Task`
- **Description**: Dispatch a subagent to execute a task. Subagents cannot access the main agent's context; all necessary information must be provided in the prompt.
- **Path**: `kimi_cli.tools.agent:Agent`
- **Description**: Start or resume a subagent instance for a focused task. Three built-in subagent types are available: `coder` (general software engineering), `explore` (fast read-only codebase exploration), and `plan` (implementation planning and architecture design). Each instance maintains its own context history and supports foreground or background execution.

| Parameter | Type | Description |
|-----------|------|-------------|
| `description` | string | Short task description (3-5 words) |
| `subagent_name` | string | Subagent name |
| `prompt` | string | Detailed task description |
| `subagent_type` | string | Built-in subagent type, default `coder` |
| `model` | string | Optional model override |
| `resume` | string | Optional agent instance ID to resume an existing instance |
| `run_in_background` | bool | Whether to run in background, default false |

### `AskUserQuestion`

Expand Down Expand Up @@ -351,12 +355,12 @@ This tool takes no parameters.
### `TaskOutput`

- **Path**: `kimi_cli.tools.background:TaskOutput`
- **Description**: Retrieve output and status of a background task. Supports blocking wait or non-blocking query. Returns structured task metadata and an output preview; use `ReadFile` with the returned `output_path` to read the full log if output is truncated.
- **Description**: Retrieve output and status of a background task. Returns a non-blocking status/output snapshot by default; use `ReadFile` with the returned `output_path` to read the full log if output is truncated.

| Parameter | Type | Description |
|-----------|------|-------------|
| `task_id` | string | Task ID to query |
| `block` | bool | Whether to wait for task completion, default true |
| `block` | bool | Whether to wait for task completion, default false |
| `timeout` | int | Maximum wait time in seconds when `block=true` (0–3600), default 30 |

### `TaskStop`
Expand All @@ -369,15 +373,6 @@ This tool takes no parameters.
| `task_id` | string | Task ID to stop |
| `reason` | string | Reason for stopping (optional), default "Stopped by TaskStop" |

### `CreateSubagent`

- **Path**: `kimi_cli.tools.multiagent:CreateSubagent`
- **Description**: Dynamically create subagents

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | string | Unique name for the subagent, used to reference in `Task` tool |
| `system_prompt` | string | System prompt defining agent's role, capabilities, and boundaries |

## Tool security boundaries

Expand Down
42 changes: 36 additions & 6 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 Expand Up @@ -690,17 +690,27 @@ interface ApprovalResponse {
request_id: string
/** Approval result */
response: "approve" | "approve_for_session" | "reject"
/** Optional feedback text when rejecting, may be absent in JSON */
feedback?: string
}
```

### `SubagentEvent`

::: info Changed
Changed in Wire 1.6. `task_tool_call_id` renamed to `parent_tool_call_id`; added `agent_id` and `subagent_type` fields.
:::

Subagent event.

```typescript
interface SubagentEvent {
/** Associated Task tool call ID */
task_tool_call_id: string
/** Associated parent Agent tool call ID, may be absent in JSON */
parent_tool_call_id?: string | null
/** Subagent instance ID, may be absent in JSON */
agent_id?: string | null
/** Built-in subagent type used by this instance, may be absent in JSON */
subagent_type?: string | null
/** Event from subagent, nested Wire message format */
event: { type: string; payload: object }
}
Expand All @@ -723,6 +733,10 @@ interface SteerInput {

### `ApprovalRequest`

::: info Changed
Changed in Wire 1.6. Added `source_kind`, `source_id`, `agent_id`, `subagent_type`, and `source_description` fields.
:::

Approval request, sent via `request` method, client must respond before agent can continue.

```typescript
Expand All @@ -739,25 +753,41 @@ interface ApprovalRequest {
description: string
/** Display blocks shown to user, may be absent in JSON, defaults to [] */
display?: DisplayBlock[]
/** Where the request originated: foreground turn or background agent, may be absent in JSON */
source_kind?: "foreground_turn" | "background_agent" | null
/** Source identifier (e.g. background agent ID), may be absent in JSON */
source_id?: string | null
/** Subagent instance ID if from a subagent, may be absent in JSON */
agent_id?: string | null
/** Subagent type if from a subagent, may be absent in JSON */
subagent_type?: string | null
/** Human-readable source description, may be absent in JSON */
source_description?: string | null
}
```

**Response format**

::: info Changed
Changed in Wire 1.6. Added optional `feedback` field.
:::

Client needs to return `ApprovalResponse` as the response result:

```typescript
interface ApprovalResponse {
request_id: string
response: "approve" | "approve_for_session" | "reject"
/** Optional feedback text when rejecting, may be absent in JSON */
feedback?: string
}
```

| response | Description |
|----------|-------------|
| `approve` | Approve this operation |
| `approve_for_session` | Approve similar operations for this session |
| `reject` | Reject operation |
| `reject` | Reject operation; optionally include `feedback` to instruct the model on what to do instead |

### `ToolCallRequest`

Expand Down
2 changes: 1 addition & 1 deletion docs/en/guides/sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ In addition to conversation history, Kimi Code CLI also automatically saves and

- **Approval decisions**: YOLO mode on/off status, operation types approved via "allow for this session"
- **Plan mode**: Plan mode on/off status
- **Dynamic subagents**: Subagent definitions created via the `CreateSubagent` tool during the session
- **Subagent instances**: Subagent instance state and context history created via the `Agent` tool during the session
- **Additional directories**: Workspace directories added via `--add-dir` or `/add-dir`

This means you don't need to reconfigure these settings each time you resume a session. For example, if you approved auto-execution of certain shell commands in your previous session, those approvals remain in effect after resuming.
Expand Down
Loading
Loading