/** * Background reflection triggered by negative user feedback (thumbs-down). * * Flow: * 1. User thumbs-down -> invoke handler acks immediately * 2. This module runs in the background (fire-and-forget) * 3. Reads recent session context * 4. Sends a synthetic reflection prompt to the agent * 5. Stores the derived learning in session * 6. Optionally sends a proactive follow-up to the user
*/
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime"; import {
dispatchReplyFromConfigWithSettledDispatcher,
type OpenClawConfig,
} from "../runtime-api.js"; import type { StoredConversationReference } from "./conversation-store.js"; import { formatUnknownError } from "./errors.js"; import { buildReflectionPrompt, parseReflectionResponse } from "./feedback-reflection-prompt.js"; import {
DEFAULT_COOLDOWN_MS,
clearReflectionCooldowns,
isReflectionAllowed,
loadSessionLearnings,
recordReflectionTime,
storeSessionLearning,
} from "./feedback-reflection-store.js"; import type { MSTeamsAdapter } from "./messenger.js"; import { buildConversationReference } from "./messenger.js"; import type { MSTeamsMonitorLogger } from "./monitor-types.js"; import { getMSTeamsRuntime } from "./runtime.js";
/** * Run a background reflection after negative feedback. * This is designed to be called fire-and-forget (don't await in the invoke handler).
*/
export async function runFeedbackReflection(params: RunFeedbackReflectionParams): Promise<void> { const { cfg, log, sessionKey } = params; const cooldownMs = cfg.channels?.msteams?.feedbackReflectionCooldownMs ?? DEFAULT_COOLDOWN_MS; if (!isReflectionAllowed(sessionKey, cooldownMs)) {
log.debug?.("skipping reflection (cooldown active)", { sessionKey }); return;
}
const reflectionResponse = capture.readResponse().trim(); if (!reflectionResponse) {
log.debug?.("reflection produced no output"); return;
}
const parsedReflection = parseReflectionResponse(reflectionResponse); if (!parsedReflection) {
log.debug?.("reflection produced no structured output"); return;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.