Skip to content

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

Draft
Hunter Lovell (hntrl) wants to merge 1 commit into
mainfrom
hunter/middleware-replace-by-name
Draft

fix(deepagents): replace same-name middleware in createDeepAgent#573
Hunter Lovell (hntrl) wants to merge 1 commit into
mainfrom
hunter/middleware-replace-by-name

Conversation

@hntrl

Copy link
Copy Markdown
Member

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.

@changeset-bot

changeset-bot Bot commented Jun 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1decaab

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
deepagents Patch
deepagents-acp Patch
@deepagents/evals Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

1 participant