Prebuilt Agents in LangGraph: Classes or Functions? #4390
Replies: 7 comments 3 replies
-
+1 for functions! If we are building prebuilts that are meaningfully reliant on implementation details of other prebuilts, that seems like a code smell to me and has the potential to get us into inheritance trouble (we learned this the hard way with If a prebuilt builds on top of previous prebuilts, we can do it via composition (like https://github.com/langchain-ai/langgraph-reflection) and just enforce that the externally facing inputs and outputs are as expected. If certain patterns and architectures become very common (like if there were now many different flavors of ReAct agent) and there are specific things we need to do with them outside of just tl;dr, IMO subclassing prebuilts or adding other prebuilt specific methods is an anti-pattern right now. In terms of how we'd use them, Open to concrete counterexamples of how classes would make our lives easier in ways composition wouldn't though. |
Beta Was this translation helpful? Give feedback.
-
One problem I had with create_react_agent especially on early stages, was the ability to extend. Most of the small things, that could be done with simple override, were requiring exploding it to manual reimplementation of the graph. |
Beta Was this translation helpful? Give feedback.
-
Por que no los dos? That is, an |
Beta Was this translation helpful? Give feedback.
-
+1 For functional approach, it will be lighter, easier, and quicker for implementation. |
Beta Was this translation helpful? Give feedback.
-
+1 For Functions just based on my gut as an Software Engineer. I do have experience with create_react_agent but I ended up creating my own (using the underlying code as inspiration) because I had the desire to add an LLM judge/evaluator that works hand in hand with the main agent in the react design. The evaluator would double check the main agent's process and ensure they were taking the right steps. I could not extend the original react agent to do this out of the box but I was able to create my own version using the code behind the scenes. If anything leveraging the code behind the function helped me learn the components that allow you to customize your graph. I know there is a reflection graph but thought it would be fun to build my own react function. |
Beta Was this translation helpful? Give feedback.
-
+1 for classes
Classes have constructors which also have arguments. So classes are as simple as function as it comes to concise customization IMO.
Again, the same API boundaries are for constructor's parameters. I don't see how function have an edge here. Arguments for classes:
|
Beta Was this translation helpful? Give feedback.
-
My own personal experience was using create_react_agent for a quick prototype used to evaluate the agentic approach on the use case at my company, assuming that we will have to customize a lot of stuff when wanting it to level up to a real product. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In
langgraph
, we offer a prebuilt agent constructorcreate_react_agent
, available inlanggraph.prebuilt
.The goal of abstractions in our
prebuilt
module is to make it as easy as possible to get started with an agent that has access to (dynamic) tools, prompts, etc.Usage looks something like:
We’re currently debating whether or not we should continue down this functional route, or if we should use an object oriented approach, something like:
We’re looking for feedback on the interface that you, as a
langgraph
user would prefer. Here’s a few bullets on the strengths of each approach:Function Based Approach
Class Based Approach
Agent
subclass you can further customizepartial
😵💫Excited to hear thoughts from folks as we gear up for a major sprint on prebuilt functionality!
Beta Was this translation helpful? Give feedback.
All reactions