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

# Multi-Agent Orchestration

> Configure task delegation across agents, run child threads within a single session, and observe multi-agent execution status and events.

Multi-agent orchestration lets one agent act as a coordinator agent that delegates tasks to one or more child threads within the same session.
The coordinator agent receives user input and organizes the work, while each child thread runs its subtask under a designated agent configuration and returns the result.

The workflow covered on this page is: configure delegatable agents, create a session, send a task, observe the child threads spawned by the model, and read each thread's status and events.

## When to use multi-agent orchestration

Use multi-agent orchestration when a task breaks cleanly into well-bounded subtasks, or when different subtasks require different agent configurations.

Common use cases include:

* Processing independent sources or subtasks in parallel and having the coordinator agent synthesize the final output.
* Delegating specialized work such as code review or source retrieval to agents equipped with dedicated tools or skills.
* Running multiple instances of the same agent configuration to handle separate inputs concurrently.
* Inspecting or auditing the execution trace of each subtask independently.

If a task does not need to be split up, use a single agent and session directly.
Multi-agent orchestration adds overhead in agent configuration, thread management, and event observation—avoid splitting simple tasks just to involve multiple agents.

## Coordinator agent and child threads

When you create a session, the platform creates a coordinator thread.
It serves as the session's default entry point and handles user input submitted through session-level endpoints.

When the coordinator agent decides to delegate work, the platform creates child threads inside the same session.
Each child thread executes the subtask assigned by the coordinator agent and returns its result to the coordinator agent.

```text theme={null}
Session
└── Coordinator thread
    ├── Child thread A
    ├── Child thread B
    └── Child thread C
```

Agents, sessions, and threads have distinct responsibilities:

| Object | Role |
| - | - |
| Agent | Defines the model, system prompt, tools, MCP servers, skills, plugins, and optional delegation configuration |
| Session | Pins the agent version used for the run and binds the execution environment and session resources |
| Coordinator thread | Created with the session; receives user input and manages delegation |
| Child thread | Created at runtime by the coordinator agent; executes a specific subtask and retains its own execution trace |

The coordinator thread and child threads belong to the same session, but each thread maintains its own status, event history, and live event stream.
Sharing an execution environment does not mean sharing the full model context.

A coordinator agent can spawn child threads, whereas child threads cannot spawn further nested threads.

## Configure delegatable agents

When creating or updating a coordinator agent, declare the agents it can delegate to in `multiagent.agents`.
Use `type` to specify the reference source:

* `type: "agent"`: References another existing agent. Set `id` to that agent's ID; `version` is optional, and if omitted, the platform pins its latest version at write time.
* `type: "self"`: References the coordinator agent itself so child threads reuse the coordinator agent's currently pinned version and configuration; `id` is not required.

```json theme={null}
{
  "multiagent": {
    "agents": [
      { "type": "agent", "id": "agent_researcher" },
      { "type": "agent", "id": "agent_writer", "version": "3" },
      { "type": "self" }
    ]
  }
}
```

On creation, `agents` must contain 1–20 entries. On update, pass `agents: []` to clear the delegation roster.
Referencing the same agent more than once, using duplicate display names, referencing an archived agent, or referencing an agent that itself has `multiagent` configured fails at write time.
Updating a referenced agent afterward does not alter an already saved delegation configuration.
To have the coordinator agent use a newer version of a referenced agent, update the coordinator agent to generate a new immutable version.

### Create a coordinator agent

The example below creates a coordinator agent and pins its roster of delegatable agents at creation time.
This request neither spawns child threads nor creates the referenced agents: replace `agent_researcher` with an agent ID that already exists in your project.
The `self` entry in the roster allows the coordinator agent to spawn child threads that reuse its own pinned version and configuration.

