create_spark_sql_agent#
- langchain_community.agent_toolkits.spark_sql.base.create_spark_sql_agent(llm: BaseLanguageModel, toolkit: SparkSQLToolkit, callback_manager: BaseCallbackManager | None = None, callbacks: Callbacks = None, prefix: str = 'You are an agent designed to interact with Spark SQL.\nGiven an input question, create a syntactically correct Spark SQL query to run, then look at the results of the query and return the answer.\nUnless the user specifies a specific number of examples they wish to obtain, always limit your query to at most {top_k} results.\nYou can order the results by a relevant column to return the most interesting examples in the database.\nNever query for all the columns from a specific table, only ask for the relevant columns given the question.\nYou have access to tools for interacting with the database.\nOnly use the below tools. Only use the information returned by the below tools to construct your final answer.\nYou MUST double check your query before executing it. If you get an error while executing a query, rewrite the query and try again.\n\nDO NOT make any DML statements (INSERT, UPDATE, DELETE, DROP etc.) to the database.\n\nIf the question does not seem related to the database, just return "I don\'t know" as the answer.\n', suffix: str = 'Begin!\n\nQuestion: {input}\nThought: I should look at the tables in the database to see what I can query.\n{agent_scratchpad}', format_instructions: str | None = None, input_variables: List[str] | None = None, top_k: int = 10, max_iterations: int | None = 15, max_execution_time: float | None = None, early_stopping_method: str = 'force', verbose: bool = False, agent_executor_kwargs: Dict[str, Any] | None = None, **kwargs: Any) AgentExecutor [source]#
Construct a Spark SQL agent from an LLM and tools.
- Parameters:
llm (BaseLanguageModel) β The language model to use.
toolkit (SparkSQLToolkit) β The Spark SQL toolkit.
callback_manager (Optional[BaseCallbackManager]) β Optional. The callback manager. Default is None.
callbacks (Callbacks) β Optional. The callbacks. Default is None.
prefix (str) β Optional. The prefix for the prompt. Default is SQL_PREFIX.
suffix (str) β Optional. The suffix for the prompt. Default is SQL_SUFFIX.
format_instructions (Optional[str]) β Optional. The format instructions for the prompt. Default is None.
input_variables (Optional[List[str]]) β Optional. The input variables for the prompt. Default is None.
top_k (int) β Optional. The top k for the prompt. Default is 10.
max_iterations (Optional[int]) β Optional. The maximum iterations to run. Default is 15.
max_execution_time (Optional[float]) β Optional. The maximum execution time. Default is None.
early_stopping_method (str) β Optional. The early stopping method. Default is βforceβ.
verbose (bool) β Optional. Whether to print verbose output. Default is False.
agent_executor_kwargs (Optional[Dict[str, Any]]) β Optional. The agent executor kwargs. Default is None.
kwargs (Any) β Any. Additional keyword arguments.
- Returns:
The agent executor.
- Return type:
Examples using create_spark_sql_agent