📌 fix: Stabilize Agent Prompt Cache Prefix - #12907
Conversation
GitNexus: 🚀 deployedThe |
There was a problem hiding this comment.
Pull request overview
This PR stabilizes the cacheable “system prompt prefix” for agent runs by keeping agent/tool instructions static while shifting volatile per-turn context (memory/RAG/file context, runtime timestamps, etc.) into additional_instructions, anchored to the conversation’s creation time.
Changes:
- Anchors date/time special-variable resolution to a persisted conversation creation timestamp (captured server-side and reused across turns).
- Splits
web_searchcontext into a static instruction block and a dynamic runtime block built from the anchored conversation time. - Refactors agent instruction composition to keep stable instructions separate from dynamic “system tail”, and bumps
@librechat/agentsto3.1.75.
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/data-schemas/src/methods/conversation.ts | Adds createdAtOnInsert support to persist a stable conversation createdAt during first upsert. |
| packages/data-schemas/src/methods/conversation.spec.ts | Tests createdAtOnInsert is applied only on insert and not overwritten on updates. |
| packages/data-provider/src/parsers.ts | Extends replaceSpecialVars with optional now anchor + whitespace-tolerant placeholders. |
| packages/data-provider/specs/parsers.spec.ts | Adds tests for anchored time replacement and whitespace in placeholders. |
| packages/api/src/types/http.ts | Adds conversationCreatedAt to request typing for timestamp anchoring. |
| packages/api/src/tools/toolkits/web.ts | Splits web search context into static + buildWebSearchDynamicContext(now) runtime block. |
| packages/api/src/tools/toolkits/web.spec.ts | Verifies static context has no volatile substitutions; dynamic context is deterministic by anchor. |
| packages/api/src/agents/run.ts | Separates stable tool/agent instructions vs dynamic tail via dynamicToolContextMap and additional_instructions. |
| packages/api/src/agents/initialize.ts | Anchors temporal special vars to req.conversationCreatedAt and classifies temporal instructions as dynamic. |
| packages/api/src/agents/context.ts | Splits stable instructions (instructions) from dynamic runtime context (additional_instructions). |
| packages/api/src/agents/context.spec.ts | Updates/extends tests for stable vs dynamic instruction composition. |
| packages/api/src/agents/tests/run-summarization.test.ts | Adds regression test ensuring stable and dynamic instruction fields remain separated. |
| packages/api/src/agents/tests/initialize.test.ts | Tests temporal vars move to dynamic tail and anchor is applied. |
| packages/api/package.json | Bumps @librechat/agents to ^3.1.75. |
| api/server/services/ToolService.js | Produces both toolContextMap (static) and dynamicToolContextMap (anchored runtime) for tools. |
| api/server/controllers/agents/request.js | Resolves and attaches req.conversationCreatedAt (new vs existing convo) for prompt anchoring. |
| api/server/controllers/agents/client.js | Preserves stable/dynamic instruction fields when applying shared run context. |
| api/server/controllers/agents/client.test.js | Updates expectations: memory context now lives in additional_instructions rather than stable instructions. |
| api/app/clients/tools/util/handleTools.js | Adds dynamicToolContextMap output and anchors dynamic web search context from request. |
| api/app/clients/BaseClient.js | Persists anchored createdAt on first conversation insert via createdAtOnInsert. |
| api/package.json | Bumps @librechat/agents to ^3.1.75. |
| package-lock.json | Locks @librechat/agents to 3.1.75. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…-cache-stable-prefix # Conflicts: # api/server/controllers/agents/client.js # api/server/controllers/agents/client.test.js
GitNexus: 🚀 deployedThe |
GitNexus: 🚀 deployedThe |
GitNexus: 🚀 deployedThe |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e947099d1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
GitNexus: 🚀 deployedThe |
|
@codex review |
GitNexus: 🚀 deployedThe |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6905776dc6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
GitNexus: 🚀 deployedThe |
|
Codex Review: Didn't find any major issues. Hooray! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
* fix: stabilize agent prompt cache prefix * chore: refresh agents sdk lockfile integrity * test: format agent memory assertion * test: type agent context fixtures * fix: preserve MCP instruction precedence * fix: reuse resolved conversation anchor * fix: keep resumable startup immediate
* fix: stabilize agent prompt cache prefix * chore: refresh agents sdk lockfile integrity * test: format agent memory assertion * test: type agent context fixtures * fix: preserve MCP instruction precedence * fix: reuse resolved conversation anchor * fix: keep resumable startup immediate
* fix: stabilize agent prompt cache prefix * chore: refresh agents sdk lockfile integrity * test: format agent memory assertion * test: type agent context fixtures * fix: preserve MCP instruction precedence * fix: reuse resolved conversation anchor * fix: keep resumable startup immediate
Summary
Fixes #12634
Depends on LibreChat-AI/agents#128
Tests
Note: packages/api build passed with the existing Redis type warning in src/cache/cacheFactory.ts.