Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(heartbeat): inject current datetime into Phase 1 prompt
who960dda2b23e632
diff --git a/nanobot/heartbeat/service.py b/nanobot/heartbeat/service.pyindex 2242802d2..2b8db9d2e 100644--- a/nanobot/heartbeat/service.py+++ b/nanobot/heartbeat/service.py@@ -3,6 +3,7 @@from __future__ import annotationsimport asyncio+from datetime import datetime, timezonefrom pathlib import Pathfrom typing import TYPE_CHECKING, Any, Callable, Coroutine@@ -87,10 +88,19 @@ class HeartbeatService:Returns (action, tasks) where action is 'skip' or 'run'."""+ now_str = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")+response = await self.provider.chat_with_retry(messages=[- {"role": "system", "content": "You are a heartbeat agent. Call the heartbeat tool to report your decision."},+ {"role": "system", "content": (+ "You are a heartbeat agent. Call the heartbeat tool to report your decision. "+ "The current date/time is provided so you can evaluate time-based conditions. "+ "Choose 'run' if there are active tasks to execute. "+ "Choose 'skip' if the file has no actionable tasks, if blocking conditions "+ "are not yet met, or if tasks are scheduled for a future time that has not arrived yet."+ )},{"role": "user", "content": (+ f"Current date/time: {now_str}\n\n""Review the following HEARTBEAT.md and decide whether there are active tasks.\n\n"f"{content}")},diff --git a/tests/test_heartbeat_service.py b/tests/test_heartbeat_service.pyindex 2a6b20eb6..e330d2ba0 100644--- a/tests/test_heartbeat_service.py+++ b/tests/test_heartbeat_service.py@@ -250,3 +250,47 @@ async def test_decide_retries_transient_error_then_succeeds(tmp_path, monkeypatcassert tasks == "check open tasks"assert provider.calls == 2assert delays == [1]+++async def test_decide_prompt_includes_current_datetime(tmp_path) -> None:+ """Phase 1 prompt must contain the current date/time so the LLM can judge task urgency."""++ captured_messages: list[dict] = []++ class CapturingProvider(LLMProvider):+ async def chat(self, *, messages=None, **kwargs) -> LLMResponse:+ if messages:+ captured_messages.extend(messages)+ return LLMResponse(+ content="",+ tool_calls=[+ ToolCallRequest(+ id="hb_1", name="heartbeat",+ arguments={"action": "skip"},+ )+ ],+ )++ def get_default_model(self) -> str:+ return "test-model"++ service = HeartbeatService(+ workspace=tmp_path,+ provider=CapturingProvider(),+ model="test-model",+ )++ await service._decide("- [ ] check servers at 10:00 UTC")++ # System prompt should mention date/time awareness+ system_msg = captured_messages[0]+ assert system_msg["role"] == "system"+ assert "date/time" in system_msg["content"].lower()++ # User prompt should contain a UTC timestamp+ user_msg = captured_messages[1]+ assert user_msg["role"] == "user"+ assert "Current date/time:" in user_msg["content"]+ assert "UTC" in user_msg["content"]+