diff --git a/src/agents/system-prompt.test.ts b/src/agents/system-prompt.test.ts index 809db837ef4..7b2d9718832 100644 --- a/src/agents/system-prompt.test.ts +++ b/src/agents/system-prompt.test.ts @@ -192,6 +192,41 @@ describe("buildAgentSystemPrompt", () => { expect(prompt).toContain("Time zone: America/Chicago"); }); + it("hints to use session_status for current date/time", () => { + const prompt = buildAgentSystemPrompt({ + workspaceDir: "/tmp/clawd", + userTimezone: "America/Chicago", + }); + + expect(prompt).toContain("session_status"); + expect(prompt).toContain("current date"); + }); + + // The system prompt intentionally does NOT include the current date/time. + // Only the timezone is included, to keep the prompt stable for caching. + // See: https://github.com/moltbot/moltbot/commit/66eec295b894bce8333886cfbca3b960c57c4946 + // Agents should use session_status or message timestamps to determine the date/time. + // Related: https://github.com/moltbot/moltbot/issues/1897 + // https://github.com/moltbot/moltbot/issues/3658 + it("does NOT include a date or time in the system prompt (cache stability)", () => { + const prompt = buildAgentSystemPrompt({ + workspaceDir: "/tmp/clawd", + userTimezone: "America/Chicago", + userTime: "Monday, January 5th, 2026 — 3:26 PM", + userTimeFormat: "12", + }); + + // The prompt should contain the timezone but NOT the formatted date/time string. + // This is intentional for prompt cache stability — the date/time was removed in + // commit 66eec295b. If you're here because you want to add it back, please see + // https://github.com/moltbot/moltbot/issues/3658 for the preferred approach: + // gateway-level timestamp injection into messages, not the system prompt. + expect(prompt).toContain("Time zone: America/Chicago"); + expect(prompt).not.toContain("Monday, January 5th, 2026"); + expect(prompt).not.toContain("3:26 PM"); + expect(prompt).not.toContain("15:26"); + }); + it("includes model alias guidance when aliases are provided", () => { const prompt = buildAgentSystemPrompt({ workspaceDir: "/tmp/openclaw", diff --git a/src/agents/system-prompt.ts b/src/agents/system-prompt.ts index dc4f1332a84..5be6fba1273 100644 --- a/src/agents/system-prompt.ts +++ b/src/agents/system-prompt.ts @@ -58,10 +58,13 @@ function buildUserIdentitySection(ownerLine: string | undefined, isMinimal: bool } function buildTimeSection(params: { userTimezone?: string }) { - if (!params.userTimezone) { - return []; - } - return ["## Current Date & Time", `Time zone: ${params.userTimezone}`, ""]; + if (!params.userTimezone) return []; + return [ + "## Current Date & Time", + `Time zone: ${params.userTimezone}`, + "If you need the current date, time, or day of week, use the session_status tool.", + "", + ]; } function buildSafetySection() {