diff --git a/pkg/agent/agent.go b/pkg/agent/agent.go index 97ee4fe7d..8c90f4ee2 100644 --- a/pkg/agent/agent.go +++ b/pkg/agent/agent.go @@ -258,7 +258,14 @@ func (al *AgentLoop) Run(ctx context.Context) error { return } if continued != "" { - al.PublishResponseIfNeeded(ctx, target.Channel, target.ChatID, target.SessionKey, continued) + al.publishResponseWithContextIfNeeded( + ctx, + target.Channel, + target.ChatID, + target.SessionKey, + continued, + &m.Context, + ) } return } diff --git a/pkg/agent/agent_outbound.go b/pkg/agent/agent_outbound.go index a9a5071f6..d89ea17d2 100644 --- a/pkg/agent/agent_outbound.go +++ b/pkg/agent/agent_outbound.go @@ -41,6 +41,14 @@ func (al *AgentLoop) publishResponseOrError( } func (al *AgentLoop) PublishResponseIfNeeded(ctx context.Context, channel, chatID, sessionKey, response string) { + al.publishResponseWithContextIfNeeded(ctx, channel, chatID, sessionKey, response, nil) +} + +func (al *AgentLoop) publishResponseWithContextIfNeeded( + ctx context.Context, + channel, chatID, sessionKey, response string, + inboundCtx *bus.InboundContext, +) { if response == "" { return } diff --git a/pkg/agent/agent_steering.go b/pkg/agent/agent_steering.go index 9b136e7cd..610bc2fad 100644 --- a/pkg/agent/agent_steering.go +++ b/pkg/agent/agent_steering.go @@ -58,7 +58,14 @@ func (al *AgentLoop) runTurnWithSteering(ctx context.Context, initialMsg bus.Inb // Publish final response if finalResponse != "" { - al.PublishResponseIfNeeded(ctx, target.Channel, target.ChatID, target.SessionKey, finalResponse) + al.publishResponseWithContextIfNeeded( + ctx, + target.Channel, + target.ChatID, + target.SessionKey, + finalResponse, + &initialMsg.Context, + ) } } diff --git a/pkg/channels/manager.go b/pkg/channels/manager.go index e88241d0b..a07f5785c 100644 --- a/pkg/channels/manager.go +++ b/pkg/channels/manager.go @@ -187,6 +187,15 @@ func trackedToolFeedbackMessageChatID(ch Channel, chatID string, outboundCtx *bu return strings.TrimSpace(chatID) } +func candidateToolFeedbackMessageChatIDs(raw, resolved string) []string { + raw = strings.TrimSpace(raw) + resolved = strings.TrimSpace(resolved) + if raw == "" || raw == resolved { + return []string{resolved} + } + return []string{resolved, raw} +} + func dismissTrackedToolFeedbackMessage( ctx context.Context, ch Channel, @@ -218,9 +227,9 @@ func dismissTrackedToolFeedbackMessageForSession( dismissTrackedToolFeedbackMessage(ctx, ch, chatID, outboundCtx) return } - resolvedChatID := resolveOutboundChatID(ch, chatID, outboundCtx) + resolvedChatID := trackedToolFeedbackMessageChatID(ch, chatID, outboundCtx) if cleaner, ok := ch.(toolFeedbackMessageCleaner); ok { - for _, candidate := range candidateChatIDs(chatID, resolvedChatID) { + for _, candidate := range candidateToolFeedbackMessageChatIDs(chatID, resolvedChatID) { if candidate == "" { continue } @@ -229,7 +238,7 @@ func dismissTrackedToolFeedbackMessageForSession( return } if tracker, ok := ch.(toolFeedbackMessageTracker); ok { - for _, candidate := range candidateChatIDs(chatID, resolvedChatID) { + for _, candidate := range candidateToolFeedbackMessageChatIDs(chatID, resolvedChatID) { if candidate == "" { continue }