[PR #573] fix(deepagents): replace same-name middleware in createDeepAgent #573

Open
opened 2026-06-05 17:23:48 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/573
Author: @hntrl
Created: 6/2/2026
Status: 🔄 Open

Base: mainHead: hunter/middleware-replace-by-name


📝 Commits (1)

  • 1decaab fix(deepagents): replace same-name middleware in createDeepAgent

📊 Changes

4 files changed (+176 additions, -19 deletions)

View changed files

.changeset/hunter-middleware-replace-by-name.md (+8 -0)
📝 libs/deepagents/src/agent.test.ts (+138 -1)
📝 libs/deepagents/src/agent.ts (+29 -17)
📝 libs/deepagents/src/profiles/harness/merge.ts (+1 -1)

📄 Description

Summary

createDeepAgent now merges user-provided middleware into the assembled middleware stack by .name, replacing matching entries in place instead of appending duplicates. This gives users a direct path to override built-in middleware configuration (such as summarization) without introducing duplicate triggers. The same replacement behavior now applies to declarative subagent middleware stacks.

Changes

libs/deepagents/src/agent.ts

  • Reused shared middleware merge semantics when composing the root middleware stack, so matching middleware names replace existing entries at their current position.
  • Applied the same merge-by-name behavior to declarative subagent middleware assembly before cache middleware is appended.
  • Preserved existing stack ordering guarantees while preventing duplicate named middleware.

libs/deepagents/src/profiles/harness/merge.ts

  • Exported mergeMiddleware so the same merge-by-name logic can be reused by createDeepAgent.

libs/deepagents/src/agent.test.ts

  • Added coverage for root middleware replacement by name and declarative subagent middleware replacement by name.
  • Asserted both de-duplication (SummarizationMiddleware appears once) and ordering behavior.

.changeset/hunter-middleware-replace-by-name.md

  • Added a patch changeset for deepagents describing the middleware replacement behavior.

🔄 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/573 **Author:** [@hntrl](https://github.com/hntrl) **Created:** 6/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `hunter/middleware-replace-by-name` --- ### 📝 Commits (1) - [`1decaab`](https://github.com/langchain-ai/deepagentsjs/commit/1decaab37e4a76d4eb3d14c12c4f12d8f1c57feb) fix(deepagents): replace same-name middleware in createDeepAgent ### 📊 Changes **4 files changed** (+176 additions, -19 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/hunter-middleware-replace-by-name.md` (+8 -0) 📝 `libs/deepagents/src/agent.test.ts` (+138 -1) 📝 `libs/deepagents/src/agent.ts` (+29 -17) 📝 `libs/deepagents/src/profiles/harness/merge.ts` (+1 -1) </details> ### 📄 Description ## Summary `createDeepAgent` now merges user-provided middleware into the assembled middleware stack by `.name`, replacing matching entries in place instead of appending duplicates. This gives users a direct path to override built-in middleware configuration (such as summarization) without introducing duplicate triggers. The same replacement behavior now applies to declarative subagent middleware stacks. ## Changes ### `libs/deepagents/src/agent.ts` - Reused shared middleware merge semantics when composing the root middleware stack, so matching middleware names replace existing entries at their current position. - Applied the same merge-by-name behavior to declarative subagent middleware assembly before cache middleware is appended. - Preserved existing stack ordering guarantees while preventing duplicate named middleware. ### `libs/deepagents/src/profiles/harness/merge.ts` - Exported `mergeMiddleware` so the same merge-by-name logic can be reused by `createDeepAgent`. ### `libs/deepagents/src/agent.test.ts` - Added coverage for root middleware replacement by name and declarative subagent middleware replacement by name. - Asserted both de-duplication (`SummarizationMiddleware` appears once) and ordering behavior. ### `.changeset/hunter-middleware-replace-by-name.md` - Added a patch changeset for `deepagents` describing the middleware replacement behavior. --- <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:23:48 -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#573