fix(heartbeat): inject current datetime into Phase 1 prompt
Phase 1 _decide() now includes "Current date/time: YYYY-MM-DD HH:MM UTC" in the user prompt and instructs the LLM to use it for time-aware scheduling. Without this, the LLM defaults to 'run' for any task description regardless of whether it is actually due, defeating Phase 1's pre-screening purpose. Closes #1929
This commit is contained in:
@@ -250,3 +250,47 @@ async def test_decide_retries_transient_error_then_succeeds(tmp_path, monkeypatc
|
||||
assert tasks == "check open tasks"
|
||||
assert provider.calls == 2
|
||||
assert delays == [1]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
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"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user