feat: inject current time into system prompt on every API call#5241
Closed
tsamuels-432 wants to merge 1 commit into
Closed
feat: inject current time into system prompt on every API call#5241tsamuels-432 wants to merge 1 commit into
tsamuels-432 wants to merge 1 commit into
Conversation
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)
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:
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. |
|
Why not use https://github.com/modelcontextprotocol/servers/tree/main/src/time Time MCP Server instead ? |
Author
Prevents a tool call. It adds latency. |
Collaborator
This was referenced Apr 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Appends
Current time: Sunday, April 05, 2026 11:45 AMto 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.pythat build the system message before calling the LLM:run_conversation()— main conversation loop_handle_max_iterations()— final summary when max tool calls reachedInserted right before the existing
api_messages = [{"role": "system", ...}] + api_messagesline in each:hermes_time.now()(respectsHERMES_TIMEZONE/config.yaml)_build_system_prompt()