From 01ba714f8d857c328854bc8c18a14499355cc2a5 Mon Sep 17 00:00:00 2001 From: Kang Zhou Date: Mon, 16 Mar 2026 08:00:57 +0800 Subject: [PATCH] fix: skip memory persistence for delegated sub-agent calls (#1026) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a parent agent delegates a task to a sub-agent via delegate_task, the sub-agent was persisting its messages under the parent's conversationId, causing duplicate messages in the parent's history. This fix checks for parentAgentId on the OperationContext — which is already set during delegation — and skips memory persistence for sub-agent calls. Sub-agents acting as stateless task executors should not pollute the parent conversation's memory. Fixes #1026 --- packages/core/src/agent/agent.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/core/src/agent/agent.ts b/packages/core/src/agent/agent.ts index 800ca6f0e..a3aa23315 100644 --- a/packages/core/src/agent/agent.ts +++ b/packages/core/src/agent/agent.ts @@ -3794,6 +3794,12 @@ export class Agent { } private shouldPersistMemoryForContext(oc: OperationContext): boolean { + // Skip memory persistence for delegated sub-agent calls to prevent + // polluting the parent conversation's memory with duplicate messages. + // See: https://github.com/VoltAgent/voltagent/issues/1026 + if (oc.parentAgentId) { + return false; + } return !this.isReadOnlyMemoryForContext(oc); }