diff --git a/agent/assistant/agent.go b/agent/assistant/agent.go index dcdb15b5..6803da38 100644 --- a/agent/assistant/agent.go +++ b/agent/assistant/agent.go @@ -176,6 +176,7 @@ func (ast *Assistant) Stream(ctx *context.Context, inputMessages []context.Messa ctx.Logger.Debug("Create hook delegating to agent: %s", createResponse.Delegate.AgentID) // Delegate to target agent (reuse existing delegation logic from next.go) + // Note: User input is already buffered by root agent, delegated agent will skip buffering delegateResponse, err := ast.handleDelegation(ctx, createResponse.Delegate, streamHandler) if err != nil { finalStatus = context.ResumeStatusFailed diff --git a/agent/assistant/chat.go b/agent/assistant/chat.go index 381472fe..f714950c 100644 --- a/agent/assistant/chat.go +++ b/agent/assistant/chat.go @@ -237,6 +237,12 @@ func (ast *Assistant) BufferUserInput(ctx *agentcontext.Context, inputMessages [ return } + // Only root stack should buffer user input + // Delegated agents share the same buffer but should not duplicate user input + if ctx.Stack != nil && !ctx.Stack.IsRoot() { + return + } + // Convert input messages to buffer format for _, msg := range inputMessages { // Extract content from message diff --git a/agent/assistant/next.go b/agent/assistant/next.go index accacaab..779b36c2 100644 --- a/agent/assistant/next.go +++ b/agent/assistant/next.go @@ -15,6 +15,7 @@ func (ast *Assistant) processNextResponse(npc *NextProcessContext) (*agentContex } // Handle Delegate: call another agent + // Note: User input is already buffered by root agent, delegated agent will skip buffering if npc.NextResponse.Delegate != nil { return ast.handleDelegation(npc.Context, npc.NextResponse.Delegate, npc.StreamHandler) }