

























@@ -12,6 +12,10 @@ const REPLY_MEDIA_HINT =
1212"To send an image back, prefer the message tool (media/path/filePath). If you must inline, use MEDIA:https://example.com/image.jpg (spaces ok, quote if needed) or a safe relative path like MEDIA:./image.jpg. Absolute and ~ paths only work when they stay inside your allowed file-read boundary; host file:// URLs are blocked. Keep caption in the text body.";
1313const ROOM_EVENT_PROMPT = "[OpenClaw room event]";
1414const ROOM_EVENT_SOURCE_REPLY_DELIVERY_MODE = "message_tool_only";
15+const RESUMABLE_ROOM_CONTEXT_OMITTED_PREFIXES = [
16+"Conversation context (untrusted, chronological, selected for current message):",
17+"Chat history since last reply (untrusted, for context):",
18+];
15191620export function buildReplyPromptBodies(params: {
1721ctx: MsgContext;
@@ -131,8 +135,9 @@ function resolveRoomEventBody(params: ReplyPromptEnvelopeBaseParams): string {
131135);
132136}
133137134-function buildRoomEventContext(params: ReplyPromptEnvelopeBaseParams): string {
138+function buildRoomEventContext(params: ReplyPromptEnvelopeBaseParams, roomContext: string): string {
135139const roomEventBody = resolveRoomEventBody(params);
140+const roomContextBlock = roomContext.trim() ? `Room context:\n${roomContext.trim()}` : "";
136141const visibleReplyContract =
137142params.sourceReplyDeliveryMode === "message_tool_only"
138143 ? `visible_reply_contract: ${ROOM_EVENT_SOURCE_REPLY_DELIVERY_MODE}`
@@ -141,23 +146,35 @@ function buildRoomEventContext(params: ReplyPromptEnvelopeBaseParams): string {
141146"[OpenClaw room event]",
142147"inbound_event_kind: room_event",
143148visibleReplyContract,
144-params.inboundUserContext.trim() ? `Room context:\n${params.inboundUserContext.trim()}` : "",
149+roomContextBlock,
145150`Current event:\n${formatRoomEventLine(params.sessionCtx, roomEventBody)}`,
146151"Treat this as observed room activity. Decide whether to act.",
147152]
148153.filter(Boolean)
149154.join("\n\n");
150155}
151156157+function buildResumableRoomContext(roomContext: string): string {
158+return roomContext
159+.split(/\n{2,}/u)
160+.filter(
161+(block) =>
162+!RESUMABLE_ROOM_CONTEXT_OMITTED_PREFIXES.some((prefix) => block.startsWith(prefix)),
163+)
164+.join("\n\n");
165+}
166+152167export function buildReplyPromptEnvelopeBase(
153168params: ReplyPromptEnvelopeBaseParams,
154169): ReplyPromptEnvelopeBase {
155170const softResetTail = params.softResetTail?.trim() ?? "";
156171const isRoomEvent = params.inboundEventKind === "room_event";
157-const roomEventContext = buildRoomEventContext(params);
158-const currentInboundContextText = isRoomEvent
159- ? roomEventContext
160- : params.inboundUserContext.trim();
172+const inboundUserContext = params.inboundUserContext.trim();
173+const roomEventContext = buildRoomEventContext(params, inboundUserContext);
174+const resumableRoomEventContext = isRoomEvent
175+ ? buildRoomEventContext(params, buildResumableRoomContext(inboundUserContext))
176+ : undefined;
177+const currentInboundContextText = isRoomEvent ? roomEventContext : inboundUserContext;
161178const resetModelBody = params.isBareSessionReset
162179 ? [
163180params.inboundUserContext,
@@ -188,6 +205,7 @@ export function buildReplyPromptEnvelopeBase(
188205!params.isBareSessionReset && currentInboundContextText
189206 ? {
190207text: currentInboundContextText,
208+ ...(resumableRoomEventContext ? { resumableText: resumableRoomEventContext } : {}),
191209promptJoiner: params.inboundUserContextPromptJoiner,
192210}
193211 : undefined;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。