You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added a very descriptive title to this question.
I searched the LangChain documentation with the integrated search.
I used the GitHub search to find a similar question and didn't find it.
Commit to Help
I commit to help with one of those options 👆
Example Code
importjsonfrompydanticimportBaseModelfromlangchain.agentsimportcreate_tool_calling_agentfromlangchain_core.promptsimportChatPromptTemplate, MessagesPlaceholderfromlangchain.agentsimportAgentExecutorfromlangchain_core.promptsimportChatPromptTemplate, MessagesPlaceholderfromlangchain_experimental.toolsimportPythonAstREPLToolfromlangchain.agentsimportAgentExecutor, OpenAIFunctionsAgentfromlangchain_core.promptsimportChatPromptTemplate, MessagesPlaceholderfromlangchain_experimental.toolsimportPythonAstREPLToolfromlangchain.agentsimportAgentExecutor, OpenAIFunctionsAgentfrompydanticimportBaseModel, Field, model_validatorfromlangchain_core.toolsimportBaseToolfromlangchain_core.promptsimportChatPromptTemplate, MessagesPlaceholderimportastimportreimportsysfromcontextlibimportredirect_stdoutfromioimportStringIOfromtypingimportAny, Dict, Optional, Typefromlangchain_core.callbacks.managerimport (
AsyncCallbackManagerForToolRun,
CallbackManagerForToolRun,
)
fromlangchain_core.runnables.configimportrun_in_executorfromlangchain_core.toolsimportBaseToolfrompydanticimportBaseModel, Field, model_validatorfromlangchain_experimental.utilities.pythonimportPythonREPLclassPythonInputs(BaseModel):
"""Python inputs."""query: str=Field(description="code snippet to run")
template="""You are working with a pandas dataframe in Python. The name of the dataframe is `df`.\n"It is important to understand the attributes of the dataframe before working with it. This is the result of running `df.head().to_markdown()`.\n"<df>{dhead}</df>You are not meant to use only these rows to answer questions - they are meant as a way of telling you about the shape and schema of the dataframe.You also do not have use only the information here to answer questions - you can run intermediate queries to do exploratory data analysis to give you more information as needed.Convert your curiosity or questions into executable Python code using Pandas to learn as needed."""# noqa: E501template=template.format(dhead=df.head().to_markdown())
# Define the promptprompt=ChatPromptTemplate.from_messages(
[
("system", template),
MessagesPlaceholder(variable_name="agent_scratchpad"),
("human", "{input}"),
MessagesPlaceholder("chat_history", optional=True),
]
)
repl=PythonAstREPLTool( ##### This is the function brining df in to the agent_executorlocals={"df": df},
name="python_repl",
description="A Python shell. Use this to execute python commands. Input should be a valid python command. When using this tool, sometimes output is abbreviated - make sure it does not look abbreviated before using it in your answer.",
args_schema=PythonInputs,
prompt=prompt,
)
tools= [repl]
agent=create_openai_functions_agent(
llm=llm, prompt=prompt, tools=tools
)
agent_executor=AgentExecutor(
agent=agent,
tools=tools,
max_iterations=10,
early_stopping_method="force", ##### Changed from generate due to Generate error.allow_dangerous_code=True,
allow_dangerous_requests=True,
) | (lambdax: x["output"])
# Typing for playground inputsclassAgentInputs(BaseModel):
input: stragent_executor=agent_executor.with_types(input_type=AgentInputs)
# Define the workflowoutput_query_str="Top 5 brands by total BVs"defprocess_input(input_data):
messages=agent_executor.invoke({"input":output_query_str})
returnmessagesinput_data=output_query_stroutput=process_input(input_data)
print(output)
Description
There is a lot of information available, but it's unclear how to proceed with the migration when using a pandas DataFrame in Langchain to achieve the same results in LangGraph. Any thoughts? Above my code works perfect in Langchain. Why I need LangGraph if no path is defined? These are real life stuctured data RAG in real corporations. No path, no Go to production :-(
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Checked other resources
Commit to Help
Example Code
Description
There is a lot of information available, but it's unclear how to proceed with the migration when using a pandas DataFrame in Langchain to achieve the same results in LangGraph. Any thoughts? Above my code works perfect in Langchain. Why I need LangGraph if no path is defined? These are real life stuctured data RAG in real corporations. No path, no Go to production :-(
System Info
Name: langchain
Version: 0.3.2
Name: langgraph
Version: 0.2.34
Beta Was this translation helpful? Give feedback.
All reactions