```bash cURL theme={null}
curl -sS -X POST "https://api.moonshot.ai/v1/agents" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "Investment Research Coordinator",
    "model": { "id": "kimi-k3.1-pro" },
    "system": "You receive tasks and delegate subtasks to appropriate child threads.",
    "multiagent": {
      "agents": [
        { "type": "agent", "id": "agent_researcher" },
        { "type": "self" }
      ]
    }
  }'
```

```bash CLI theme={null}
kha agents create --file - <<'JSON'
{
  "name": "Investment Research Coordinator",
  "model": { "id": "kimi-k3.1-pro" },
  "system": "You receive tasks and delegate subtasks to appropriate child threads.",
  "multiagent": {
    "agents": [
      { "type": "agent", "id": "agent_researcher" },
      { "type": "self" }
    ]
  }
}
JSON
```

Once created, `id` in the response is the coordinator agent's ID, which you pass when creating a session.
`multiagent.agents` in the response shows the pinned agent versions; because `self` resolves to the coordinator agent itself at write time, the list also includes an entry pointing to the coordinator agent's own ID and version.
The snippet below shows only the fields needed for the rest of this guide—refer to the OpenAPI specification for the full response schema:

```json theme={null}
{
  "id": "agent_coordinator",
  "name": "Investment Research Coordinator",
  "version": "1",
  "multiagent": {
    "agents": [
      {
        "id": "agent_researcher",
        "version": "3"
      },
      {
        "id": "agent_coordinator",
        "version": "1"
      }
    ]
  }
}
```

Save the coordinator agent's `id` for creating a session next:

```bash theme={null}
export AGENT_ID="agent_coordinator"
```

## Create and run a session

### Create a session

Create a session with the coordinator agent from the previous step and an execution environment.
Replace `env_xxx` with the ID of an actual execution environment.

```bash cURL theme={null}
curl -sS -X POST "https://api.moonshot.ai/v1/sessions" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --header "Content-Type: application/json" \
  --data '{
    "agent_id": "agent_coordinator",
    "environment_id": "env_xxx",
    "title": "Multi-agent task example"
  }'
```

```bash CLI theme={null}
kha sessions create --agent agent_coordinator --environment env_xxx --title "Multi-agent task example"
```

Once created, `id` in the response is the session ID used to send tasks and query threads:

```json theme={null}
{
  "id": "sesn_example",
  "agent_id": "agent_coordinator",
  "environment_id": "env_xxx",
  "status": "idle",
  "title": "Multi-agent task example"
}
```

```bash theme={null}
export SESSION_ID="sesn_example"
```

### Send a task

Send a `user.message` event through the session events endpoint.
Pass message content as a `content` array where each content block declares its own `type`.

```bash cURL theme={null}
curl -sS -X POST "https://api.moonshot.ai/v1/sessions/$SESSION_ID/events" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --header "Content-Type: application/json" \
  --data '{
    "events": [
      {
        "type": "user.message",
        "data": {
          "content": [
            {
              "type": "text",
              "text": "Split this task into two subtasks — source retrieval and result synthesis — and summarize the final output."
            }
          ]
        }
      }
    ]
  }'
```

```bash CLI theme={null}
kha sessions send "$SESSION_ID" "Split this task into two subtasks — source retrieval and result synthesis — and summarize the final output."
```

Clients submit user messages only to the session.
When the request succeeds, the platform wakes the coordinator thread.
Based on the task and its configured delegation roster, the coordinator agent's model decides whether to delegate, which agent to select, and how many child threads to spawn. When the model calls `spawn_subagent`, the platform creates the child thread in the same session and starts execution.

## Synchronous and asynchronous delegation

You guide delegation through agent configuration and instructions rather than supplying tool arguments directly.
`spawn_subagent` is a runtime tool invoked by the model, not a REST API endpoint called by clients.
If your client needs deterministic control over subtask inputs and execution order, orchestrate multiple session calls from your client instead of using multi-agent delegation.

An example `spawn_subagent` tool input looks like this:

