docs(subagent): document parent-attributed initial tasks

Update the in-process provider READMEs and add an upgrade guide for the initial task source change.
This commit is contained in:
Dudu-0223 committed 2026-11-16 17:18:07 +08:00
1 parent e592b98576
commit 0fb2b5c1cd
9 files changed
+68 -12

No files matched your search

@@ -0,0 +1,16 @@
# Bilingual-pair consistency record for guide.md (docs/i18n/README.md): per heading
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
# After editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write docs/upgrade-guide/v0.2.2-rc.2/subagent-initial-task-source/guide.md
/:
en: 643defc5c1f7c556
zh: d0eb87e9f9b8ab04
/subagent-initial-tasks-are-agent-messages:
en: c906e368b0a9bb59
zh: d9d101cf60c4b59b
/subagent-initial-tasks-are-agent-messages/change:
en: bace0953390241ba
zh: 208b75e8f024d83f
/subagent-initial-tasks-are-agent-messages/migration:
en: 87f787e243c43531
zh: fd05bf541be3ea63
@@ -0,0 +1,20 @@
---
kind: upgrade-guide
description: "In-process continuable subagents record their initial delegated task as an agent-message from the parent agent instead of a user message."
---
# Subagent initial tasks are agent messages
English | [中文](guide.zh.md)
## Change
In-process continuable subagents started by `subagent-spawn-in-process` or `subagent-fork-in-process` record the initial delegated task as a message from the parent agent. Its `user/message` source changes from `{ "kind": "user" }` to `{ "kind": "agent-message", "form": "relay", "senderSessionId": "<parent Session id>" }`, and its content starts with a text block `Agent <parent name> sent a message: ` before the task blocks. Child Session logs, SDK Session event notifications, and Python SDK results show the new form. Sessions written earlier keep the old form.
Consumers that treat `user` sources as human input no longer apply to the task: `$skill` mentions in it do not load skills, Session references in it are not expanded, Markdown export and the turn outline omit it, and a child without human messages gets no fallback title. Direct human messages to a child keep the `user` source and their original content.
## Migration
1. Where code finds a child's task as its first `user`-source message, match an `agent-message` source whose `senderSessionId` equals the child Session's `parentSession`, and drop the first content block to read the task text. Keep accepting `user` for Sessions written before the upgrade.
2. Where a delegated task relies on `$skill` to load a skill, name the skill in the task and let the child call the `skill` tool.
3. Confirm by starting a continuable child and checking that its first non-context `user/message` has the `agent-message` source and the sender prefix.
@@ -0,0 +1,20 @@
---
kind: upgrade-guide
description: "进程内可续聊子 agent 的初始委派任务改为记录成来自父 agent 的 agent-message,不再是 user 消息。"
---
# 子 agent 初始任务改为 agent 消息
[English](guide.md) | 中文
## 变更
由 `subagent-spawn-in-process` 或 `subagent-fork-in-process` 启动的进程内可续聊子 agent,把初始委派任务记录为来自父 agent 的消息。其 `user/message` 的 source 从 `{ "kind": "user" }` 变为 `{ "kind": "agent-message", "form": "relay", "senderSessionId": "<父级 Session id>" }`,正文在任务内容块之前多一个文本块 `Agent <parent name> sent a message: `。子 Session 日志、SDK Session 事件通知和 Python SDK 结果都使用新形式。升级前写入的 Session 保持旧形式。
把 `user` 来源当作真人输入的使用方不再作用于该任务:任务中的 `$skill` 不再加载 skill,任务中的 Session 引用不再展开,Markdown 导出与 turn 大纲不包含该任务,没有真人消息的子会话不再生成回退标题。真人直接发给子 agent 的消息保持 `user` 来源和原文。
## 迁移
1. 如果代码把子会话的第一条 `user` 来源消息当作任务,改为匹配 `senderSessionId` 等于子 Session `parentSession` 的 `agent-message` 来源,并去掉第一个内容块后读取任务文本。对升级前写入的 Session 仍接受 `user`。
2. 如果委派任务依赖 `$skill` 加载 skill,改为在任务中写明 skill 名称,由子 agent 调用 `skill` 工具。
3. 启动一个可续聊子 agent,确认其第一条非上下文 `user/message` 使用 `agent-message` 来源并带有发送方前缀。
@@ -54,14 +54,14 @@
en: 91a5bd22001586e9
zh: 456e5bf20881a70d
/deepseek-ai-dsh-subagent-fork-in-process/model-experience/child-agent-history-and-envelope/what-the-model-sees:
en: d4d51c5937bab67c
zh: e7c07b5a38d68d8e
en: aa73e4e958b4d1af
zh: f514cf0ec0ef3ef4
/deepseek-ai-dsh-subagent-fork-in-process/model-experience/child-agent-history-and-envelope/token-effect:
en: 19b588baaa87126b
zh: 7010e93bbe7d71ba
/deepseek-ai-dsh-subagent-fork-in-process/model-experience/child-agent-history-and-envelope/kv-cache-effect:
en: 1e8f8bbab3052b39
zh: 1efff4da78d60ef9
en: d01f590e986f815e
zh: a1c433d759b4e908
/deepseek-ai-dsh-subagent-fork-in-process/model-experience/parent-tool-result-indirectly:
en: 75d061c2151624a7
zh: 71e58e020b60ff90
@@ -109,7 +109,7 @@ Read these pages when the package-level contract is not enough; they move from t
#### What the model sees
The child receives the parent's balanced completed-turn prefix, then the new task content verbatim. It joins the parent's preset revision, which supplies persona and tools. Parent agent-local restrictions are not copied. An optional structured-output request adds a child-only tool; the parent's current in-flight turn is excluded.
The child receives the parent's balanced completed-turn prefix, then the new task as a message from the parent agent: `Agent <parent name> sent a message: ` followed by the task content verbatim. It joins the parent's preset revision, which supplies persona and tools. Parent agent-local restrictions are not copied. An optional structured-output request adds a child-only tool; the parent's current in-flight turn is excluded.
#### Token effect
@@ -117,7 +117,7 @@ Forking duplicates retained completed history into the child's request, which th
#### KV Cache effect
The child may reuse the inherited byte-identical prefix under the same provider and model. Structured output, generated-SDK, route changes, or historical descriptor overrides on cold resume can invalidate reuse before inherited history; later child history is append-only. Continuable messaging adds no child-only system-prompt section or tool schema; the parent id and return guidance follow inherited history in the initial user task ([cache-preserving fork Agent Note](../../../.agents/notes/implemented/architecture/2026-08-10-fork-children-stay-one-shot.md)).
The child may reuse the inherited byte-identical prefix under the same provider and model. Structured output, generated-SDK, route changes, or historical descriptor overrides on cold resume can invalidate reuse before inherited history; later child history is append-only. Continuable messaging adds no child-only system-prompt section or tool schema; the parent id and return guidance follow inherited history in the initial delegated task ([cache-preserving fork Agent Note](../../../.agents/notes/implemented/architecture/2026-08-10-fork-children-stay-one-shot.md)).
### Parent tool result, indirectly
@@ -109,7 +109,7 @@ kind: "package-reference"
#### 模型看到什么
子 agent 先接收由父级已配平的已完成轮次构成的前缀,再逐字接收新的任务内容。它加入父级的 preset 代际,由 preset 提供 persona 和工具。父级 agent 局部限制不会被复制。可选的结构化输出请求会添加仅属于子 agent 的工具;父级当前进行中的轮次会被排除。
子 agent 先接收由父级已配平的已完成轮次构成的前缀,再接收一条来自父 agent 的新任务消息:`Agent <parent name> sent a message: ` 后接逐字任务内容。它加入父级的 preset 代际,由 preset 提供 persona 和工具。父级 agent 局部限制不会被复制。可选的结构化输出请求会添加仅属于子 agent 的工具;父级当前进行中的轮次会被排除。
#### Token 影响
@@ -117,7 +117,7 @@ fork 会把保留的已完成历史复制到子 agent 的请求中,子 agent
#### KV Cache 影响
在提供方与模型相同的前提下,子 agent 可以复用继承的逐字节相同前缀。结构化输出、生成 SDK、路由变化,或冷恢复时的历史 descriptor 覆盖,可能在继承历史之前使复用失效;后续子 agent 历史仅追加。可继续消息不会增加子级专属的系统提示词区段或工具 schema;父级 ID 与返回指导在初始用户任务中位于继承历史之后(见[保持 fork 缓存的 Agent Note](../../../.agents/notes/implemented/architecture/2026-08-10-fork-children-stay-one-shot.zh.md))。
在提供方与模型相同的前提下,子 agent 可以复用继承的逐字节相同前缀。结构化输出、生成 SDK、路由变化,或冷恢复时的历史 descriptor 覆盖,可能在继承历史之前使复用失效;后续子 agent 历史仅追加。可继续消息不会增加子级专属的系统提示词区段或工具 schema;父级 ID 与返回指导在初始委派任务中位于继承历史之后(见[保持 fork 缓存的 Agent Note](../../../.agents/notes/implemented/architecture/2026-08-10-fork-children-stay-one-shot.zh.md))。
### 父级工具结果(间接)
@@ -51,8 +51,8 @@
en: 05e6180f1498fdf9
zh: 2b05d2b97bfa67da
/deepseek-ai-dsh-subagent-spawn-in-process/model-experience/child-agent-request/what-the-model-sees:
en: c9dfab9a4d363fed
zh: 6cb3b0914ccb73e2
en: 84a5e689a55f5bec
zh: 89d6bcbe1a7fb6e7
/deepseek-ai-dsh-subagent-spawn-in-process/model-experience/child-agent-request/token-effect:
en: eb373a4b35a4b548
zh: 9537d0e466e8bcd9
@@ -106,7 +106,7 @@ Read these pages when the package-level contract is not enough; they move from t
#### What the model sees
The fresh child receives the task content verbatim as its only user message in a new empty conversation, with the parent provider, model, reasoning effort, output-token limit, and working directory by default. The inherited or selected preset supplies tools and prompt sections. No parent conversation message is included.
The fresh child receives the task as its only user message in a new empty conversation, attributed to the parent agent: `Agent <parent name> sent a message: ` followed by the task content verbatim. It uses the parent provider, model, reasoning effort, output-token limit, and working directory by default. The inherited or selected preset supplies tools and prompt sections. No parent conversation message is included.
#### Token effect
@@ -106,7 +106,7 @@ kind: "package-reference"
#### 模型看到什么
全新子 agent 逐字接收任务内容,作为新空对话中的唯一用户消息,默认使用父级提供方、模型、推理强度、输出 token 上限与工作目录。继承或选定的 preset 提供工具和提示词片段。不包含任何父级对话消息。
全新子 agent 在新空对话中接收唯一一条用户消息,即来自父 agent 的任务:`Agent <parent name> sent a message: ` 后接逐字任务内容。默认使用父级提供方、模型、推理强度、输出 token 上限与工作目录。继承或选定的 preset 提供工具和提示词片段。不包含任何父级对话消息。
#### Token 影响