Skip to content

Conversation

@carefreelife98
Copy link

Summary

Agent creation often requires toggling multiple middleware components (todo list, human-in-the-loop, prompt caching, etc.) based on runtime conditions. Today every caller must import each factory and manually push them into arrays, which leads to duplicated logic and error-prone configuration handling.

Proposal

  1. Expose a centralized factory enum (BuiltInAgentMiddleware) plus createBuiltInAgentMiddleware so callers can request middleware by name.
  2. Provide a lightweight AgentMiddlewareBuilder that accepts descriptors { name, config, when } and returns the assembled array, mirroring the builder used in Mate-X.
  3. Update docs/examples to illustrate building agent middleware stacks with conditional guards.
  4. Add unit tests ensuring the builder respects when flags and that factory entries require the correct config shape.

Motivation

  • Improves ergonomics for teams composing agents with many optional behaviors.
  • Avoids repeated imports and misconfiguration (e.g. missing retry configs).
  • Gives us a single extension point when introducing new built-in middleware.

@changeset-bot
Copy link

changeset-bot bot commented Nov 21, 2025

⚠️ No Changeset found

Latest commit: 5318b65

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant