> ## Documentation Index
> Fetch the complete documentation index at: https://platform.kimi.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Tools

> Explore built-in and custom tools, usage limits, and on-demand schema loading in Kimi Hosted Agents.

Tools are how an agent interacts with the outside world. Kimi Hosted Agents supports three categories of tools:

| Category | Executed by | Description |
| - | - | - |
| Built-in toolset | Platform | Ready-to-use file, command execution, web search, and delivery tools provided by the platform; new agents load `agent_toolset_20261101` by default |
| MCP toolset (`mcp_toolset`) | MCP server | Tools exposed by remote MCP servers declared on the agent; see [Configure MCP Servers](https://platform.kimi.ai/docs/hosted-agents/mcp.md) |
| Custom tool (`custom`) | Your client | Declared in the agent's `tools` array; the platform dispatches tool calls over the event stream and your client returns the results (see "Custom tools" below) |

The built-in toolset is provided by default. Once you declare an MCP server on an agent, its tools become available to the model automatically; `mcp_toolset` declarations in `tools` are used to customize those tools' settings. This page covers the built-in toolset, custom tools, and the shared schema loading modes across toolsets.

## Built-in toolset

Built-in sandbox toolsets are versioned by release date. Two versions are currently available:

| Toolset | Status | Included tools |
| - | - | - |
| `agent_toolset_20261101` | **Current default**. Loaded automatically when a new agent does not explicitly declare an `agent_toolset` | `read`, `write`, `edit`, `bash`, `glob`, `grep`, `web_search`, `web_fetch`, `save_artifact` |
| `agent_toolset_20260901` | Earlier toolset that continues to serve existing agents, including `ipython`, task checklists, and image search tools | `read_file`, `write_file`, `edit_file`, `shell`, `ipython`, `todo_read`, `todo_write`, `web_search`, `web_open_url`, `search_image_by_text`, `search_image_by_image`, `save_artifact` |

> [!NOTE]
>
> Built-in sandbox toolsets have been renamed from `default_toolset_<date>` to `agent_toolset_<date>`. The legacy name `default_toolset_20260901` remains supported in requests and existing configurations as a deprecated alias for `agent_toolset_20260901`; use `agent_toolset_20260901` or `agent_toolset_20261101` in new requests.

### `agent_toolset_20261101` (default)

`agent_toolset_20261101` is designed for coding and file-processing tasks, providing dedicated tools for file discovery, ranged reads, unique-match edits, and command execution:

| Category | Tool | Purpose |
| - | - | - |
| File | `read` | Read text files in the sandbox (returned line by line as `<line_number>\t<content>` with no path header), with `view_range` for reading line ranges; in cloud sandboxes, also supports images, videos, PDFs, and Office documents |
| File | `write` | Create new files or replace file contents in full, with `append` support |
| File | `edit` | Perform targeted edits on text files; requires `old_string` to match exactly once by default, or set `replace_all: true` to replace every match |
| Search | `glob` | Match file paths by pattern, returning up to 100 results ordered from newest to oldest modification time |
| Search | `grep` | Search file contents with regular expressions, supporting `files_with_matches`, `count`, and `content` output modes |
| Command | `bash` | Execute Bash commands in the cloud sandbox; oversized output is saved to a file and returned as a preview |
| Search | `web_search` | Search the web |
| Search | `web_fetch` | Fetch a specified URL and read its webpage content |
| Delivery | `save_artifact` | Deliver a specified output file as an immutable artifact version for subsequent download and reference |

> [!NOTE]
>
> `agent_toolset_20261101` no longer includes `ipython`, `todo_read` / `todo_write`, or `search_image_by_text` / `search_image_by_image`. To search for images by keyword, attach the official [`search-image`](https://platform.kimi.ai/docs/hosted-agents/skills) skill to your agent; the agent runs the skill's script via `bash` to find images and download them into the sandbox. To keep using `ipython`, task checklists, or image search tools, explicitly select `agent_toolset_20260901`.

### Comparison with `agent_toolset_20260901`

| Purpose | `agent_toolset_20261101` | `agent_toolset_20260901` |
| - | - | - |
| Read files | `read` | `read_file` |
| Write files | `write` | `write_file` |
| Targeted edits | `edit` (supports `replace_all`) | `edit_file` |
| Find files / search contents | `glob` / `grep` | — |
| Execute commands | `bash` | `shell` |
| Run Python / task checklists | — | `ipython`; `todo_read` / `todo_write` |
| Web search / fetch webpages | `web_search` / `web_fetch` | `web_search` / `web_open_url` |
| Image search | Attach the official `search-image` skill (keyword search) | `search_image_by_text` / `search_image_by_image` |
| Deliver artifacts | `save_artifact` | `save_artifact` |

> [!NOTE]
>
> To customize built-in toolset settings—including per-tool overrides for `enabled`, `permission_policy`, `result_hint`, or `load_mode`—you must explicitly declare `agent_toolset`; without an explicit declaration, default settings apply and individual tools cannot be adjusted. Likewise, to disable sandbox tools altogether, explicitly declare the toolset and set `default_config.enabled` to `false`.

### Toolset configuration and version pinning

The `name` of an `agent_toolset` accepts `"agent_toolset_20261101" | "agent_toolset_20260901"`, plus the deprecated alias `"default_toolset_20260901"`. Toolsets are selected and pinned according to the following rules:

* **New agents**: When `POST /v1/agents` does not declare an `agent_toolset` (including omitting `tools`, passing an empty array, or declaring only custom / MCP tools), the platform prepends `agent_toolset_20261101` to `tools` (counting toward the 128-item limit).
* **Existing versions stay unchanged**: Saved agent versions keep their pinned toolset and do not switch automatically when the platform default changes or toolsets are renamed.
* **Updating agents or overriding session tools**: When replacing an agent's `tools` or setting a session's `agent_overrides.tools` without an `agent_toolset`, the platform keeps the currently effective or bound agent's `agent_toolset`, or prepends `agent_toolset_20261101` if none exists. Updating an older agent version that lacks an `agent_toolset` without passing `tools` returns `400` `failed_precondition_error`; pass `tools` to pin a toolset explicitly.
* **At most one sandbox toolset**: Each `tools` list can declare at most one sandbox toolset. Mixing `agent_toolset_20260901` and `agent_toolset_20261101` (including the `default_toolset_20260901` alias) returns `400` `invalid_parameter_error`; declaring the same toolset (including via an alias) more than once uses only the first declaration without merging configurations. `configs[].name` must use a tool name from the selected toolset.
* **Legacy name compatibility**: `default_toolset_20260901` remains supported as a deprecated alias for `agent_toolset_20260901`; both refer to the same toolset (saved under the name you pass). Use `agent_toolset_20260901` in new requests.
* **Self-hosted environments**: Support both `agent_toolset_20260901` (including the deprecated alias `default_toolset_20260901`) and `agent_toolset_20261101`.

`default_config` applies to every tool in the toolset, while `configs` overrides those defaults by tool name. Permission fields match [Permissions](https://platform.kimi.ai/docs/hosted-agents/permissions.md): `enabled` controls whether a tool is exposed to the model, and `permission_policy` accepts `always_allow` or `always_ask` (defaulting to enabled and `always_allow` when unset). `always_ask` pauses execution after `agent.tool_use` and waits for the client to reply with `user.tool_confirmation`. Use `enabled: false` to disable a tool.

The example below disables the entire built-in sandbox toolset:

```json theme={null}
{
  "type": "agent_toolset",
  "name": "agent_toolset_20261101",
  "default_config": {
    "enabled": false
  }
}
```

MCP toolsets use `mcp_toolset` and reference an MCP server declared on the agent via `mcp_server_name`. They also support `default_config` and `configs`, where `configs` can override only tools actually exposed by that MCP server. Built-in sandbox tools are not configured in `mcp_toolset`—they remain managed under `agent_toolset`'s `default_config` and `configs`.

### Limits and security boundaries

Built-in tools enforce limits on read/write sizes and execution duration. Calls that exceed a limit return a descriptive error result to the model—allowing the model to adapt its strategy (for example, reading a file in chunks) without interrupting the session:

| Limit | Default |
| - | - |
| `read` text output limit | 100,000 characters (including `<line_number>\t<content>` line-number prefixes; exceeding the limit returns a single-line error without partial content—use `view_range` to read in chunks) |
| `read` PDF / Office conversion limit | 100 MiB per file, 60-second conversion timeout (cloud only; self-hosted `read` supports local text files only) |
| `read_file` single-file read and output truncation | 100 MiB per file; returns up to 1,000 lines and 100,000 characters |
| `edit` parameter length | Up to 128 KiB each for `old_string` and `new_string` (requires a unique `old_string` match by default; use `replace_all` to replace all matches) |
| `edit_file` single-file size limit | 100 MiB |
| `glob` result count and timeout | Up to 100 results, 30 seconds |
| `grep` output truncation and timeout | Up to 30,000 characters (lines longer than 500 characters are omitted), 30 seconds |
| `bash` / `shell` output preview | Up to 30,000 characters; full output is saved to `/tmp/bash-full-output-<thread>.txt` |
| `bash` / `shell` per-call execution timeout | 5 minutes |
| `ipython` output truncation and timeout | 10,000 characters (rolling truncation), 4 minutes |
| `web_search` / `web_fetch` / `web_open_url` / built-in image search timeout | 30 seconds |
| `web_search` result length | 10,240 tokens |
| Total timeout per tool call | 5 minutes |

> [!TIP]
>
> Path parameters on file tools (such as the path for `read` / `read_file`) must be absolute paths inside cloud sandboxes. The tool parameter schema itself does not restrict OS path formats: self-hosted workers support `${KHA_WORKDIR}`, paths relative to the working directory, and host OS paths (such as Windows paths). `edit` and `edit_file` are intended for plain UTF-8 text files only, not binary or non-UTF-8 content.

All file operations and process execution run inside the session's cloud sandbox, and sandbox instances are isolated from one another.
Instance-local files may be lost when a sandbox instance is recycled. Session workspaces, session files, and [Memory](https://platform.kimi.ai/docs/hosted-agents/memory.md) mounted into the session persist across instances via asynchronous write-back, so the most recent writes not yet flushed before an instance exits may still be lost.
For critical deliverables that must be retained permanently, call `save_artifact` to publish them explicitly as immutable artifact versions.
After a sandbox instance is recreated, the platform automatically routes subsequent tool calls to the new instance with no client-side action required.

### Sandbox networking and credentials

Outbound network access from sandbox processes is governed by the execution environment's network policy, whereas platform-level tools are not directly restricted by that environment network policy. An environment can additionally configure a proxy to route designated outbound traffic through your own proxy server; configuring a proxy does not imply credential injection.

| Network access mode | Description |
| - | - |
| `limited` | Allows access only to configured hosts, plus package managers and MCP servers permitted by configuration |
| `unrestricted` | Allows public internet access, though special endpoints such as cloud provider metadata addresses remain blocked by the platform |

Credential injection applies only to HTTP/HTTPS traffic (`80`/`443`) routed through the platform egress proxy; whether other ports are reachable depends on the network policy. Credentials stored in a Vault are never injected into all outbound requests indiscriminately—instead, they are injected or substituted based on credential type and matching rules: MCP credentials match by MCP server URL, while `environment_variable` credentials substitute placeholders in matching outbound requests according to each credential's host allowlist and injection location settings.

## Custom tools

Custom tools are executed by your client. Once you declare a custom tool in an agent's `tools` array, the model can invoke it: the platform sends the tool name and input arguments over the event stream, your client executes the tool and submits the result, and the session resumes.

### Declare custom tools

Add an entry with `type` set to `"custom"` in the `tools` array:

| Field | Type | Required | Description |
| - | - | - | - |
| `type` | string | Required | Fixed to `"custom"` |
| `name` | string | Required | Tool name, 1–128 characters, containing only letters, digits, underscores, or hyphens (`^[A-Za-z0-9_-]+$`) |
| `description` | string | Required | Instructions helping the model decide when to call the tool, 1–4,096 characters |
| `input_schema` | object | Required | JSON Schema for the tool input; root `type` must be `"object"`. Use `properties` to describe parameters and `required` to mark required ones |

`tools` can contain up to 128 declarations. Custom tool names must be unique and cannot collide with built-in tool names; if `input_schema.type` is not `"object"`, agent creation fails with `400 invalid_parameter_error`.

The example below creates an agent that uses only the `lookup_order` custom tool, explicitly disabling the default built-in toolset so the model cannot select sandbox tools:

```bash cURL theme={null}
curl -X POST https://api.moonshot.ai/v1/agents \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Order Assistant",
    "model": {"id": "kimi-k3.1-pro"},
    "system": "When handling order inquiries, call lookup_order to fetch the live order status.",
    "tools": [
      {
        "type": "agent_toolset",
        "name": "agent_toolset_20261101",
        "default_config": {"enabled": false}
      },
      {
        "type": "custom",
        "name": "lookup_order",
        "description": "Look up the current status of an order in your system.",
        "input_schema": {
          "type": "object",
          "properties": {
            "order_id": {"type": "string"}
          },
          "required": ["order_id"]
        }
      }
    ]
  }'
```

```bash CLI theme={null}
kha agents create --file - <<'JSON'
{
  "name": "Order Assistant",
  "model": {"id": "kimi-k3.1-pro"},
  "system": "When handling order inquiries, call lookup_order to fetch the live order status.",
  "tools": [
    {
      "type": "agent_toolset",
      "name": "agent_toolset_20261101",
      "default_config": {"enabled": false}
    },
    {
      "type": "custom",
      "name": "lookup_order",
      "description": "Look up the current status of an order in your system.",
      "input_schema": {
        "type": "object",
        "properties": {
          "order_id": {"type": "string"}
        },
        "required": ["order_id"]
      }
    }
  ]
}
JSON
```

> [!NOTE]
>
> When a new agent omits `agent_toolset`, the platform loads the default built-in toolset `agent_toolset_20261101` automatically. If your agent needs only custom tools, explicitly declare the built-in toolset with `default_config.enabled: false` as shown above.

### Receive and execute tool calls

After creating the agent, follow [Create a Session](https://platform.kimi.ai/docs/hosted-agents/sessions.md) to create a session, subscribe to the [Event Stream](https://platform.kimi.ai/docs/hosted-agents/event-stream.md), and send a user message. When the model decides to call a custom tool, the event stream emits `agent.custom_tool_use`:

```json theme={null}
{
  "id": "sevt_01h455vb4pex5vsknk084sn02s",
  "processed_at": "2026-01-01T00:00:00Z",
  "type": "agent.custom_tool_use",
  "data": {
    "name": "lookup_order",
    "input": {
      "order_id": "order_123"
    }
  }
}
```

Execute the tool locally and return the result via `POST /v1/sessions/{session_id}/events`, passing the event's `id` as `event_id`:

```bash theme={null}
curl -X POST https://api.moonshot.ai/v1/sessions/$SESSION_ID/events \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta" \
  -H "Content-Type: application/json" \
  -d '{
    "events": [
      {
        "type": "user.custom_tool_result",
        "data": {
          "event_id": "sevt_01h455vb4pex5vsknk084sn02s",
          "content": [
            {"type": "text", "text": "shipped"}
          ],
          "is_error": false
        }
      }
    ]
  }'
```

The endpoint returns `202` when the submission is accepted. `content` is an ordered array of tool result blocks; `is_error` indicates whether the tool call failed and defaults to `false` when omitted.

### Waiting state and resumption

While waiting for the client to return a custom tool result or tool confirmation, the calling thread pauses execution. When no other threads in the session are running, the `session.status` event reports `data.status` as `idle` and `data.stop_reason.type` as `requires_action`. `event_ids` lists all pending event IDs—including both `agent.custom_tool_use` events awaiting custom tool results and `agent.tool_use` events awaiting confirmation:

```json theme={null}
{
  "type": "session.status",
  "data": {
    "status": "idle",
    "stop_reason": {
      "type": "requires_action",
      "event_ids": [
        "sevt_01h455vb4pex5vsknk084sn02s"
      ]
    }
  }
}
```

Once every pending confirmation and custom tool result on that thread has been submitted, the thread resumes execution. Resubmitting an identical result is idempotent and does not produce a duplicate result; submitting a different result for an already-resolved call returns `409 conflict_error`.

In multi-agent sessions, waiting pauses only the calling thread: while other threads continue running, session-level `session.status` stays `running`, and the waiting state is reflected on that thread's `session.thread_status` event instead. When `session.status` transitions to `idle`, `event_ids` aggregates pending events across all waiting threads in the session, whereas `session.thread_status` covers only its respective thread. For thread-level events, see [Multi-Agent Orchestration](https://platform.kimi.ai/docs/hosted-agents/multiagent-orchestration.md#observe-threads-and-events).

### Override tools for a single session

When creating a session, you can pass `agent_overrides.tools` to replace the entire tool configuration of the frozen agent version. Custom tools follow the same declaration and validation rules as on an agent:

```json theme={null}
{
  "agent_id": "agent_your_agent_id",
  "environment_id": "env_your_environment_id",
  "agent_overrides": {
    "tools": [
      {
        "type": "agent_toolset",
        "name": "agent_toolset_20261101",
        "default_config": {"enabled": false}
      },
      {
        "type": "custom",
        "name": "lookup_order",
        "description": "Look up the current status of an order in your system.",
        "input_schema": {
          "type": "object",
          "properties": {
            "order_id": {"type": "string"}
          },
          "required": ["order_id"]
        }
      }
    ]
  }
}
```

`tools` uses full-replacement semantics rather than merging with the frozen agent version's custom or MCP tool arrays. However, if the array omits `agent_toolset`, the platform keeps the `agent_toolset` declaration from the bound agent (or the currently effective one), or prepends `agent_toolset_20261101` if none exists. When updating a session, passing `tools: []` clears the tools override and inherits the bound agent's tools again. This override affects only the current session and neither modifies the agent nor creates a new agent version.

## Dynamic on-demand loading

As toolsets grow—especially when plugins bring large sets of MCP tools—inlining every tool schema into every model turn consumes significant context window space. Toolsets support two schema loading modes via `load_mode`:

| Value | Description |
| - | - |
| `eager` | Full tool schemas are inlined into every model turn. Most built-in tools use this mode by default |
| `on_demand` | The model initially sees only tool names, and full schemas are loaded into context only after selection. Plugin MCP toolsets use this mode by default |

Among built-in toolsets, all tools in `agent_toolset_20261101` default to `eager`. In `agent_toolset_20260901`, `search_image_by_text` and `search_image_by_image` default to `on_demand`, while all other tools default to `eager`.

How on-demand loading works:

1. The platform advertises the list of `on_demand` tool names to the model without their parameter schemas.
2. The model calls the `select_tools` meta-tool by name to load the tools it needs, bringing their schemas into context.
3. From that point on, the model calls those tools like any standard tool.

`load_mode` also supports two-level configuration: `default_config.load_mode` applies to the entire toolset, while `load_mode` inside `configs` overrides individual tools. Models that do not support on-demand loading automatically fall back to `eager` loading—behaving the same as when `load_mode` is unset, with no code changes required.

> [!NOTE]
>
> `select_tools` calls appear in the event stream as ordinary `agent.tool_use` events and require no special handling on the client. When a model or provider does not support on-demand loading, the platform falls back silently without raising errors.

## Next steps

> [card] [Connect MCP tools](https://platform.kimi.ai/docs/hosted-agents/mcp.md)
>
> Connect external tools and data sources to your agent via MCP servers.

> [card] [Configure tool permissions](https://platform.kimi.ai/docs/hosted-agents/permissions.md)
>
> Learn how `enabled` and `permission_policy` govern tool execution.

> [card] [Inspect tool call events](https://platform.kimi.ai/docs/hosted-agents/event-stream.md)
>
> Subscribe to tool call and result events to track every step of execution.
