refactor: move current time from system prompt to user message for prompt cache stability#3203
Open
wuyuanfr wants to merge 2 commits into
Open
refactor: move current time from system prompt to user message for prompt cache stability#3203wuyuanfr wants to merge 2 commits into
wuyuanfr wants to merge 2 commits into
Conversation
…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.
Jasonxia007
approved these changes
Jun 8, 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.
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
backend/prompts/manager_system_prompt_template_{en,zh}.yamlit is {{time}} now/现在是{{time}}backend/prompts/managed_system_prompt_template_{en,zh}.yamlbackend/utils/context_utils.pytime_strparam and "Current time" line from_format_app_context,build_skeleton_header_component,build_context_components,build_app_context_string; remove unuseddatetimeimportbackend/agents/create_agent_info.pytimefromrender_kwargsandbuild_context_componentscall; removedatetimeimportsdk/nexent/core/agents/core_agent.pyrun(), prepend[Current time: …]toself.taskso the timestamp travels with the user messagetest/backend/utils/test_context_utils.pytime_str=from 3 test casesWhy
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).
Notes
user_id; this PR only removestimeand does not adduser_idto EN, preserving the existing EN/ZH asymmetry (can be addressed in a follow-up PR).skill_creation_agentuses an independent prompt and is unaffected.prompt_template["system_prompt"]Jinja rendering is now fully deterministic, enabling a(agent_id, tenant_id, version_no, language)-level cache increate_agent_configfor further CPU savings.