[PR #331] [MERGED] fix(deepagents): reorder middleware so prompt caching and memory run last #365

Closed
opened 2026-06-05 17:22:49 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/331
Author: @hntrl
Created: 3/19/2026
Status: Merged
Merged: 3/20/2026
Merged by: @hntrl

Base: mainHead: hunter/middleware-reorder


📝 Commits (2)

  • fa7ba5d fix(deepagents): reorder middleware so prompt caching and memory run last
  • 775562f cr

📊 Changes

2 files changed (+35 additions, -19 deletions)

View changed files

.changeset/middleware-reorder.md (+7 -0)
📝 libs/deepagents/src/agent.ts (+28 -19)

📄 Description

Summary

Port of https://github.com/langchain-ai/deepagents/pull/2070 to JS.

  • Move anthropicPromptCachingMiddleware and memoryMiddleware after all static and user-supplied middleware
  • Ensures updates to memory contents do not invalidate Anthropic prompt caches

System message ordering becomes:

base prompt
todos
skills
filesystem
task
(any user-supplied / custom middleware)
<cache point> <---
memory contents and guidelines

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/deepagentsjs/pull/331 **Author:** [@hntrl](https://github.com/hntrl) **Created:** 3/19/2026 **Status:** ✅ Merged **Merged:** 3/20/2026 **Merged by:** [@hntrl](https://github.com/hntrl) **Base:** `main` ← **Head:** `hunter/middleware-reorder` --- ### 📝 Commits (2) - [`fa7ba5d`](https://github.com/langchain-ai/deepagentsjs/commit/fa7ba5dfc85234c8548c707d14f9d4cc3678107f) fix(deepagents): reorder middleware so prompt caching and memory run last - [`775562f`](https://github.com/langchain-ai/deepagentsjs/commit/775562fa7d9194b7eeae809291b4253a51ef5123) cr ### 📊 Changes **2 files changed** (+35 additions, -19 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/middleware-reorder.md` (+7 -0) 📝 `libs/deepagents/src/agent.ts` (+28 -19) </details> ### 📄 Description ## Summary Port of https://github.com/langchain-ai/deepagents/pull/2070 to JS. - Move `anthropicPromptCachingMiddleware` and `memoryMiddleware` after all static and user-supplied middleware - Ensures updates to memory contents do not invalidate Anthropic prompt caches System message ordering becomes: ``` base prompt todos skills filesystem task (any user-supplied / custom middleware) <cache point> <--- memory contents and guidelines ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 17:22:49 -04:00
yindo closed this issue 2026-06-05 17:22:49 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#365