-
Checked other resources
Commit to Help
Example CodeHere my agent executor is using python repl.
# Define the prompt
prompt = ChatPromptTemplate.from_messages(
[
("system", template),
MessagesPlaceholder(variable_name="agent_scratchpad"),
("human", "{input}"),
MessagesPlaceholder("chat_history", optional=True),
]
)
repl = PythonAstREPLTool(
locals={"df": df},
name="python_repl",
description="Runs Python code and returns the output of the final line",
args_schema=PythonInputs,
prompt = prompt,
)
tools = [repl, retriever_tool]
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,
) | (lambda x: x["output"]) DescriptionSimilar to this post #9591, is it possible to train my agent_executor who is using python repl (datafram qery)? I like to train on my dataset columns and data before asking a question. System InfoName: langchain |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Yes, it is possible to train your Here is the relevant part of the code: repl = PythonAstREPLTool(
locals={"df": df},
name="python_repl",
description="Runs code and returns the output of the final line",
args_schema=PythonInputs,
)
tools = [repl, retriever_tool]
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",
allow_dangerous_code=True, allow_dangerous_requests=True
) | (lambda x: x["output"]) This setup allows the Additionally, the LangChain framework provides a comprehensive setup for integrating various tools, including a Python REPL, with language models. The Here is an example of how to set up the Python REPL tool using LangChain: from langchain.agents import Tool
from langchain_experimental.utilities import PythonREPL
python_repl = PythonREPL()
repl_tool = Tool(
name="python_repl",
description="A Python shell. Use this to execute python commands. Input should be a valid python command. If you want to see the output of a value, you should print it out with `print(...)`.",
func=python_repl.run,
) This setup allows you to execute Python commands interactively, making it easier to explore and manipulate your dataset before querying. For more advanced use cases and flexibility, LangChain also offers other tools and agents, such as LangGraph Agents, which provide more control and customization options. You can refer to the LangChain documentation for more details on setting up and using these advanced agents [1][2][3]. |
Beta Was this translation helpful? Give feedback.
-
@dosu How I use query function after training? after your comment |
Beta Was this translation helpful? Give feedback.
-
@dosu Thank you. One last question... what is the difference between what I used below for python repl vs. what you suggested?
Your suggestion:
|
Beta Was this translation helpful? Give feedback.
The key differences between
PythonAstREPLTool
andPythonREPL
are in their capabilities and limitations:PythonAstREPLTool
:`
) and triple backticks (```
).1 + 1
returns2
).IndexError
,KeyError
).PythonREPL
: