Skip to content

Conversation

@christian-bromann
Copy link
Member

If someone tries to run a createAgent with LangGraph, it will fail due to the fact that createAgent wraps the LangGraph graph instance to provide better type security.

Rather then documenting that users can just do this:

const agent = createAgent(...)
export const graph = agent.graph

This patch makes the createAgent function return a proxy that directs access to graph properties to the right object. For the user this is totally transparent.

@changeset-bot
Copy link

changeset-bot bot commented Sep 20, 2025

⚠️ No Changeset found

Latest commit: 1c23be9

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

@vercel
Copy link

vercel bot commented Sep 20, 2025

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

Project Deployment Preview Comments Updated (UTC)
langchainjs-docs Ready Ready Preview Comment Sep 20, 2025 1:30am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchainjs-api-refs Ignored Ignored Sep 20, 2025 1:30am

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.

I'm partial to amending LGP to look for some kind of symbol that returns a graph instead of returning a proxy. I'm generally not a fan of using proxy objects since there's a lot of ways to shoot yourself in the foot

Comment on lines +410 to +433
return new Proxy(agent, {
get(target, prop) {
/**
* access graph properties if not a `createAgent` function
*/
if (
!agentMethodNames.has(prop as string) &&
target.graph[prop as keyof typeof target.graph]
) {
const value = target.graph[prop as keyof typeof target.graph];
return typeof value === "function" ? value.bind(target.graph) : value;
}

const value =
target[
prop as keyof ReactAgent<
StructuredResponseFormat,
ContextSchema,
TMiddleware
>
];
return typeof value === "function" ? value.bind(target) : value;
},
});
Copy link
Member

Choose a reason for hiding this comment

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

do we foresee any collisions between ReactAgent properties and CompiledStateGraph?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is why have a !agentMethodNames.has(prop as string) check to ensure the methods we expose from ReactAgent will be called in favor of what StateGraph exposes.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm so in that hypothetical case ReactAgent would only partially implement state graph?

Copy link
Member Author

Choose a reason for hiding this comment

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

If a function like invoke or stream is implemented in ReactAgent is will prefer that over the one implemented in state graph. With the proxy it will still reach into state graph for methods not implemented in ReactAgent which will guarantee the support for LGP.

@christian-bromann
Copy link
Member Author

Closing in favor of #9117

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.

3 participants