```json theme={null}
{
  "agent_type": "Research Analyst",
  "description": "Research deployment history",
  "prompt": "Check recent deployment logs and return an evidence-backed summary.",
  "run_in_background": true
}
```

Field descriptions:

* `agent_type` is required with no default value—it specifies the display name of an agent in the delegation roster.
* `description` is a short label identifying the subtask.
* `prompt` provides the full instructions needed for the child thread to carry out the subtask.
* `run_in_background: false` runs the child thread synchronously and is the default behavior.
* `run_in_background: true` runs the child thread asynchronously.

### Synchronous delegation

Synchronous delegation waits until the child thread returns a report, enters `idle`, or terminates before the coordinator agent resumes execution.

Use synchronous delegation when subsequent steps depend directly on the child thread's output.

### Asynchronous delegation

Asynchronous delegation returns immediately once the child thread is created and starts running.
When the child thread finishes a turn, it delivers its report back to the coordinator agent, which can continue doing other work in the meantime or wait for messages.

The tool result for asynchronous delegation is a text message containing the child thread ID and follow-up instructions:

```text theme={null}
Subagent "Research Analyst" started in background (thread id: sthr_child_example). Its report will be delivered to you automatically when it finishes a turn — no need to poll. Use send_message to give it follow-up work, check_subagent_status to inspect it, and delete_subagent to terminate it and free its slot.
```

The text above illustrates the model-side tool result; exact wording is determined at runtime.

After finishing its work, a child thread remains `idle` and is not deleted automatically; the coordinator agent can call `delete_subagent` to terminate it, transitioning the thread status to `terminated`.
If follow-up work is needed on the same subtask, the coordinator agent can reuse the child thread by sending further messages with `send_message`. Clients cannot send messages directly to child threads.

## Send messages between agents

All inter-agent messages in Kimi Hosted Agents are routed through the coordinator thread.
The coordinator thread can send a message to a specific child thread or broadcast to all child threads, whereas child threads can only send results or questions back to the coordinator thread.
Child threads cannot communicate directly with each other or send messages across sessions.

```text theme={null}
                Coordinator thread
               /        |         \
  Child thread A  Child thread B  Child thread C
```

### Send messages: `send_message`

The coordinator agent can message a specific child thread or broadcast to all child threads:

```json theme={null}
{
  "agent_id": "sthr_child_example",
  "content": "Also check the Q2 2026 deployment logs."
}
```

To broadcast to all child threads, set `agent_id` to `all`:

```json theme={null}
{
  "agent_id": "all",
  "content": "Explicitly list any unverified facts in your report."
}
```

### Wait for messages: `wait_for_message`

The coordinator agent—or an asynchronous child thread participating in message-based collaboration—can call `wait_for_message` to wait for incoming messages:

```json theme={null}
{
  "timeout": 300
}
```

When a child thread report arrives, the tool result text includes the message count, source thread, and body:

```text theme={null}
1 message(s) received:

<subagent_message from="sthr_child_example">Inspection complete. No new deployment errors found.</subagent_message>
```

The snippet above illustrates the model-side message result.
On the client side, you can read the source thread (`from_session_thread_id`) and source agent display name (`from_agent_name`) from the `agent.thread_message_received` event payload.
To inspect the child thread's full execution trace, read the thread's event history rather than relying on the `wait_for_message` return text.

## Shared resources and context isolation

Agents, sessions, and threads manage configuration at different scopes:

| Scope | Contents |
| - | - |
| Agent level | Model, system prompt, tools, MCP servers, skills, and plugins |
| Session level | Pinned agent version, execution environment, and session resources |
| Thread level | Thread status, event history, and live event stream |

