fix(agent): inject Shanghai time into each reply message
103 goosed harness_remember returns remembered:false, so session memory never carried the time anchor. Prepend buildCurrentTimeAgentPrefix on every H5 /reply and WeChat agent prompt so the model sees Asia/Shanghai clock. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+22
-4
@@ -11,7 +11,7 @@ import {
|
||||
PUBLISH_ROOT_DIR,
|
||||
resolvePublicBaseUrl,
|
||||
} from './user-publish.mjs';
|
||||
import { buildTaskRoutingAgentText } from './user-memory-profile.mjs';
|
||||
import { buildCurrentTimeAgentPrefix, buildTaskRoutingAgentText } from './user-memory-profile.mjs';
|
||||
import { reconcileAgentSession } from './session-reconcile.mjs';
|
||||
import { createImgproxySigner } from './imgproxy-signer.mjs';
|
||||
|
||||
@@ -343,11 +343,11 @@ function messageHasImages(userMessage) {
|
||||
return extractImageUrlsFromMessage(userMessage).length > 0;
|
||||
}
|
||||
|
||||
function injectTaskRoutingHint(body, sessionPolicy) {
|
||||
function prependAgentTextToUserMessage(body, transformText) {
|
||||
const originalText = firstUserText(body?.user_message);
|
||||
if (!originalText?.trim()) return body;
|
||||
|
||||
const agentText = buildTaskRoutingAgentText(originalText, sessionPolicy);
|
||||
const agentText = transformText(originalText);
|
||||
if (!agentText || agentText === originalText) return body;
|
||||
|
||||
const userMessage = body.user_message ?? {};
|
||||
@@ -377,6 +377,20 @@ function injectTaskRoutingHint(body, sessionPolicy) {
|
||||
};
|
||||
}
|
||||
|
||||
function injectCurrentTimeAnchor(body, timezone) {
|
||||
const tz = String(timezone ?? process.env.H5_DEFAULT_TIMEZONE ?? 'Asia/Shanghai').trim() || 'Asia/Shanghai';
|
||||
return prependAgentTextToUserMessage(body, (originalText) => {
|
||||
if (originalText.includes('TKMind 当前时间基准')) return originalText;
|
||||
return `${buildCurrentTimeAgentPrefix({ timezone: tz })}${originalText}`;
|
||||
});
|
||||
}
|
||||
|
||||
function injectTaskRoutingHint(body, sessionPolicy) {
|
||||
return prependAgentTextToUserMessage(body, (originalText) =>
|
||||
buildTaskRoutingAgentText(originalText, sessionPolicy),
|
||||
);
|
||||
}
|
||||
|
||||
export async function buildVisionPayload({
|
||||
userMessage,
|
||||
userId,
|
||||
@@ -1336,8 +1350,12 @@ export function createTkmindProxy({
|
||||
|
||||
let baseBody = req.body;
|
||||
if (isReplyPath && !policyState.unrestricted) {
|
||||
const publishLayout = await userAuth
|
||||
.getUserPublishLayout(req.currentUser.id)
|
||||
.catch(() => null);
|
||||
baseBody = injectCurrentTimeAnchor(req.body, publishLayout?.timezone);
|
||||
baseBody = injectTaskRoutingHint(
|
||||
req.body,
|
||||
baseBody,
|
||||
await userAuth.getAgentSessionPolicy(req.currentUser.id),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user