MoonshotAI / MoonshotAI/kimi-code

Subagent 可无限层递归 spawn 新 subagent,目前无深度上限与重复转包识别

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

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

What version of Kimi Code is running?

0.34.0

Which open platform/subscription were you using?

OpenAI

Which model were you using?

GPT-5.6 Sol Xhigh 为 primary model,secondary model 设置为 deepseek v4 flash max

What platform is your computer?

Linux 7.1.5-arch1-2 x86_64

What issue are you seeing?

主 agent 通过 Agent / AgentSwarm 工具 spawn 的 subagent,自身同样持有这两个工具,可以继续 spawn 下一层 subagent,委托链条可以逐层延伸。目前系统中没有:

  • 委托深度上限;
  • 对「同一任务被逐层原样转包」的识别机制。

链条中的每一层都是一次完整的 agent 运行:独立的上下文、完整的模型调用、独立计算的超时预算。任务层层转包,最后系统空转,只消耗 token,但却没有任何产出。

What steps can reproduce the bug?

这其实并不完全是一个 bug,而且无法期待可以稳定复现。可能复现:交给主agent一个复杂且规模较大的任务,但将任务拆解后每个子任务并不足够有趣,每个 agent 都倾向于把自己的任务转包给一个子agent,就可能会发现任务层层转包的嵌套agent树。

下图为一次实际运行的 agent 树(路径已打码):主 agent 通过 Agent 生成 codercoder 通过 AgentSwarm spawn 下一层 coder,该 coder 又通过 Agent spawn 再下一层 coder,任务沿链条逐层下推。

Image
What is the expected behavior?

系统中应有委托深度上限,或者在 prompt 层面约束子 agent 转包自己的任务。

Additional information
  1. subagent 默认持有 Agent / AgentSwarm 工具

    内置 profile(packages/agent-core-v2/src/session/agentLifecycle/profile/profiles.ts)中,agentcoder 的工具列表均包含 AgentAgentSwarmAgent 工具的默认 subagent 类型为 coderpackages/agent-core-v2/src/agent/tools/agent/agent.ts:16DEFAULT_PROFILE_NAME = 'coder')。explore 不含 Agent。v1 引擎中 coder profile 同样包含二者(packages/agent-core/src/profile/default/coder.yaml)。

  2. agent 注册表扁平,无层级约束

    生命周期注册表保持扁平(packages/agent-core-v2/src/session/agentLifecycle/agentLifecycle.ts:10):"The registry is flat: agents have no nesting. There is no parent/child or caller/callee relationship here"。parentAgentId 仅以 label 元数据形式记录,不参与运行时约束;Agent 工具实现中没有针对调用方层级的判断。

  3. 现有限制均为横向并发与单次超时,不约束链条深度

    • 后台任务并发上限 maxRunningTaskspackages/agent-core-v2/src/agent/task/taskService.ts:923):默认无上限,且仅统计 detached 后台任务;前台链(A 等 B 等 C)每层只占 1 个任务。
    • 单次 subagent 超时默认 2 小时(packages/agent-core-v2/src/session/subagent/configSection.ts:75),每层 subagent 独立计算,不累计。
    • AGENT_ALREADY_RUNNING / AGENT_NOT_OWNEDpackages/agent-core-v2/src/agent/tools/agent/agentTool.ts)仅约束同一实例并发与 resume 归属;链条每层都会新建实例,不受影响。

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 packages/agent-core-v2/src/session/agentLifecycle/profile/profiles.ts, agentLifecycle.ts, and the Agent tool at packages/agent-core-v2/src/agent/tools/agent/agent.ts; compare these with the v1 coder profile. Review taskService.ts and configSection.ts to understand existing concurrency and timeout limits. Done should mean recursive delegation is bounded or repeated pass-through tasks are detected, without relying on per-agent timeouts.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
ai, cli, devtools
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.