Skip to content

Conversation

christian-bromann
Copy link
Member

This allows to create middleware without depending on langchain or @langchain/langgraph.

Copy link

changeset-bot bot commented Oct 14, 2025

⚠️ No Changeset found

Latest commit: f585e8b

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.

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

Copy link

vercel bot commented Oct 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
langchainjs-api-refs Ignored Ignored Oct 14, 2025 9:54pm
langchainjs-docs Ignored Ignored Oct 14, 2025 9:54pm

Copy link
Member

@hntrl hntrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for posterity: I think it's worth exploring how we can make the middleware types in core more generic. We're indirectly introducing langgraph primitives (e.g. we are name dropping Command in core middleware, but filling that type information in only if we import createMiddleware from langchain. It wires us in sort of an awkward way, but this is better than working against circular dependency errors.

Probably best to mark all of these in core as @internal so they're hidden in references, and then have a type alias which is where the jsdocs live.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is just invalidating the point of dep tests. Fine to either disable for this pass, but I think the fix for the latest tests is to allow for pre-release versions if thats what's in dependencies (since we're just pnpm add @langchain/core'ing within the script)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, ideally we need to be able to push dev releases from branches and then adjust the peer dep in langchain.

Comment on lines +281 to +298
Runtime<
TContextSchema extends InteropZodObject
? InferInteropZodOutput<TContextSchema>
: TContextSchema extends InteropZodDefault<any>
? InferInteropZodOutput<TContextSchema>
: TContextSchema extends InteropZodOptional<any>
? Partial<InferInteropZodOutput<TContextSchema>>
: never
>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to dedupe the TContextSchema extends InteropZodObject... closures into a utility type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do in a separate PR.

Comment on lines +21 to +29
/**
* Cast the promptCachingMiddleware to `any` to avoid the following error:
* > Type instantiation is excessively deep and possibly infinite.
*
* This is because the actual `promptCachingMiddleware` is implemented within
* the `@langchain/anthropic` package and tesed in here. To avoid circular dependencies,
* we have to run the unit and integration tests here as we need `createAgent`.
*/
const anthropicPromptCachingMiddleware = promptCachingMiddleware as any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is surprising to me actually. Can get that rolldown is detecting circular dependencies, but typescript is throwing errors like this also? My intuition would be that there's no circular type trees since anthropic is only a dev dependency

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For TypeScript it seems to not matter if it is a dev, optional or peer dependency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these prompt caching tests just be living inside of @langchain/anthropic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally yes, but they use createAgent which lives in langchain so we are having the same problem. This brings me back of saying: let's collapse all into one langchain package.

@christian-bromann christian-bromann marked this pull request as draft October 14, 2025 21:58
@christian-bromann
Copy link
Member Author

Moving back to draft due to:

examples:build: src/createAgent/middleware/promptCaching.ts:13:16 - error TS2589: Type instantiation is excessively deep and possibly infinite.
examples:build: 
examples:build: 13   middleware: [promptCachingMiddleware({ ttl: "5m" }) as AgentMiddleware],
examples:build:                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examples:build: 

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.

2 participants