Skip to content

feat: inject current time into system prompt on every API call#5241

Closed
tsamuels-432 wants to merge 1 commit into
NousResearch:mainfrom
tsamuels-432:feat/per-turn-current-time
Closed

feat: inject current time into system prompt on every API call#5241
tsamuels-432 wants to merge 1 commit into
NousResearch:mainfrom
tsamuels-432:feat/per-turn-current-time

Conversation

@tsamuels-432

@tsamuels-432 tsamuels-432 commented Apr 5, 2026

Copy link
Copy Markdown

Appends Current time: Sunday, April 05, 2026 11:45 AM to the bottom of the system prompt on every API call so the model knows what time it is — not just when the conversation started.


Details

Without this, the model only sees a static Conversation started: timestamp from session creation. In a long-running session, it has no idea hours have passed.

One 4-line block added in the two places in run_agent.py that build the system message before calling the LLM:

  1. run_conversation() — main conversation loop
  2. _handle_max_iterations() — final summary when max tool calls reached

Inserted right before the existing api_messages = [{"role": "system", ...}] + api_messages line in each:

# Inject current time into system prompt on every API call
from hermes_time import now as _hermes_now
_current_time = _hermes_now().strftime("%A, %B %d, %Y %I:%M %p")
effective_system = effective_system + f"\n\nCurrent time: {_current_time}"
  • Uses hermes_time.now() (respects HERMES_TIMEZONE / config.yaml)
  • Local import follows the existing pattern at line ~2613 in _build_system_prompt()
  • Appended at the tail so the stable prefix above stays unchanged for prompt caching
  • 8 lines added, 1 file changed, no new dependencies

Appends a 'Current time: <timestamp>' line to the end of the system
prompt before each LLM call. This gives the model accurate time
awareness on every turn, not just the session start.

The existing 'Conversation started:' timestamp is static — it's baked
into the cached system prompt once at session creation. In long-running
sessions (hours or days), the model has no idea what time it actually
is on subsequent turns.

This patch adds a dynamic 'Current time:' line that is freshly computed
on every API call, using the existing hermes_time.now() helper (which
respects HERMES_TIMEZONE and config.yaml timezone settings).

Placed at the tail of the system prompt to preserve Anthropic prompt
cache prefix stability — everything above (identity, tools, skills,
memory) stays identical between turns so cache hits are maintained.

Applied in both code paths that make LLM API calls:
- run_conversation() main loop (~line 6907)
- summarization/compression path (~line 6368)
@tsamuels-432

Copy link
Copy Markdown
Author

Worth noting, the comment at line 6902-6905 says plugin context goes in the user message to avoid breaking prompt cache. This change intentionally goes in the system prompt instead because:

  1. The current time is a Hermes internal, same as the existing Conversation started: line that's already in the system prompt. It's not external plugin context.
  2. Putting it at the very end of the system prompt means only the last ~20 tokens change per turn. Everything above (identity, tools, skills, memory) still matches for prefix caching. We could also make the language more concise, perhaps remove the seconds precision, and just say "Current Time 2026-04-05 11:19PM"
  3. The alternative — injecting it into the user message — works but feels wrong. The time isn't something the user said, it's framework context.

There is a small cache cost for the system prompt block itself, but it's a few tokens vs the model having no idea what time it is after turn 1.

Happy to rework this as a plugin or in a better location, let me know.

@akuckartz

Copy link
Copy Markdown

@tsamuels-432

Copy link
Copy Markdown
Author

Why not use https://github.com/modelcontextprotocol/servers/tree/main/src/time Time MCP Server instead ?

Prevents a tool call. It adds latency.

@tsamuels-432 tsamuels-432 closed this by deleting the head repository Apr 27, 2026
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/agent Core agent loop, run_agent.py, prompt builder labels Apr 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #10448 — same per-turn live time injection in run_agent.py. #10448 is still open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder 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.

3 participants