MoonshotAI / MoonshotAI/kimi-cli

Subagent context usage is not tracked or visible in parent agent statistics

Open
#2,024 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
11.4k
Forks
1.3k
Avg merge
9h 47m
Merged PRs (30d)
2

Description

Problem Description

Currently, subagent context/token usage is completely isolated from the parent agent'''s statistics. This leads to:

  1. Invisible subagent context consumption: The parent agent'''s status bar shows only its own context usage, giving users no visibility into how much context their subagents are consuming.
  2. No compaction trigger for subagents: Auto-compaction only considers the parent context, so subagents can grow unbounded without triggering compaction.
  3. No inspection mechanism: There is no command, API, or UI feature to check a subagent'''s current token count or context usage percentage.

Current Behavior

  • Each subagent gets its own Context instance with a separate context.jsonl file (src/kimi_cli/subagents/core.py:59)
  • Each subagent gets its own KimiSoul instance (src/kimi_cli/subagents/core.py:85)
  • StatusUpdate wire messages only contain the current soul'''s context metrics (src/kimi_cli/soul/kimisoul.py:951-961)
  • The UI status bar (src/kimi_cli/ui/shell/prompt.py) only renders the parent soul'''s StatusSnapshot
  • The Vis API /subagents endpoint only returns raw file sizes (bytes), not token counts

Expected Behavior

Users should be able to:

  1. See subagent context usage aggregated in the parent agent'''s status, OR
  2. Have a way to inspect individual subagent context usage (e.g., a slash command or API endpoint)

Possible Solutions

  1. Aggregate in parent status: Sum active subagents''' token_count into the parent'''s StatusSnapshot.context_usage
  2. Expose subagent stats: Add token_count/context_usage fields to AgentInstanceRecord and expose via Vis API
  3. New slash command: Add /subagents command to list running subagents with their context usage
  4. Event propagation: Forward subagent StatusUpdate events to the parent wire stream

Additional Context

The Context class already tracks _token_count internally, so the data exists — it'''s just never read or exposed for subagents.

Image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with subagent lifecycle and context handling in src/kimi_cli/subagents/core.py, then trace StatusUpdate and StatusSnapshot in src/kimi_cli/soul/kimisoul.py and rendering in src/kimi_cli/ui/shell/prompt.py. Review the Vis API /subagents endpoint and choose a defined exposure or aggregation path; done means subagent context usage is observable and compaction behavior is addressed without regressing parent statistics.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.