Open Arron-Clague opened 4 days ago
To modify the CSV Agent in version 1.0.6 to pass the parameter to allow dangerous code to the langchain component, you can update the build
method in the CSVAgentComponent
class to include the allow_dangerous_code
parameter. Here is the suggested code change:
from langchain_experimental.agents.agent_toolkits.csv.base import create_csv_agent
from langflow import CustomComponent
from langflow.field_typing import BaseLanguageModel, AgentExecutor
class CSVAgentComponent(CustomComponent):
display_name = "CSVAgent"
description = "Construct a CSV agent from a CSV and tools."
documentation = "https://python.langchain.com/docs/modules/agents/toolkits/csv"
def build_config(self):
return {
"llm": {"display_name": "LLM", "type": BaseLanguageModel},
"path": {"display_name": "Path", "field_type": "file", "suffixes": [".csv"], "file_types": [".csv"]},
"handle_parsing_errors": {"display_name": "Handle Parse Errors", "advanced": True},
"agent_type": {
"display_name": "Agent Type",
"options": ["zero-shot-react-description", "openai-functions", "openai-tools"],
"advanced": True,
},
"allow_dangerous_code": {"display_name": "Allow Dangerous Code", "advanced": True, "type": "boolean"},
}
def build(
self, llm: BaseLanguageModel, path: str, handle_parsing_errors: bool = True, agent_type: str = "openai-tools", allow_dangerous_code: bool = False
) -> AgentExecutor:
# Instantiate and return the CSV agent class with the provided llm and path
return create_csv_agent(
llm=llm,
path=path,
agent_type=agent_type,
verbose=True,
agent_executor_kwargs=dict(handle_parsing_errors=handle_parsing_errors, allow_dangerous_code=allow_dangerous_code),
)
This change adds the allow_dangerous_code
parameter to the build_config
method and includes it in the build
method, passing it to the create_csv_agent
function [1][2][3].
To continue talking to Dosu, mention @dosu.
CSV Agent does not pass parameter to allow dangerous code to langchain component, and throws an error.
Suggested change to CSV Component :
from langchain_experimental.agents.agent_toolkits.csv.base import create_csv_agent
from langflow.custom import CustomComponent from langflow.field_typing import AgentExecutor, LanguageModel
class CSVAgentComponent(CustomComponent): display_name = "CSVAgent" description = "Construct a CSV agent from a CSV and tools - ADC." documentation = "https://python.langchain.com/docs/modules/agents/toolkits/csv"