Inject live datetime into system prompt per invocation with relative-time instruction
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import os
|
||||
import boto3
|
||||
from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
# Cache keyed by actor_id ('' = global/no user)
|
||||
@@ -9,9 +11,24 @@ _prompt_cache: dict[str, str] = {}
|
||||
def build_system_prompt(user_context: str = '', actor_id: str = '') -> str:
|
||||
"""Build system prompt from S3 workspace files + optional per-user context."""
|
||||
base = _get_base_prompt(actor_id)
|
||||
|
||||
# Dynamic block — injected fresh every call, never cached
|
||||
chicago = ZoneInfo('America/Chicago')
|
||||
now = datetime.now(chicago)
|
||||
dt_str = now.strftime('%A %Y-%m-%d %H:%M:%S %Z')
|
||||
time_block = (
|
||||
f'## Current Time\n'
|
||||
f'The current date and time is: {dt_str}\n\n'
|
||||
f'When examining any other date or time value, calculate its distance from now '
|
||||
f'(in seconds, minutes, hours, or days as appropriate) before drawing conclusions '
|
||||
f'like "upcoming", "overdue", "recent", "just happened", or "a long time ago". '
|
||||
f'Do this arithmetic explicitly — do not estimate or assume.'
|
||||
)
|
||||
|
||||
parts = [base, time_block]
|
||||
if user_context:
|
||||
return base + f'\n\n---\n\n## User\n{user_context}'
|
||||
return base
|
||||
parts.append(f'## User\n{user_context}')
|
||||
return '\n\n---\n\n'.join(parts)
|
||||
|
||||
|
||||
def _get_base_prompt(actor_id: str = '') -> str:
|
||||
@@ -58,7 +75,7 @@ def _get_base_prompt(actor_id: str = '') -> str:
|
||||
except Exception as e:
|
||||
print(f'[prompt_builder] Failed to load {fname}: {e}')
|
||||
|
||||
parts.append('## Runtime\nRuntime: agent-claw | host=AgentCore | model=bedrock-claude-sonnet | channel=telegram\nCurrent date/time is provided by the system. Timezone: America/Chicago.')
|
||||
parts.append('## Runtime\nRuntime: agent-claw | host=AgentCore | model=bedrock-claude-sonnet | channel=telegram | timezone=America/Chicago')
|
||||
|
||||
result = '\n\n---\n\n'.join(parts)
|
||||
_prompt_cache[actor_id] = result
|
||||
|
||||
Reference in New Issue
Block a user