fix(agents): preserve feedback target metadata

This commit is contained in:
Anton Bogdanovich 2026-05-06 18:50:21 -07:00
parent 2efdcb7bec
commit 62654a8cd8
4 changed files with 36 additions and 5 deletions

View file

@ -258,7 +258,14 @@ func (al *AgentLoop) Run(ctx context.Context) error {
return return
} }
if continued != "" { 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 return
} }

View file

@ -41,6 +41,14 @@ func (al *AgentLoop) publishResponseOrError(
} }
func (al *AgentLoop) PublishResponseIfNeeded(ctx context.Context, channel, chatID, sessionKey, response string) { 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 == "" { if response == "" {
return return
} }

View file

@ -58,7 +58,14 @@ func (al *AgentLoop) runTurnWithSteering(ctx context.Context, initialMsg bus.Inb
// Publish final response // Publish final response
if finalResponse != "" { if finalResponse != "" {
al.PublishResponseIfNeeded(ctx, target.Channel, target.ChatID, target.SessionKey, finalResponse) al.publishResponseWithContextIfNeeded(
ctx,
target.Channel,
target.ChatID,
target.SessionKey,
finalResponse,
&initialMsg.Context,
)
} }
} }

View file

@ -187,6 +187,15 @@ func trackedToolFeedbackMessageChatID(ch Channel, chatID string, outboundCtx *bu
return strings.TrimSpace(chatID) 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( func dismissTrackedToolFeedbackMessage(
ctx context.Context, ctx context.Context,
ch Channel, ch Channel,
@ -218,9 +227,9 @@ func dismissTrackedToolFeedbackMessageForSession(
dismissTrackedToolFeedbackMessage(ctx, ch, chatID, outboundCtx) dismissTrackedToolFeedbackMessage(ctx, ch, chatID, outboundCtx)
return return
} }
resolvedChatID := resolveOutboundChatID(ch, chatID, outboundCtx) resolvedChatID := trackedToolFeedbackMessageChatID(ch, chatID, outboundCtx)
if cleaner, ok := ch.(toolFeedbackMessageCleaner); ok { if cleaner, ok := ch.(toolFeedbackMessageCleaner); ok {
for _, candidate := range candidateChatIDs(chatID, resolvedChatID) { for _, candidate := range candidateToolFeedbackMessageChatIDs(chatID, resolvedChatID) {
if candidate == "" { if candidate == "" {
continue continue
} }
@ -229,7 +238,7 @@ func dismissTrackedToolFeedbackMessageForSession(
return return
} }
if tracker, ok := ch.(toolFeedbackMessageTracker); ok { if tracker, ok := ch.(toolFeedbackMessageTracker); ok {
for _, candidate := range candidateChatIDs(chatID, resolvedChatID) { for _, candidate := range candidateToolFeedbackMessageChatIDs(chatID, resolvedChatID) {
if candidate == "" { if candidate == "" {
continue continue
} }