Enhance User Input Buffering Logic for Delegated Agents
- Updated the BufferUserInput method to ensure only the root stack buffers user input, preventing duplication in delegated agents. - Added comments in the Stream and processNextResponse methods to clarify that user input is already buffered by the root agent, allowing delegated agents to skip this step. - Improved code clarity and maintainability by documenting delegation behavior in the context of user input handling.
This commit is contained in:
parent
7b3df059c4
commit
401f22eeb1
3 changed files with 8 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue