From 7fd685f53ac270476424287d941d29020823ccdd Mon Sep 17 00:00:00 2001 From: Jon Saad-Falcon <41205309+jonsaadfalcon@users.noreply.github.com> Date: Sat, 28 Mar 2026 14:29:54 -0700 Subject: [PATCH] feat: inject current date/time into system prompt dynamically The model now knows today's date and time. _build_system_prompt() generates a fresh prompt with "Today is Saturday, March 28, 2026. The current time is 02:28 PM." on every agent.run() call. Fixes: model was hallucinating "January 29, 2025" for date queries. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/openjarvis/agents/deep_research.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/openjarvis/agents/deep_research.py b/src/openjarvis/agents/deep_research.py index a07cdd92..e806698d 100644 --- a/src/openjarvis/agents/deep_research.py +++ b/src/openjarvis/agents/deep_research.py @@ -31,12 +31,23 @@ def _tc_args(tc: dict) -> str: return tc["arguments"] -DEEP_RESEARCH_SYSTEM_PROMPT = """\ +def _build_system_prompt() -> str: + """Build the system prompt with the current date injected.""" + from datetime import datetime + + now = datetime.now() + date_str = now.strftime("%A, %B %d, %Y") + time_str = now.strftime("%I:%M %p") + + return f"""\ /no_think You are Jarvis, a personal AI assistant with access to the user's private \ knowledge base — emails, text messages, meeting notes, documents, and notes. \ You are helpful, conversational, and smart about when to use your tools. +**Today is {date_str}. The current time is {time_str}.** \ +Use this for any time-related queries ("today", "this week", "recently", etc.). + ## How to Respond Read the query and decide which response type fits best: @@ -134,6 +145,10 @@ abbreviations, related terms. - If nothing found, say so honestly and suggest alternatives.""" +# Backward-compatible constant (static snapshot, prefer _build_system_prompt()) +DEEP_RESEARCH_SYSTEM_PROMPT = _build_system_prompt() + + @AgentRegistry.register("deep_research") class DeepResearchAgent(ToolUsingAgent): """Multi-hop research agent with native function calling and citations.""" @@ -199,9 +214,9 @@ class DeepResearchAgent(ToolUsingAgent): ) -> AgentResult: self._emit_turn_start(input) - # Build system prompt and initial messages + # Build system prompt with current date/time injected messages = self._build_messages( - input, context, system_prompt=DEEP_RESEARCH_SYSTEM_PROMPT + input, context, system_prompt=_build_system_prompt() ) # Prepare OpenAI-format tool definitions for native function calling