Skip to content

feat(gateway): inject current timestamp into user messages#5487

Open
willy-scr wants to merge 4 commits into
NousResearch:mainfrom
willy-scr:feat/message-timestamp-injection
Open

feat(gateway): inject current timestamp into user messages#5487
willy-scr wants to merge 4 commits into
NousResearch:mainfrom
willy-scr:feat/message-timestamp-injection

Conversation

@willy-scr

@willy-scr willy-scr commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Injects a human-readable timestamp at the top of every user message before it reaches the agent, so the agent always knows the current date and time without needing to invoke a tool call.

Format: [Current time: Monday, April 06, 2026 07:36 AM]

Why

Agents running long conversations often lose track of time. The only built-in mechanism is the Conversation started: header, which becomes stale after minutes or hours of back-and-forth. Currently the agent must spend a date tool call just to answer "what time is it?" or "what day is today?" — wasting tokens and latency.

This is especially important for:

  • Cron-scheduled tasks — the agent wakes up with no conversation history and no time context
  • Long multi-turn conversations — the original timestamp is hours old
  • Time-sensitive instructions — "remind me at 3pm", "is it past midnight?", etc.

What Changed

Core Injection (gateway/run.py)

Inside _run_agent(), right before agent.run_conversation():

  • Check display.gateway_timestamp config (default: true)
  • Get current time via datetime.now()
  • Set locale to en_US.UTF-8 for consistent day/month names (with graceful fallback)
  • Format as human-readable string: Monday, April 06, %Y %I:%M %p
  • Prepend [Current time: ...]\n\n to the message

Config Toggle (hermes_cli/config.py)

  • Add display.gateway_timestamp: true to DEFAULT_CONFIG
  • Persisted in config.yaml — survives restarts

Slash Command (hermes_cli/commands.py + gateway/run.py)

  • Add /timestamps (alias /ts) command — toggles injection on/off
  • Available in both CLI and messaging gateway
  • Takes effect immediately without restart
  • Persists to config.yaml

Design Decisions

Decision Rationale
datetime.now() instead of injecting into system prompt The message-level approach works for ALL model providers (some strip system prompts)
Locale en_US.UTF-8 with try/except fallback Server locale may be non-English; we want consistent English output
Prepend to message, not modify agent API Zero-impact change — no changes to agent interface, prompt builder, or context files
Only in _run_agent (gateway path) CLI mode has direct terminal access; gateway agents need the injection
Config toggle + slash command Some users may not want the token overhead; easy on/off without code changes
Default true Time awareness is universally useful; users who don't want it can opt-out

Testing

Manual testing on self-hosted instance:

  • Agent correctly reports current time without any tool calls
  • Works across long multi-turn conversations (timestamp updated per message)
  • Cron jobs also receive timestamps (they pass through the same _run_agent path)
  • Gracefully handles missing en_US locale (falls back to server default)
  • /timestamps toggle works — ON/OFF states persist across messages and restarts
  • Config display.gateway_timestamp: false correctly disables injection

@willy-scr willy-scr force-pushed the feat/message-timestamp-injection branch from 3132311 to 6d334bc Compare April 6, 2026 10:19
Akah-dev and others added 4 commits April 9, 2026 17:36
Prepend a human-readable timestamp to every user message before passing
it to the agent.  The agent can then answer time-aware questions
(e.g. "what day is it?") without spending a tool call on `date`.

Format: [Current time: Monday, April 06, 2026 07:36 AM]
Uses locale-aware strftime with en_US fallback for consistent English
day/month names.
@markojak

Copy link
Copy Markdown

Closing this as superseded by #17459/#17476.

The need is real, but we do not want a separate gateway-only timestamp-prefix mechanism. The chosen direction is one core ephemeral runtime/user-message context path for current time + timezone, with time-sensitive tools also returning explicit advisory metadata when relevant (#17474).

If there are useful tests or gateway adapter details here, please port them into the consolidated implementation rather than keeping this as a parallel feature flag.

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery labels Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants