fix: intercept [HEARTBEAT] prompt, suppress chatty non-urgent responses

This commit is contained in:
daniel
2026-05-15 18:34:14 -05:00
parent e00702164d
commit 4f17bbd2c3

View File

@@ -563,9 +563,21 @@ async def main(payload: dict, context):
tools=all_tools,
)
# Intercept heartbeat: replace bare [HEARTBEAT] with a strict-format instruction.
# Agent-runner suppresses replies that start with HEARTBEAT_OK, so only real alerts reach Telegram.
prompt = payload.get('prompt', '')
if prompt.strip() == '[HEARTBEAT]':
prompt = (
'HEARTBEAT CHECK: Silently check for anything urgent Daniel should know about '
'(calendar events starting within 2 hours, unread urgent emails, overdue reminders). '
'Do NOT narrate your checking process. '
'If nothing is urgent: reply with the single word HEARTBEAT_OK and nothing else. '
'If something IS urgent: reply with 2-3 lines max summarising only the urgent items.'
)
final_message = None
try:
async for event in agent.stream_async(payload.get('prompt', '')):
async for event in agent.stream_async(prompt):
if 'result' in event:
final_message = event['result'].message
yield event