-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(langchain/agent): re-enable support for LangGraph #9016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
There was a problem hiding this 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
| 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; | ||
| }, | ||
| }); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
Closing in favor of #9117 |
If someone tries to run a
createAgentwith LangGraph, it will fail due to the fact thatcreateAgentwraps the LangGraph graph instance to provide better type security.Rather then documenting that users can just do this:
This patch makes the
createAgentfunction return a proxy that directs access to graph properties to the right object. For the user this is totally transparent.