Skip to content

fix(agent): inject turn-level live time context#10448

Closed
Sapientropic wants to merge 1 commit into
NousResearch:mainfrom
Sapientropic:fix/turn-level-live-time-context
Closed

fix(agent): inject turn-level live time context#10448
Sapientropic wants to merge 1 commit into
NousResearch:mainfrom
Sapientropic:fix/turn-level-live-time-context

Conversation

@Sapientropic

Copy link
Copy Markdown

Summary

Hermes currently has a session-level Conversation started: ... timestamp, but it does not provide a reliable turn-level live sense of "now" for each API call.

This PR adds a turn-scoped Current time: YYYY-MM-DD HH:MM (TZ) hint at API-call time instead of baking live time into the cached session prompt.

What changed

  • add _build_live_time_context() in run_agent.py
  • add _build_turn_scoped_system_prompt() so live time is injected per API call, not into _build_system_prompt()
  • use that helper in both:
    • run_conversation()
    • _handle_max_iterations()
  • add targeted tests for:
    • cached system prompt stays free of Current time:
    • chat-completions run path injects live time
    • max-iteration summary path injects live time
    • codex responses path injects live time

Why this shape

This is intentionally aligned with the request in #10421:

  • live time is turn-scoped
  • it is injected at API-call time
  • it does not mutate the session-cached system prompt
  • it works for both chat-completions and codex-responses paths

Relation to other work

This PR is intentionally narrower than #10061.

They are adjacent, but not the same fix.

Repro verified

I re-verified the gap locally on:

  • latest stable v0.9.0 released on April 13, 2026
  • current main at 422f2866 on April 16, 2026

In both cases, Hermes still had only the session-start timestamp and no turn-level live Current time: context.

How to test

python -m pytest tests/run_agent/test_run_agent.py -k 'turn_level_live_time or excludes_turn_level or summary_injects'
python -m pytest tests/run_agent/test_run_agent_codex_responses.py -k 'turn_level_live_time'

Refs #10421

@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 26, 2026
@quinnmacro

Copy link
Copy Markdown

Hi @Sapientropic — I noticed this is closely related to my PR #15872 which addresses the same root cause (no turn-level live time). I wanted to flag a key architectural difference for the maintainers:

This PR (#10448) injects Current time: into the system prompt via _build_turn_scoped_system_prompt(). This means the system prompt content changes every turn, which breaks prompt cache prefix — the system message sent to the API is no longer identical across turns.

PR #15872 injects Current time: into the user message (same mechanism as pre_llm_call plugin context). This preserves prompt cache — the system prompt stays frozen and identical across turns, while dynamic time goes into the per-turn user message.

The Hermes codebase itself documents this principle (around run_conversation line 9449):

"Context is ALWAYS injected into the user message, never the system prompt. This preserves the prompt cache prefix — the system prompt stays identical across turns so cached tokens are reused."

However, this PR has advantages that #15872 initially lacked (now added):

  • ✅ Test coverage (3 test paths)
  • _handle_max_iterations() path covered
  • ✅ Codex responses path covered

I have updated #15872 to also cover _handle_max_iterations() with tests and user-message injection. The codex responses path still needs coverage.

Happy to collaborate on a unified approach — the ideal solution would use user-message injection (for cache preservation) with the comprehensive path coverage and tests from this PR.

@markojak

Copy link
Copy Markdown

Closing this as superseded by #17459/#17476.

The problem statement is valid, but the selected direction is to consolidate on a single core ephemeral runtime/user-message context path, preferably based on #15872, while keeping volatile current time out of the cached system prompt/cacheable prefix. A turn-scoped system-prompt path risks reintroducing prompt-cache instability or another parallel timestamp mechanism.

Please rebase any still-useful pieces (tests, wording, helper code) into #15872/#17476 rather than pursuing this PR as a standalone path.

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.

5 participants