Each child thread runs with the pinned version and configuration of its selected agent.
Session-bound resources such as files, vaults, and memory stores are managed through session configuration; see [Create a Session](https://platform.kimi.ai/docs/hosted-agents/sessions.md) for how to bind them.

Session-level `agent_overrides` apply only to the current session and do not modify any stored agent resource. Setting `agent_overrides.roster` when creating a session replaces the delegation roster and pins the referenced versions for this session.
Other `agent_overrides` fields (such as `model`, `system`, `tools`, `mcp_servers`, `skills`, and `plugins`) take effect only on the coordinator thread and are not propagated to child threads, including `self` entries. Each child thread runs the agent version pinned in the effective roster for the session.

## Observe threads and events

After sending a task, you can observe overall progress on the coordinator thread through the session-level event stream.
To inspect detailed activity on a child thread, first list the threads in the session and then query the target thread using its `id`.

### List threads in a session

```bash cURL theme={null}
curl -sS \
  "https://api.moonshot.ai/v1/sessions/$SESSION_ID/threads" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha sessions threads list "$SESSION_ID"
```

Threads are returned with the coordinator thread first, followed by child threads in creation order:

```json theme={null}
{
  "items": [
    {
      "id": "sthr_coordinator",
      "session_id": "sesn_example",
      "status": "idle"
    },
    {
      "id": "sthr_researcher",
      "session_id": "sesn_example",
      "parent_thread_id": "sthr_coordinator",
      "status": "idle"
    }
  ],
  "next_page_token": "next-page-token"
}
```

Use `id` from the list response for subsequent thread queries.
The coordinator thread has no `parent_thread_id`, whereas child threads point to their parent thread via `parent_thread_id`.
If the response includes `next_page_token`, fetch subsequent pages rather than assuming the current page contains all threads.

### Get thread details

Set `$THREAD_ID` to the `id` of the target thread from the thread list:

```bash cURL theme={null}
export THREAD_ID="sthr_researcher"

curl -sS \
  "https://api.moonshot.ai/v1/sessions/$SESSION_ID/threads/$THREAD_ID" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
export THREAD_ID="sthr_researcher"

kha sessions threads get "$SESSION_ID" "$THREAD_ID"
```

The `status` field in the response indicates whether the thread is still running:

```json theme={null}
{
  "id": "sthr_researcher",
  "session_id": "sesn_example",
  "parent_thread_id": "sthr_coordinator",
  "status": "idle",
  "created_at": "2026-08-29T04:00:01Z",
  "updated_at": "2026-08-29T04:01:40Z"
}
```

### Read thread event history

```bash cURL theme={null}
curl -sS \
  "https://api.moonshot.ai/v1/sessions/$SESSION_ID/threads/$THREAD_ID/events" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha sessions threads events "$SESSION_ID" "$THREAD_ID" --all -o json
```

The event history shows the thread's status transitions and message exchanges:

```json theme={null}
{
  "items": [
    {
      "id": "sevt_status",
      "processed_at": "2026-08-29T04:00:05Z",
      "type": "session.thread_status",
      "session_thread_id": "sthr_researcher",
      "data": {
        "status": "running"
      }
    },
    {
      "id": "sevt_message_received",
      "processed_at": "2026-08-29T04:01:40Z",
      "type": "agent.thread_message_received",
      "session_thread_id": "sthr_researcher",
      "data": {
        "content": [
          {
            "type": "text",
            "text": "Check recent deployment logs and return an evidence-backed summary."
          }
        ],
        "from_session_thread_id": "sthr_coordinator"
      }
    }
  ],
  "next_page_token": "next-page-token"
}
```

The thread creation event `session.thread_created` is recorded only in the coordinator thread's history—observe it through the session-level event stream (coordinator thread), as it does not appear in the child thread's own event history.
The response above highlights only the event fields relevant to multi-agent orchestration.
For the full set of event types, fields, and pagination rules, see [Event Stream](https://platform.kimi.ai/docs/hosted-agents/event-stream.md).

### Subscribe to live thread events

```bash cURL theme={null}
curl -sS -N \
  "https://api.moonshot.ai/v1/sessions/$SESSION_ID/threads/$THREAD_ID/events/stream" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --header "Accept: text/event-stream"
```

```bash CLI theme={null}
kha sessions attach "$SESSION_ID" --thread "$THREAD_ID"
```

Live thread events include status transitions such as:

```text theme={null}
id: 4096
event: session.thread_status
data: {"id":"sevt_status","processed_at":"2026-08-29T04:00:05Z","session_thread_id":"sthr_researcher","type":"session.thread_status","data":{"status":"running"}}
```

The frame above illustrates how to observe events; actual event fields and ordering follow runtime behavior.
The `id:` line in each SSE frame is a numeric resume cursor that lets you resume streaming after a disconnect; see [Event Stream](https://platform.kimi.ai/docs/hosted-agents/event-stream.md) for details.
Use `session_thread_id` in the event payload to identify which thread an event belongs to.
A thread cursor is valid only for that specific thread's event stream and cannot be used across other threads or sessions.

### Archive a child thread

You can archive a child thread to terminate it and cancel any in-flight execution without waiting for it to become `idle`. The coordinator thread cannot be archived separately; archive the session instead.

```bash cURL theme={null}
curl -sS -X POST \
  "https://api.moonshot.ai/v1/sessions/$SESSION_ID/threads/$THREAD_ID/archive" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha sessions threads archive "$SESSION_ID" "$THREAD_ID"
```

The endpoint responds with `204 No Content` on success.
Archiving a thread does not delete its event history.

## Event sequence of a delegation

A typical asynchronous delegation produces events in roughly the following order:

```text theme={null}
1. Coordinator thread receives user.message
2. Coordinator agent calls spawn_subagent
3. session.thread_created
4. Task message from coordinator thread is recorded as agent.thread_message_sent
5. Child thread enters running
6. Child thread finishes, enters idle, and delivers its report to the coordinator thread's inbox
7. Coordinator agent receives agent.thread_message_received
8. Coordinator agent synthesizes the results
9. Coordinator thread enters idle
```

Exact event ordering varies with synchronous vs. asynchronous delegation, task execution behavior, and error handling.
Use this sequence as a guide to what to look for rather than assuming every run emits an identical sequence.

## Best practices

### Define clear task boundaries for child threads

In `prompt`, state the inputs, expected outputs, success criteria, and what supporting evidence to retain.
For example:

```text theme={null}
Task: Review deployment logs from the past 30 days.
Output: Confirmed facts, supporting evidence, open questions, and recommended next steps.
```

### Configure only the agents you need

Only add agents to the roster if the coordinator agent genuinely needs to delegate to them.
Adding unnecessary agents gives the model more candidates to choose from and increases the effort required to maintain the roster.

### Standardize the report format

Instruct child threads to return reports using a consistent structure:

```markdown theme={null}
## Conclusion

## Evidence

## Open Questions

## Recommendations
```

A consistent report structure reduces formatting variance and extraneous text when the coordinator agent synthesizes results.

### Audit with thread-level event streams

Do not rely solely on the coordinator agent's final summary.
When debugging or auditing, list the threads in the session and inspect each target child thread's event history and live event stream independently.

## Next steps

> [card] [Configure agents and delegation](https://platform.kimi.ai/docs/hosted-agents/agents.md)
>
> Configure agents, tools, and multi-agent delegation rosters.

> [card] [Start a multi-agent session](https://platform.kimi.ai/docs/hosted-agents/sessions.md)
>
> Create a session and submit task inputs.

> [card] [Inspect thread events](https://platform.kimi.ai/docs/hosted-agents/event-stream.md)
>
> Read event history, subscribe to SSE streams, and resume from cursors.

> [card] [Explore the investment research team design](https://platform.kimi.ai/docs/hosted-agents/official-investment-research-agent.md)
>
> See the full design of the official multi-agent investment research team.
