> ## 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.

# Create and Manage Agents

> Create, update, version, and archive configuration objects for Kimi Hosted Agents.

An **Agent** is a **persistent, versioned** configuration object in Kimi Hosted Agents that defines how it runs: model selection, the system prompt, and available tools. A **Session** references an agent via `agent_id` to run tasks and pins the agent version active when the session is created.

> [!NOTE]
>
> Every update to an agent's configuration produces a **new immutable version**, while older versions remain intact. Existing sessions continue using the version pinned at creation time and are unaffected by subsequent updates—ensuring consistent behavior even when long-running tasks pause and resume.

## Agent fields

| Field | Type | Required | Description |
| - | - | - | - |
| `name` | string | Required | Agent name, 1–256 characters |
| `model` | object \| string | Required | Model selection: pass a model ID string directly such as `"kimi-k3.1-pro"`, or pass a structured configuration `{"id": "kimi-k3.1-pro", "reasoning_effort": ..., "provider": ...}`; `reasoning_effort` (`"low" \| "medium" \| "high" \| "max"`, a hint the selected model may ignore) and `provider` (leave empty to use the platform default) are optional |
| `system` | string | Optional | System prompt, up to 100,000 characters |
| `tools` | array\[object] | Optional | List of tool declarations, up to 128 entries; built-in toolsets, MCP toolsets, and custom tools can be combined freely (see "Tool declarations" below) |
| `mcp_servers` | array\[object] | Optional | MCP server connection definitions, up to 20 entries; `name` must be unique within the same agent (see "MCP servers" below) |
| `skills` | array\[object] | Optional | Attached skills (see "Skill references" below) |
| `plugins` | array\[object] | Optional | Attached plugins. Official plugins require only `plugin_id`; custom plugins can also specify an exact version or pass `latest`. See [Plugins](https://platform.kimi.ai/docs/hosted-agents/plugins.md) |
| `description` | string | Optional | Description, up to 2,048 characters |
| `metadata` | object | Optional | Custom key-value pairs, up to 16 entries |
| `multiagent` | object | Optional | Delegation configuration. `agents` declares the subagent roster (1–20 entries of `type: "agent"` or `"self"`), pinning each referenced agent's version on write; pass `agents: []` on update to clear the roster. See [Multi-Agent Orchestration](https://platform.kimi.ai/docs/hosted-agents/multiagent-orchestration.md) |
| `id` | string | Read-only | Stable agent ID (`agent_` prefix), unchanged after creation |
| `version` | string | Read-only | Current immutable version string, updated on every modification; can be passed in update requests for optimistic concurrency checks |
| `created_at` / `updated_at` / `archived_at` | string | Read-only | Creation, last update, and archival timestamps |
| `scope` | string | Read-only | Resource ownership scope; `"official"` indicates an official platform agent |

### Tool declarations

The `tools` array declares which tools the agent can use. Each entry is distinguished by its `type` field:

| Category | `type` value | Description |
| - | - | - |
| Built-in toolset | `"agent_toolset"` | Declares a platform built-in toolset (file read/write, code execution, web search, and more). `name` is required and accepts `"agent_toolset_20261101"` or `"agent_toolset_20260901"` (`"default_toolset_20260901"` is a deprecated alias of `"agent_toolset_20260901"`); `default_config` sets group-wide defaults (`enabled`, `permission_policy`, `load_mode`), while `configs` overrides individual tools |
| MCP toolset | `"mcp_toolset"` | Exposes tools from an MCP server. `mcp_server_name` references a server declared in the same agent's `mcp_servers`; the toolset also supports `default_config` and `configs` |
| Custom tool | `"custom"` | Declares a client-executed tool. `name`, `description`, and `input_schema` are required; the platform dispatches tool calls over the event stream and the client returns results after execution. See [Custom tools](https://platform.kimi.ai/docs/hosted-agents/tools.md#custom-tools) |

If no `agent_toolset` is declared on creation, `agent_toolset_20261101` is prepended to `tools` by default (counting toward the 128-item limit). Once you explicitly declare an `agent_toolset`, only the declared toolset is loaded; each `tools` list allows at most one sandbox toolset, and mixing `agent_toolset_20260901` with `agent_toolset_20261101` returns `400` `invalid_parameter_error`. To disable sandbox tools, explicitly declare an `agent_toolset` with `default_config.enabled` set to `false` for the entire toolset. For detailed tool configuration options, see [Tools](https://platform.kimi.ai/docs/hosted-agents/tools.md).

### MCP servers

`mcp_servers` stores connection metadata: `type` (currently only `"url"` is supported), `name`, `url`, and optional `headers`. `headers` specifies custom non-sensitive HTTP request headers (such as `User-Agent` or tenant routing headers), up to 16 entries; they are accepted in requests and omitted from responses. On update, the entire `mcp_servers` array is replaced—any server omitted from the request is removed. `headers` follows a different rule: if `headers` is omitted or empty and the server's `name`, `type`, and `url` are unchanged, existing headers are preserved; if `headers` is non-empty, it replaces all headers for that server, and setting a key to an empty string deletes that key. **Access credentials are not stored in the agent configuration**—instead, they are injected via a Vault when creating a session. See [MCP](https://platform.kimi.ai/docs/hosted-agents/mcp.md) and [Vaults](https://platform.kimi.ai/docs/hosted-agents/vaults.md).

### Skill references

Each entry in `skills` contains `skill_id` and `version`. When creating or updating an agent, omitting `version` pins it to the latest version available at write time; specifying an exact version pins that version; explicitly passing `"latest"` preserves the literal `"latest"` value and re-resolves it whenever the agent is read or woken up. See [Skills](https://platform.kimi.ai/docs/hosted-agents/skills.md) for details.

## Official agents vs. custom agents

Agents fall into two categories:

| | Official agents | Custom agents |
| - | - | - |
| Source | Prebuilt and maintained by the platform | Created by you via the API or console |
| `scope` | `"official"` | Your project |
| Read access | Visible to all users | Visible only to your project |
| Update / Archive | **Not allowed** (read-only via API) | Allowed |
| Create sessions | Can reference `agent_id` directly | Allowed |

> [!NOTE]
>
> Official agents are read-only: you can inspect their full configuration and reference them directly when creating sessions, but update and archive requests are rejected. To customize one, create your own custom agent based on the official agent's configuration.

## API endpoints

| Operation | Method and path |
| - | - |
| Create agent | `POST /v1/agents` |
| List agents | `GET /v1/agents` |
| Get agent | `GET /v1/agents/{id}` |
| Update agent | `PATCH /v1/agents/{id}` |
| Archive agent | `POST /v1/agents/{id}/archive` |
| List version history | `GET /v1/agents/{id}/versions` |

When listing agents, you can pass `exclude_multiagent=true` to return only agents without `multiagent` configured—useful when building a delegation list and filtering out agents that already delegate to others.

In addition to the console and REST API, you can create, update, and archive agents with the [kha CLI](https://platform.kimi.ai/docs/hosted-agents/kha.md). The examples below show both cURL and `kha` CLI commands; cURL examples read your API key from the `KIMI_API_KEY` environment variable.

## Create an agent

Creating a minimal working agent requires only `name` and `model`, though you will typically include a `system` prompt as well. A successful request returns the full agent object, including its `id` and initial `version`. Save the `id` for creating sessions later.

```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": "Research Assistant",
    "model": {"id": "kimi-k3.1-pro"},
    "system": "You are a rigorous research assistant skilled at retrieving, organizing, and citing sources.",
    "description": "Hosted agent for in-depth research tasks"
  }'
```

```bash CLI theme={null}
kha agents create --file - <<'JSON'
{
  "name": "Research Assistant",
  "model": {"id": "kimi-k3.1-pro"},
  "system": "You are a rigorous research assistant skilled at retrieving, organizing, and citing sources.",
  "description": "Hosted agent for in-depth research tasks"
}
JSON
```

> [!TIP]
>
> The `--file` flag in `kha` accepts both JSON and YAML, and `-` reads from standard input. Request bodies with nested structures must be passed as a single payload via `--file` and cannot be combined with individual field flags. See [Request body input](https://platform.kimi.ai/docs/hosted-agents/kha.md#request-body-input) for details.

## Update an agent

Updates follow an **immutable versioning model**: `PATCH` does not mutate the configuration in place, but instead creates a brand-new immutable version based on the current configuration while preserving earlier versions. On the agent details page in the console, you can edit the current version from the **Configuration** tab; saving also creates a new immutable version.

Keep two rules in mind when updating via the API:

1. **Optional `version` concurrency control**: You can include the current `version` returned when reading the agent in the request body. If the agent was modified in the meantime, the server responds with `409`; re-fetch the latest `version` and retry. Omitting `version` skips the concurrency check.
2. **Only included fields are updated**: Omitting a field leaves it unchanged; explicitly passing `null` returns `400` (`invalid_parameter_error`). Array fields (`skills`, `plugins`) and `metadata` are **replaced in full**—pass an empty array or empty object to clear them. `tools` follows the same rule, except that omitting `agent_toolset` (including passing `[]`) keeps the current version's `agent_toolset` declarations, or prepends `agent_toolset_20261101` if none exists; if you update an older version that has no `agent_toolset` and omit `tools`, the request returns `400` `failed_precondition_error`. `mcp_servers` replaces the array in full, except for `headers`, which preserves or replaces entries according to the rules under "MCP servers" above.

The example below updates only the system prompt while leaving all other settings unchanged:

```bash cURL theme={null}
curl -X PATCH https://api.moonshot.ai/v1/agents/agent_xxx \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta" \
  -H "Content-Type: application/json" \
  -d '{
    "version": "1",
    "system": "You are a rigorous research assistant. Every conclusion must include source citations."
  }'
```

```bash CLI theme={null}
kha agents update agent_xxx --version 1 --system "You are a rigorous research assistant. Every conclusion must include source citations."
```

> [!TIP]
>
> Updating an agent does not affect existing sessions—each session pins the agent version at creation time and continues using that version even after interruption and recovery. Only newly created sessions pick up the updated version.

## View version history

Every update creates a new immutable version. You can inspect the full configuration of any historical version through the version history endpoint. Results are paginated; use `next_page_token` in the response to fetch the next page (the field is omitted when there are no more results).

```bash cURL theme={null}
curl "https://api.moonshot.ai/v1/agents/agent_xxx/versions?page_size=10" \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha agents versions agent_xxx --limit 10
```

On the agent details page in the console, you can also browse historical versions using the **Agent Version** selector on the **Configuration** tab. Selecting a historical version populates the form with its full configuration and displays a notice stating that historical versions are read-only snapshots and cannot be saved. For unarchived custom agents, switch back to **Current Version** to continue editing and saving—saving creates a new immutable version without overwriting historical versions.

## View associated resources and runtime metrics

The agent details page in the console also provides the following tabs:

* **Sessions**: Lists sessions and their pinned versions, with filtering by version, source, and status. After an agent is updated, existing sessions continue displaying the version pinned at creation time; newly created sessions without an explicit version use the current version.
* **Deployments**: Shows associated triggers along with their version, next run, last run, and creation time.
* **Observability**: Shows total sessions, session success rate, tool calls, and token usage, as well as recent sessions and associated triggers.

## Archive an agent

When an agent is no longer needed, you can archive it by selecting **Archive** from the action menu in the console's agent list or by calling the archive endpoint. Once archived:

* The agent becomes **read-only**, and update requests are rejected.
* It is hidden by default from the agent list and the agent selector when creating a session, and **can no longer be used to create new sessions**.
* The agent and its historical versions remain directly readable.
* Existing sessions are unaffected and can continue running and resuming.

Archiving succeeds with `204` and an empty response body—do not attempt to parse response JSON.

```bash cURL theme={null}
curl -X POST https://api.moonshot.ai/v1/agents/agent_xxx/archive \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha agents archive agent_xxx
```

> [!WARNING]
>
> Archiving is irreversible. Confirm that you no longer need to create new sessions with this agent before proceeding.

## Next steps

> [card] [Start a task with your agent](https://platform.kimi.ai/docs/hosted-agents/sessions.md)
>
> Launch a task session using the agent you created.

> [card] [Configure built-in and custom tools](https://platform.kimi.ai/docs/hosted-agents/tools.md)
>
> Learn how to configure the built-in toolset and custom tools.

> [card] [Attach skills](https://platform.kimi.ai/docs/hosted-agents/skills.md)
>
> Mount versioned skill packages onto your agent.

> [card] [Connect MCP servers](https://platform.kimi.ai/docs/hosted-agents/mcp.md)
>
> Connect remote MCP servers and inject access credentials.

> [card] [Manage access credentials](https://platform.kimi.ai/docs/hosted-agents/vaults.md)
>
> Store and manage credentials for MCP and external services.
