feat(gateway): inject stable human-readable message timestamps

Consolidates these related Amy fork patches:
- 429830f39 feat(gateway): inject message timestamps into user messages for LLM context
- 3c3d6fac0 fix: handle both ISO string and epoch float timestamps in history replay
- 2874f7725 feat: human-friendly timestamp format with weekday and timezone name
- 3735f4c8b fix: render gateway message timestamps once
This commit is contained in:
Wolfram Ravenwolf 2026-05-18 03:51:58 +02:00 committed by Teknium
parent b7f0c9cd52
commit bd7fc8fdcd
13 changed files with 448 additions and 28 deletions

View file

@ -1472,16 +1472,21 @@ class AIAgent:
that synthetic text leak into persisted transcripts or resumed session
history. When an override is configured for the active turn, mutate the
in-memory messages list in place so both persistence and returned
history stay clean.
history stay clean. A paired timestamp override preserves the platform
event time as message metadata, rather than embedding it in content.
"""
idx = getattr(self, "_persist_user_message_idx", None)
override = getattr(self, "_persist_user_message_override", None)
if override is None or idx is None:
timestamp = getattr(self, "_persist_user_message_timestamp", None)
if idx is None or (override is None and timestamp is None):
return
if 0 <= idx < len(messages):
msg = messages[idx]
if isinstance(msg, dict) and msg.get("role") == "user":
msg["content"] = override
if override is not None:
msg["content"] = override
if timestamp is not None:
msg["timestamp"] = timestamp
def _persist_session(self, messages: List[Dict], conversation_history: List[Dict] = None):
"""Save session state to both JSON log and SQLite on any exit path.
@ -1639,6 +1644,7 @@ class AIAgent:
reasoning_details=msg.get("reasoning_details") if role == "assistant" else None,
codex_reasoning_items=msg.get("codex_reasoning_items") if role == "assistant" else None,
codex_message_items=msg.get("codex_message_items") if role == "assistant" else None,
timestamp=msg.get("timestamp"),
)
flushed_ids.add(msg_id)
self._last_flushed_db_idx = len(messages)
@ -5218,10 +5224,20 @@ class AIAgent:
task_id: str = None,
stream_callback: Optional[callable] = None,
persist_user_message: Optional[str] = None,
persist_user_timestamp: Optional[float] = None,
) -> Dict[str, Any]:
"""Forwarder — see ``agent.conversation_loop.run_conversation``."""
from agent.conversation_loop import run_conversation
return run_conversation(self, user_message, system_message, conversation_history, task_id, stream_callback, persist_user_message)
return run_conversation(
self,
user_message,
system_message,
conversation_history,
task_id,
stream_callback,
persist_user_message,
persist_user_timestamp,
)
def chat(self, message: str, stream_callback: Optional[callable] = None) -> str:
"""