Skip to content

Agents and Subagents

An agent defines the AI's behavior, including system prompts, available tools, and subagents. You can use built-in agents or create custom agents.

Built-in agents

Kimi CLI provides two built-in agents. You can select one at startup with the --agent flag:

sh
kimi --agent okabe

default

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

Task, SetTodoList, Shell, ReadFile, Glob, Grep, WriteFile, StrReplaceFile, SearchWeb, FetchURL

okabe

An experimental agent for testing new prompts and tools. Adds SendDMail on top of default.

Custom agent files

Agents are defined in YAML format. Load a custom agent with the --agent-file flag:

sh
kimi --agent-file /path/to/my-agent.yaml

Basic structure

yaml
version: 1
agent:
  name: my-agent
  system_prompt_path: ./system.md
  tools:
    - "kimi_cli.tools.shell:Shell"
    - "kimi_cli.tools.file:ReadFile"
    - "kimi_cli.tools.file:WriteFile"

Inheritance and overrides

Use extend to inherit another agent's configuration and only override what you need to change:

yaml
version: 1
agent:
  extend: default  # Inherit from default agent
  system_prompt_path: ./my-prompt.md  # Override system prompt
  exclude_tools:  # Exclude certain tools
    - "kimi_cli.tools.web:SearchWeb"
    - "kimi_cli.tools.web:FetchURL"

extend: default inherits from the built-in default agent. You can also specify a relative path to inherit from another agent file.

Configuration fields

FieldDescriptionRequired
extendAgent to inherit from, can be default or a relative pathNo
nameAgent nameYes (optional when inheriting)
system_prompt_pathSystem prompt file path, relative to agent fileYes (optional when inheriting)
system_prompt_argsCustom arguments passed to system prompt, merged when inheritingNo
toolsTool list, format is module:ClassNameYes (optional when inheriting)
exclude_toolsTools to excludeNo
subagentsSubagent definitionsNo

System prompt built-in parameters

The system prompt file is a Markdown template that can use ${VAR} syntax to reference variables. Built-in variables include:

VariableDescription
${KIMI_NOW}Current time (ISO format)
${KIMI_WORK_DIR}Working directory path
${KIMI_WORK_DIR_LS}Working directory file list
${KIMI_AGENTS_MD}AGENTS.md file content (if exists)
${KIMI_SKILLS}Loaded skills list

You can also define custom parameters via system_prompt_args:

yaml
agent:
  system_prompt_args:
    MY_VAR: "custom value"

Then use ${MY_VAR} in the prompt.

System prompt example

markdown
# My Agent

You are a helpful assistant. Current time: ${KIMI_NOW}.

Working directory: ${KIMI_WORK_DIR}

${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:

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

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

yaml
# coder-sub.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

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:

  • 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). To use it, add to your agent file:

yaml
agent:
  tools:
    - "kimi_cli.tools.multiagent:CreateSubagent"

Built-in tools list

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

Task

  • 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.
ParameterTypeDescription
descriptionstringShort task description (3-5 words)
subagent_namestringSubagent name
promptstringDetailed task description

SetTodoList

  • Path: kimi_cli.tools.todo:SetTodoList
  • Description: Manage todo list, track task progress
ParameterTypeDescription
todosarrayTodo list items
todos[].titlestringTodo item title
todos[].statusstringStatus: pending, in_progress, done

Shell

  • Path: kimi_cli.tools.shell:Shell
  • Description: Execute shell commands. Requires user approval. Uses the appropriate shell for the OS (bash/zsh on Unix, PowerShell on Windows).
ParameterTypeDescription
commandstringCommand to execute
timeoutintTimeout in seconds, default 60, max 300

ReadFile

  • Path: kimi_cli.tools.file:ReadFile
  • Description: Read file content. Supports text, image, and video files. For text files, max 1000 lines per read, max 2000 characters per line; for image/video files, max 80MB. Files outside working directory require absolute paths.
ParameterTypeDescription
pathstringFile path
line_offsetintStarting line number, default 1 (text files only)
n_linesintNumber of lines to read, default/max 1000 (text files only)

Glob

  • Path: kimi_cli.tools.file:Glob
  • Description: Match files and directories by pattern. Returns max 1000 matches, patterns starting with ** not allowed.
ParameterTypeDescription
patternstringGlob pattern (e.g., *.py, src/**/*.ts)
directorystringSearch directory, defaults to working directory
include_dirsboolInclude directories, default true

Grep

  • Path: kimi_cli.tools.file:Grep
  • Description: Search file content with regular expressions, based on ripgrep
ParameterTypeDescription
patternstringRegular expression pattern
pathstringSearch path, defaults to current directory
globstringFile filter (e.g., *.js)
typestringFile type (e.g., py, js, go)
output_modestringOutput mode: files_with_matches (default), content, count_matches
-BintShow N lines before match
-AintShow N lines after match
-CintShow N lines before and after match
-nboolShow line numbers
-iboolCase insensitive
multilineboolEnable multiline matching
head_limitintLimit output lines

WriteFile

  • Path: kimi_cli.tools.file:WriteFile
  • Description: Write files. Can only write to files within working directory, must use absolute paths, requires user approval.
ParameterTypeDescription
pathstringAbsolute path
contentstringFile content
modestringoverwrite (default) or append

StrReplaceFile

  • Path: kimi_cli.tools.file:StrReplaceFile
  • Description: Edit files using string replacement. Can only edit files within working directory, must use absolute paths, requires user approval.
ParameterTypeDescription
pathstringAbsolute path
editobject/arraySingle edit or list of edits
edit.oldstringOriginal string to replace
edit.newstringReplacement string
edit.replace_allboolReplace all matches, default false

SearchWeb

  • Path: kimi_cli.tools.web:SearchWeb
  • Description: Search the web. Requires search service configuration (auto-configured on Kimi Code platform).
ParameterTypeDescription
querystringSearch keywords
limitintNumber of results, default 5, max 20
include_contentboolInclude page content, default false

FetchURL

  • Path: kimi_cli.tools.web:FetchURL
  • Description: Fetch webpage content, returns extracted main text. Uses fetch service if configured, otherwise uses local HTTP request.
ParameterTypeDescription
urlstringURL to fetch

Think

  • Path: kimi_cli.tools.think:Think
  • Description: Let the agent record thinking process, suitable for complex reasoning scenarios
ParameterTypeDescription
thoughtstringThinking content

SendDMail

  • Path: kimi_cli.tools.dmail:SendDMail
  • Description: Send delayed message (D-Mail), for checkpoint rollback scenarios
ParameterTypeDescription
messagestringMessage to send
checkpoint_idintCheckpoint ID to send back to (>= 0)

CreateSubagent

  • Path: kimi_cli.tools.multiagent:CreateSubagent
  • Description: Dynamically create subagents
ParameterTypeDescription
namestringUnique name for the subagent, used to reference in Task tool
system_promptstringSystem prompt defining agent's role, capabilities, and boundaries

Tool security boundaries

Working directory restrictions

  • File writing and editing can only be done within the working directory
  • Files outside working directory can be read, but require absolute paths

Approval mechanism

The following operations require user approval:

OperationApproval required
Shell command executionEach execution
File write/editEach operation
MCP tool callsEach call