From da0780e81b1504a1ba09b38ea9bfa82abc55bcb6 Mon Sep 17 00:00:00 2001 From: Dudu-0223 Date: Wed, 18 Nov 2026 14:10:46 +0800 Subject: [PATCH] feat(session): prefix cross-Session messages with the sender Session A recipient reads `Session sent a message: ` instead of the `Agent ` prefix of send_message, whose names resolve only inside one subagent tree. --- packages/session/tool-session-control/README.i18n.yaml | 8 ++++---- packages/session/tool-session-control/README.md | 4 ++-- packages/session/tool-session-control/README.zh.md | 4 ++-- packages/session/tool-session-control/src/index.ts | 5 +++-- .../tests/tool-session-control.spec.ts | 4 ++-- snapshots/web/session-send-message/session.1.v4.jsonl | 8 ++++---- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/session/tool-session-control/README.i18n.yaml b/packages/session/tool-session-control/README.i18n.yaml index 352f0e3aab..e3dedf2a95 100644 --- a/packages/session/tool-session-control/README.i18n.yaml +++ b/packages/session/tool-session-control/README.i18n.yaml @@ -27,8 +27,8 @@ en: 26bac95a60ebbdc2 zh: 290c8c32e5224e23 /deepseek-ai-dsh-tool-session-control/understand-the-implementation: - en: cb7e3f0be824f944 - zh: b849cd783d218b14 + en: 80ea89418f150059 + zh: f2dd7f0a62753d76 /deepseek-ai-dsh-tool-session-control/understand-the-implementation/source-map: en: 1a30357273bab5cf zh: 6346418a136ae0fa @@ -54,8 +54,8 @@ en: 954e51e410125348 zh: 7d23b00c1877c9dc /deepseek-ai-dsh-tool-session-control/model-experience/delivered-message/what-the-model-sees: - en: c9c4474676c44f06 - zh: 1fb879356af6667d + en: a16a6e99d1351fba + zh: 90488a8b6326c136 /deepseek-ai-dsh-tool-session-control/model-experience/delivered-message/token-effect: en: 53fb39e73cf63d85 zh: 5fd2edca105455cb diff --git a/packages/session/tool-session-control/README.md b/packages/session/tool-session-control/README.md index 7bbebb7209..eea96135fe 100644 --- a/packages/session/tool-session-control/README.md +++ b/packages/session/tool-session-control/README.md @@ -63,7 +63,7 @@ Call `session_send_message({ session_id: "target-id", message: "Please review th
Implementation internals — click to expand -The tool takes the sender from the runtime's calling Agent, so the model cannot choose a sender identity. It checks the Workspace registry's archive list, waits for the Session controller's activation while racing the caller's signal, then rechecks cancellation and the archive list. It builds the message with the `agent-message` source that `@deepseek-ai/dsh-subagent` declares, records the caller's `senderSessionId`, uses the same `Agent sent a message: ` prefix as `send_message` with the caller's Session id, and calls `steer()` on the target. Inbox failures propagate unchanged. The [tool pipeline](../../core/tools/README.md) applies its ordinary cancellation behavior. The Host presenter shows the target id and message text; the [Web tool card](../../client/ui-tool/README.md) derives the accepted state and message ID from the recorded result. +The tool takes the sender from the runtime's calling Agent, so the model cannot choose a sender identity. It checks the Workspace registry's archive list, waits for the Session controller's activation while racing the caller's signal, then rechecks cancellation and the archive list. It builds the message with the `agent-message` source that `@deepseek-ai/dsh-subagent` declares, records the caller's `senderSessionId`, prefixes the text with `Session sent a message: `, and calls `steer()` on the target. The prefix differs from the `Agent sent a message: ` prefix of `send_message`, whose names resolve only inside one subagent tree. Inbox failures propagate unchanged. The [tool pipeline](../../core/tools/README.md) applies its ordinary cancellation behavior. The Host presenter shows the target id and message text; the [Web tool card](../../client/ui-tool/README.md) derives the accepted state and message ID from the recorded result. ### Source map @@ -106,7 +106,7 @@ Enabling or disabling the row changes the tool schema list and may invalidate re #### What the model sees -The recipient receives one steering user message: a text block `Agent sent a message: ` followed by the message text unchanged. +The recipient receives one steering user message: a text block `Session sent a message: ` followed by the message text unchanged. #### Token effect diff --git a/packages/session/tool-session-control/README.zh.md b/packages/session/tool-session-control/README.zh.md index 59660443e1..9e89dba367 100644 --- a/packages/session/tool-session-control/README.zh.md +++ b/packages/session/tool-session-control/README.zh.md @@ -63,7 +63,7 @@ kind: "package-reference"
实现细节 — 点击展开 -工具从运行时的调用智能体获取发送者,因此模型无法选择发送者身份。它先检查 Workspace 注册表的归档列表,在与调用方取消信号竞争的同时等待 Session 控制器完成激活,随后再次检查取消状态和归档列表。它使用 `@deepseek-ai/dsh-subagent` 声明的 `agent-message` 来源构造消息,记录调用方的 `senderSessionId`,沿用 `send_message` 的 `Agent sent a message: ` 前缀并以调用方的 Session id 作为发送者名称,然后对目标调用 `steer()`。收件箱失败原样传播。[工具流水线](../../core/tools/README.zh.md)沿用普通取消行为。Host 展示器显示目标 id 和消息正文;[Web 工具卡片](../../client/ui-tool/README.zh.md)从已记录的结果中推导接收状态和消息 ID。 +工具从运行时的调用智能体获取发送者,因此模型无法选择发送者身份。它先检查 Workspace 注册表的归档列表,在与调用方取消信号竞争的同时等待 Session 控制器完成激活,随后再次检查取消状态和归档列表。它使用 `@deepseek-ai/dsh-subagent` 声明的 `agent-message` 来源构造消息,记录调用方的 `senderSessionId`,在正文前加上 `Session sent a message: ` 前缀,然后对目标调用 `steer()`。该前缀不同于 `send_message` 的 `Agent sent a message: `:后者的名称只能在同一棵 subagent 树内解析。收件箱失败原样传播。[工具流水线](../../core/tools/README.zh.md)沿用普通取消行为。Host 展示器显示目标 id 和消息正文;[Web 工具卡片](../../client/ui-tool/README.zh.md)从已记录的结果中推导接收状态和消息 ID。 ### 源码地图 @@ -106,7 +106,7 @@ kind: "package-reference" #### 模型看到什么 -接收方收到一条 steer 用户消息:文本块 `Agent sent a message: `,后接原样保留的消息正文。 +接收方收到一条 steer 用户消息:文本块 `Session sent a message: `,后接原样保留的消息正文。 #### Token 影响 diff --git a/packages/session/tool-session-control/src/index.ts b/packages/session/tool-session-control/src/index.ts index 5186d2a16d..cb3cfee7e7 100644 --- a/packages/session/tool-session-control/src/index.ts +++ b/packages/session/tool-session-control/src/index.ts @@ -117,9 +117,10 @@ export function apply(ctx: Context): void { } exec.signal.throwIfAborted() assertUnarchived(id) - // The subagent-owned agent-message source and prefix match send_message, naming the sender by Session id. + // The source is the agent-message kind dsh-subagent declares. The prefix differs from send_message, + // whose `Agent ` senders resolve only inside the recipient's subagent tree. const message = createUserMessage({ - content: [{ type: 'text', text: `Agent ${caller.id} sent a message: ` }, { type: 'text', text: args.message }], + content: [{ type: 'text', text: `Session ${caller.id} sent a message: ` }, { type: 'text', text: args.message }], source: { kind: 'agent-message', form: 'relay', senderSessionId: caller.id }, }) found.agent.steer(message) diff --git a/packages/session/tool-session-control/tests/tool-session-control.spec.ts b/packages/session/tool-session-control/tests/tool-session-control.spec.ts index 958faaaeff..b5497041b4 100644 --- a/packages/session/tool-session-control/tests/tool-session-control.spec.ts +++ b/packages/session/tool-session-control/tests/tool-session-control.spec.ts @@ -76,7 +76,7 @@ describe('Session message tool', () => { expect(message).toMatchObject({ source: { kind: 'agent-message', form: 'relay', senderSessionId: caller.id }, content: [ - { type: 'text', text: `Agent ${caller.id} sent a message: ` }, + { type: 'text', text: `Session ${caller.id} sent a message: ` }, { type: 'text', text: ' Please review.\nKeep the context. ' }, ], }) @@ -183,7 +183,7 @@ describe('Session message tool', () => { const [message] = agentMessages(target) expect(message).toMatchObject({ source: { kind: 'agent-message', form: 'relay', senderSessionId: caller.id }, - content: [{ type: 'text', text: `Agent ${caller.id} sent a message: ` }, { type: 'text', text: 'Hello' }], + content: [{ type: 'text', text: `Session ${caller.id} sent a message: ` }, { type: 'text', text: 'Hello' }], }) expect(agentMessages(target)).toHaveLength(1) expect(result).toMatchObject({ diff --git a/snapshots/web/session-send-message/session.1.v4.jsonl b/snapshots/web/session-send-message/session.1.v4.jsonl index f7deda0581..af6e1f150a 100644 --- a/snapshots/web/session-send-message/session.1.v4.jsonl +++ b/snapshots/web/session-send-message/session.1.v4.jsonl @@ -3,12 +3,12 @@ {"type":"sandbox/mode","data":{"mode":"workspace-write"}} {"type":"approval/policy","data":{"policy":"ask"}} {"type":"session/end-seed","data":{}} -{"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"inserted":[{"content":[{"type":"text","text":"Agent {{session:1}} sent a message: "},{"type":"text","text":"FIRST"}],"source":{"kind":"agent-message","form":"relay","senderSessionId":"{{session:1}}"},"role":"user","id":"{{message:14}}"}]}} +{"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"inserted":[{"content":[{"type":"text","text":"Session {{session:1}} sent a message: "},{"type":"text","text":"FIRST"}],"source":{"kind":"agent-message","form":"relay","senderSessionId":"{{session:1}}"},"role":"user","id":"{{message:14}}"}]}} {"type":"turn/start","data":{"turn":1}} {"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"removedCount":1,"inserted":[]}} {"type":"step/start","data":{"turn":1,"step":1}} {"type":"system/message","data":{"turn":1,"step":1,"message":{"role":"system","content":[{"type":"text","text":"{{system}}"}],"source":{"kind":"system-prompt"},"id":"{{message:15}}"}},"surfaceOp":"append"} -{"type":"user/message","data":{"content":[{"type":"text","text":"Agent {{session:1}} sent a message: "},{"type":"text","text":"FIRST"}],"source":{"kind":"agent-message","form":"relay","senderSessionId":"{{session:1}}"},"role":"user","id":"{{message:14}}"},"surfaceOp":"append"} +{"type":"user/message","data":{"content":[{"type":"text","text":"Session {{session:1}} sent a message: "},{"type":"text","text":"FIRST"}],"source":{"kind":"agent-message","form":"relay","senderSessionId":"{{session:1}}"},"role":"user","id":"{{message:14}}"},"surfaceOp":"append"} {"type":"user/message","data":{"content":[{"type":"text","text":"\nThe following information describes your current session:\n\nCurrent working directory: \"{{cwd}}/.agents/independent-recipient\".\n\nCurrent DSH file policy: workspace-write. Any available operation enforced by the DSH file sandbox may modify files under the session workspace: \"{{cwd}}/.agents/independent-recipient\". Some platform temporary areas may also be writable.\n\nApproval prompts are enabled in this session: operations that require approval may ask through the configured answerers; without an available answerer, the request fails closed.\n\nYou are the root agent. Your name is \"lead\".\n\nTo message other agents, use send_message({ agent: \"\", message: \"...\" }).\nUse list_agents({}) to find your collaborator agents and their names.\n\nCurrent DeepSeek Harness implementation checkout: \"{{sourceRoot}}\".\n\nCurrent DeepSeek Harness Web GUI URL: \"{{webUrl}}\".\n"}],"source":{"kind":"runtime-context","form":"snapshot","sections":[{"name":"working-directory:current","text":"Current working directory: \"{{cwd}}/.agents/independent-recipient\"."},{"name":"sandbox:policy","text":"Current DSH file policy: workspace-write. Any available operation enforced by the DSH file sandbox may modify files under the session workspace: \"{{cwd}}/.agents/independent-recipient\". Some platform temporary areas may also be writable."},{"name":"approval:policy","text":"Approval prompts are enabled in this session: operations that require approval may ask through the configured answerers; without an available answerer, the request fails closed."},{"name":"subagent:identity","text":"You are the root agent. Your name is \"lead\".\n\nTo message other agents, use send_message({ agent: \"\", message: \"...\" }).\nUse list_agents({}) to find your collaborator agents and their names."},{"name":"harness:source","text":"Current DeepSeek Harness implementation checkout: \"{{sourceRoot}}\"."},{"name":"app:web-surface","text":"Current DeepSeek Harness Web GUI URL: \"{{webUrl}}\"."}]},"role":"user","id":"{{message:16}}"},"surfaceOp":"append"} {"type":"user/message","data":{"content":[{"type":"text","text":"\nA skill is a reusable set of task-specific instructions. The following skills are available in this session:\n\n\n- `dsh-doc`: Use when a task needs facts about DeepSeek Harness (DSH) itself, such as how a feature, setting, plugin, agent preset, tool, or Cordis API of the running installation works; when the user asks to design, review, build, install, enable, or debug a DSH plugin, bundle, MCP connection, agent preset, plugin icon or detail page, or a DSH tool definition or skill; and when upgrading a plugin or profile to a newer DSH release. Loading it grants no permission to change files or the profile.\n- `office`: Create or edit Office files; inspect Office files and PDFs. Load before rendering, conversion, or recalculation to enable office_render, office_convert, and office_recalculate next step.\n- `office-docx`: Create, read, edit, and validate Word documents (.docx).\n- `office-pptx`: Create, read, edit, and validate PowerPoint presentations (.pptx).\n- `office-xlsx`: Read, create, edit, and validate Excel workbooks, data, and formulas (.xlsx).\n\n\nIf the user names a skill, or the task clearly matches a skill's description, call the `skill` tool with the exact skill name before taking task actions. Load all applicable skills, then follow their full instructions. This catalog contains summaries only; do not infer or follow a skill's instructions until it has been loaded.\nA user may also invoke a skill directly; its block then appears in this conversation. Follow it, and do not call the `skill` tool again for that skill.\n"}],"source":{"kind":"skill-catalog","form":"catalog","entries":[{"name":"dsh-doc","description":"Use when a task needs facts about DeepSeek Harness (DSH) itself, such as how a feature, setting, plugin, agent preset, tool, or Cordis API of the running installation works; when the user asks to design, review, build, install, enable, or debug a DSH plugin, bundle, MCP connection, agent preset, plugin icon or detail page, or a DSH tool definition or skill; and when upgrading a plugin or profile to a newer DSH release. Loading it grants no permission to change files or the profile."},{"name":"office","description":"Create or edit Office files; inspect Office files and PDFs. Load before rendering, conversion, or recalculation to enable office_render, office_convert, and office_recalculate next step."},{"name":"office-docx","description":"Create, read, edit, and validate Word documents (.docx)."},{"name":"office-pptx","description":"Create, read, edit, and validate PowerPoint presentations (.pptx)."},{"name":"office-xlsx","description":"Read, create, edit, and validate Excel workbooks, data, and formulas (.xlsx)."}]},"role":"user","id":"{{message:17}}"},"surfaceOp":"append"} {"type":"user/message","data":{"content":[{"type":"text","text":"Time sampled while preparing turn 1, step 1: {{timeContextTimestamp}}\nBrowser time zone for this request: {{clientTimeZone}}. Ask the user to clarify otherwise-unqualified dates and times.\nElapsed since the preceding model-visible message: {{elapsed}}"}],"source":{"kind":"time-context","form":"snapshot","sections":[{"name":"time-context","text":"Time sampled while preparing turn 1, step 1: {{timeContextTimestamp}}\nBrowser time zone for this request: {{clientTimeZone}}. Ask the user to clarify otherwise-unqualified dates and times.\nElapsed since the preceding model-visible message: {{elapsed}}"}]},"role":"user","id":"{{message:18}}"},"surfaceOp":"append"} @@ -17,11 +17,11 @@ {"type":"assistant/message","data":{"turn":1,"step":1,"message":{"role":"assistant","content":[{"type":"text","text":"FIRST_RECEIVED"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash"},"id":"{{message:19}}"},"usage":{"inputTokens":10,"outputTokens":5},"stream":[{"type":"chunk","time":1794464118441,"chunk":{"type":"block-start","index":0,"blockType":"text"}},{"type":"chunk","time":1794464118441,"chunk":{"type":"block-end","index":0,"block":{"type":"text","text":"FIRST_RECEIVED"}}},{"type":"chunk","time":1794464118441,"chunk":{"type":"usage","usage":{"inputTokens":10,"outputTokens":5}}},{"type":"chunk","time":1794464118441,"chunk":{"type":"finish","reason":{"kind":"stop"}}}]},"surfaceOp":"append"} {"type":"step/end","data":{"turn":1,"step":1}} {"type":"turn/end","data":{"turn":1,"reason":{"kind":"completed"}}} -{"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"inserted":[{"content":[{"type":"text","text":"Agent {{session:1}} sent a message: "},{"type":"text","text":"SECOND"}],"source":{"kind":"agent-message","form":"relay","senderSessionId":"{{session:1}}"},"role":"user","id":"{{message:20}}"}]}} +{"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"inserted":[{"content":[{"type":"text","text":"Session {{session:1}} sent a message: "},{"type":"text","text":"SECOND"}],"source":{"kind":"agent-message","form":"relay","senderSessionId":"{{session:1}}"},"role":"user","id":"{{message:20}}"}]}} {"type":"turn/start","data":{"turn":2}} {"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"removedCount":1,"inserted":[]}} {"type":"step/start","data":{"turn":2,"step":1}} -{"type":"user/message","data":{"content":[{"type":"text","text":"Agent {{session:1}} sent a message: "},{"type":"text","text":"SECOND"}],"source":{"kind":"agent-message","form":"relay","senderSessionId":"{{session:1}}"},"role":"user","id":"{{message:20}}"},"surfaceOp":"append"} +{"type":"user/message","data":{"content":[{"type":"text","text":"Session {{session:1}} sent a message: "},{"type":"text","text":"SECOND"}],"source":{"kind":"agent-message","form":"relay","senderSessionId":"{{session:1}}"},"role":"user","id":"{{message:20}}"},"surfaceOp":"append"} {"type":"assistant/message","data":{"turn":2,"step":1,"message":{"role":"assistant","content":[{"type":"text","text":"SECOND_RECEIVED"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash"},"id":"{{message:21}}"},"usage":{"inputTokens":10,"outputTokens":5},"stream":[{"type":"chunk","time":1794464118483,"chunk":{"type":"block-start","index":0,"blockType":"text"}},{"type":"chunk","time":1794464118483,"chunk":{"type":"block-end","index":0,"block":{"type":"text","text":"SECOND_RECEIVED"}}},{"type":"chunk","time":1794464118483,"chunk":{"type":"usage","usage":{"inputTokens":10,"outputTokens":5}}},{"type":"chunk","time":1794464118483,"chunk":{"type":"finish","reason":{"kind":"stop"}}}]},"surfaceOp":"append"} {"type":"step/end","data":{"turn":2,"step":1}} {"type":"turn/end","data":{"turn":2,"reason":{"kind":"completed"}}}