Skip to content

refactor: move current time from system prompt to user message for prompt cache stability#3203

Open
wuyuanfr wants to merge 2 commits into
ModelEngine-Group:developfrom
liudfgoo:memory-develop
Open

refactor: move current time from system prompt to user message for prompt cache stability#3203
wuyuanfr wants to merge 2 commits into
ModelEngine-Group:developfrom
liudfgoo:memory-develop

Conversation

@wuyuanfr

@wuyuanfr wuyuanfr commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Move the current-time injection from the system prompt to the user message side, so the rendered system prompt becomes fully deterministic per agent config version — enabling prompt/KV cache hits across requests.

Changes

File Change
backend/prompts/manager_system_prompt_template_{en,zh}.yaml Remove it is {{time}} now / 现在是{{time}}
backend/prompts/managed_system_prompt_template_{en,zh}.yaml Same as above
backend/utils/context_utils.py Drop time_str param and "Current time" line from _format_app_context, build_skeleton_header_component, build_context_components, build_app_context_string; remove unused datetime import
backend/agents/create_agent_info.py Remove time from render_kwargs and build_context_components call; remove datetime import
sdk/nexent/core/agents/core_agent.py In run(), prepend [Current time: …] to self.task so the timestamp travels with the user message
test/backend/utils/test_context_utils.py Drop time_str= from 3 test cases

Why

A timestamp baked into the system prompt changes on every request, preventing the LLM prompt/KV cache from matching across requests. By shifting the time to the user-message prefix, the system prefix becomes static text — the rendered system prompt is now identical for any given (agent_id, tenant_id, version_no, language) tuple, making it directly cacheable.

Test

All 5 related test suites pass individually (389 cases total).

image

Notes

  • The EN templates never had user_id; this PR only removes time and does not add user_id to EN, preserving the existing EN/ZH asymmetry (can be addressed in a follow-up PR).
  • skill_creation_agent uses an independent prompt and is unaffected.
  • Side benefit: prompt_template["system_prompt"] Jinja rendering is now fully deterministic, enabling a (agent_id, tenant_id, version_no, language)-level cache in create_agent_config for further CPU savings.

…ompt cache stability

Remove {{time}} from all 4 prompt YAML templates (manager/managed × en/zh)
and strip time_str from the context_utils pipeline (_format_app_context,
build_skeleton_header_component, build_context_components,
build_app_context_string). Also remove time from create_agent_info render
kwargs and build_context_components call.

In CoreAgent.run, prepend [Current time: ...] to self.task so the timestamp
travels with the user message instead of being baked into the system prompt.
This makes the rendered system prompt fully deterministic per (agent_id,
tenant_id, version_no, language) — enabling prompt/KV cache hits across
requests for the same agent config.

Sync test_context_utils.py: drop time_str= from 3 test cases.

Remove unused datetime imports from context_utils.py and create_agent_info.py.
@wuyuanfr wuyuanfr requested review from Dallas98 and WMC001 as code owners June 8, 2026 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants