Replies: 2 comments 6 replies
-
@FreddyWordingham - this will be up your street! |
Beta Was this translation helpful? Give feedback.
-
3/ - no, the runnable should be either in the global space or initialized inside
1/ is a big longer of a response. TLDR is that we're still thinking about a recomended way to handle. But regardless of what we recommend, you should be able to do it as you described. For (a) you will want to create and bind tools inside a node, eg:
For (b), you will want to NOT use the ToolNode (as that is a simple node that does not support this) and youll want to do the invocation your self |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Transitioning from LangChain to LangGraph. Very impressed with the new library for stateful implementations of agentic systems.
This discussion is to develop a mapping between libraries for the example of re-implementing the
create_pandas_dataframe_agent
in LangGraph. This is a ReAct agent which uses thePythonREPLTool
. There are a few subtleties that I'd like to raise to the developers, so to follow the principles of the library. I'm happy to contribute the implementation as an example notebook once resolved.This post is meant for pedagogy, to assist the transition from LangChain to LangGraph. If there is reference content that answers these points, please forward in comments. Any engagement appreciated.
Rough implementation:
Following the
creat_react_agent
as a template.Uses a basic state:
Here are my queries:
Passing a
pd.DataFrame
object to thestate
. Does this fit the LangGraph principles, or is it intended that thestate
should only contain message-type objects. Currently, the tool is fixed at the creation of the nodes withpython workflow.add_node('python_executor', ToolNode([PythonAstREPLTool(locals={'df': df}),]))
Here I propose adding a field to the state graphstate["df"] = [df,]
at the input. Then I would like to be able to(a) Pass
state["df"]
to theToolExecutor
when the node is visited. This would possibly mean instantiating aPythonAstREPLTool
, in which case it is unclear how to bind the tool to the llm at the startllm.bin_tools()
.(b) Allow the tool to update
state["df"]
, say when ammending adf
. A question here is, would a seconddf2
be added to a liststate["df"] = [df, df2]
, and how can the tool be instructed to do so.I would like to be able to replicate the following prompt:
from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS
. The takes the following form:Currently, I supply
tool_names
at the creation of the node where I callHowever, I would like to be able to parse variables to the prompt from the state, so I could update
agent_scratchpad
properly. How is this executed?Can one pass items such as the
runnable
in the node function arguments, likeso that
workflow.add_node('generate_code', generation_node)
still still has access to runnable in its name space?Once again, any comments/thoughts appreciated.
Beta Was this translation helpful? Give feedback.
All reactions