feat: time awareness subsystem for continuous temporal perception - #61738
feat: time awareness subsystem for continuous temporal perception#61738k-QRedHacker wants to merge 1 commit into
Conversation
Three-layer implementation: - Layer 1: Dormancy perception in system prompt (volatile_parts) - Layer 2: Heartbeat rhythm in API messages (5-min throttled) - Layer 3: Lifecycle anchoring on session transition Agent can now perceive how long it slept between sessions, current wall-clock time, and interval between turns. Does not break prompt caching. No extra LLM credits wasted. Co-authored-by: Claw F (量子红客组织) Architectural guidance: 黄昏 (Huanghun)
Duplicate of #61731 — same author, same title, same four files ( |
|
-----来件已收悉,谢谢您。
|
|
Superseded by #61837 — clean, focused time awareness PR. Thanks @alt-glitch for the thorough review. |
|
You're right on all three counts. I've split this into a clean PR:
Closing this in favor of #61837. Thanks for the thorough review. |
Time Awareness: Injecting Temporal Perception into Hermes Agent
Abstract
This PR introduces a Time Awareness subsystem that gives Hermes Agent continuous perception of time flow across sessions and turns, without breaking prompt caching or consuming unnecessary LLM credits.
Companion bug fix: This PR also includes a fix for a critical bug where custom provider stream drops cause permanent API key loss. See Appendix B.
Part A: Feature — Time Awareness
Problem
Hermes Agent currently has no built-in perception of time. The system prompt includes a date-stable
Conversation started:line, but this does not convey:Design Principles
Architecture: Three-Layer Time Awareness
Layer 1: Dormancy Perception (
agent/system_prompt.py→ volatile_parts)time_state.jsonforlast_sleep_at.sleep_duration = now - last_sleep_ts.你上次休眠于: XX,休眠时长: XXLayer 2: Heartbeat Rhythm (
agent/chat_completion_helpers.py→build_api_kwargs)api_messages.[时间心跳] 当前: XX | 会话开始: XX | 距上次心跳: XXLayer 3: Lifecycle Anchoring (
run_agent.py→_transition_context_engine_session)/new,/reset, session expiry), records sleep timestamp.New File:
agent/time_awareness.py(~180 lines)_read_state()/_write_state()— atomic JSON I/Oon_session_start()— Layer 1 entry pointon_api_call(min_interval_secs=300)— Layer 2, returns string or None (throttled)on_session_end()— Layer 3 entry pointAdditional: Session Handoff Auto-Loading
system_prompt.pyreads~/.hermes/session_handoff/*.mdat session build.Testing
Impact
time_state.json(~300 bytes)Part B: Bug Fix — Custom Provider Stream Drop Causes Permanent API Key Loss
Problem
When a custom provider (e.g., Alibaba MaaS via
provider: custom) experiences a stream drop, the gateway enters a state where all subsequent LLM requests fail silently. The gateway process remains alive and platform connections stay connected — users receive no error notification.Root Cause
Two bugs combine:
Bug 1 —
_client_kwargscleared on fallback (chat_completion_helpers.py):When fallback activates,
agent._client_kwargs = {}discards the API key and base URL.Bug 2 — No defensive check during rebuild (
run_agent.py):_replace_primary_openai_client()rebuilds the OpenAI client from empty_client_kwargs, raisingValueError: The api_key client option must be set. The error is caught but not surfaced.Impact Matrix
Fix
_replace_primary_openai_client(): check for missingapi_key/base_urland refill from agent runtime attributes.Diagnostic
Changed Files
agent/time_awareness.pyagent/system_prompt.pyagent/chat_completion_helpers.pyrun_agent.pyCredits
中文版摘要
一、时间感知三层架构
Layer 1 — 休眠感知: session构建时注入"你上次休眠于XX,休眠XX",不破坏缓存。
Layer 2 — 心跳节律: 每轮API调用前注入当前时间和调用间隔,5分钟节流。
Layer 3 — 生命周期锚点: session切换时自动记录休眠时间,形成闭环。
二、Bug: Custom Provider Stream Drop 导致永久失去 API Key
stream drop 后 fallback 路径清空了
_client_kwargs,重建 client 时缺少 api_key,导致所有后续请求静默失败。修复:防御性回填 + 保留 kwargs。三、记忆优化
MEMORY.md 从4600字符瘦身到578字符,细节移至 skill 文件。
Co-authored-by: Claw F (量子红客组织)
Architectural guidance: 黄昏 (Huanghun)