From 99980c3a2e877509bc54cbc774bf194429251069 Mon Sep 17 00:00:00 2001 From: turtle1999 Date: Tue, 13 Oct 2026 19:51:57 +0800 Subject: [PATCH] refactor(subagent): rename relayed to omitClosingText --- packages/subagent/subagent/src/activation.ts | 12 +++++------- .../subagent/subagent/src/continuation-messages.ts | 8 ++++---- packages/subagent/subagent/src/manager.ts | 10 +++++----- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/subagent/subagent/src/activation.ts b/packages/subagent/subagent/src/activation.ts index 28343accb4..34ef5e9f8c 100644 --- a/packages/subagent/subagent/src/activation.ts +++ b/packages/subagent/subagent/src/activation.ts @@ -72,14 +72,12 @@ interface ActivationBase { */ announced: boolean /** - * Whether this child's last action before its closing text was a message to - * its direct parent: the only tool call of its step, with no input claimed - * and no tool call started since. - * Its settlement notice then omits the closing message, which restates that - * message. + * Whether this child's settlement notice omits its closing text: true while + * the child's last action was a message to its direct parent, as the only + * tool call of its step, with no input claimed and no tool call logged since. */ - relayed: boolean - /** Tool calls the child's current step logged, which decides {@link relayed}. */ + omitClosingText: boolean + /** Tool calls the child's current step logged, which decides {@link omitClosingText}. */ stepToolCalls: number } diff --git a/packages/subagent/subagent/src/continuation-messages.ts b/packages/subagent/subagent/src/continuation-messages.ts index f906816432..cb1becfb5f 100644 --- a/packages/subagent/subagent/src/continuation-messages.ts +++ b/packages/subagent/subagent/src/continuation-messages.ts @@ -133,15 +133,15 @@ function settlementSummary(childId: SessionId, stopReason: SubagentResult['stopR * @param childId - durable child session id named in the notice. * @param terminal - recorded terminal state for the settled Activation. * @param continuable - whether the child can accept another task. - * @param relayed - whether the child's last action before its closing text was a message to the parent, - * which omits the closing message. + * @param omitClosingText - replace the closing text with a note that the child's + * last message to the parent already carries it. * @returns the durable user-message representation delivered to the parent. */ export function createSettlementMessage( childId: SessionId, terminal: SubagentResult, continuable = true, - relayed = false, + omitClosingText = false, ): ReturnType { const summary = settlementSummary(childId, terminal.stopReason, continuable) // Parent providers receive this notice as a user message and may reject @@ -153,7 +153,7 @@ export function createSettlementMessage( return createUserMessage({ content: [ { type: 'text' as const, text: summary }, - ...relayed + ...omitClosingText ? [{ type: 'text' as const, text: 'It sent you a message just before finishing, so its closing message is omitted.' }] : closingText.length === 0 ? [{ type: 'text' as const, text: 'It left no closing message.' }] diff --git a/packages/subagent/subagent/src/manager.ts b/packages/subagent/subagent/src/manager.ts index cbac5a115a..819a1489de 100644 --- a/packages/subagent/subagent/src/manager.ts +++ b/packages/subagent/subagent/src/manager.ts @@ -934,7 +934,7 @@ export class SubagentManager { ownedChildren: new Set(), observer, announced: false, - relayed: false, + omitClosingText: false, stepToolCalls: 0, } void activation.result.promise.catch(() => undefined) @@ -951,7 +951,7 @@ export class SubagentManager { activation.handle.agent.ctx.on('agent/inbox/claimed', () => { // Claimed input means the closing text may report work the child's // last message to its parent did not. - activation.relayed = false + activation.omitClosingText = false wakeSettlement() }) activation.handle.agent.ctx.on('agent/inbox/discarded', wakeSettlement) @@ -961,7 +961,7 @@ export class SubagentManager { if (event.type === 'step/start') activation.stepToolCalls = 0 else if (event.type === 'tool/call') { activation.stepToolCalls += 1 - activation.relayed = false + activation.omitClosingText = false } }) } @@ -1202,7 +1202,7 @@ export class SubagentManager { const parent = this.ctx.agents.get(activation.parent.id) if (parent !== activation.parent) return const message = createSettlementMessage( - activation.childId, terminal, activationAgent(activation) !== undefined, activation.relayed, + activation.childId, terminal, activationAgent(activation) !== undefined, activation.omitClosingText, ) if (this.closingTeardownFor(parent) !== undefined) { parent.inject(message) @@ -1315,7 +1315,7 @@ export class SubagentManager { } const message = createAgentMessage(sender, content) this.sendAgentMessage(parent, message) - activation.relayed = activation.stepToolCalls <= 1 + activation.omitClosingText = activation.stepToolCalls <= 1 return message.id }