create_hana_dataframe_agent

hana_ai.agents.hana_dataframe_agent.create_hana_dataframe_agent(llm: BaseLLM, df: Any, tools: List[BaseTool] = None, callback_manager: BaseCallbackManager | None = None, prefix: str = "\nYou are working with a HANA dataframe in Python that is similar to Spark dataframe. The name of the dataframe is `df`. `connection_context` is `df`'s attribute. To handle connection or to use dataframe functions, you should use python_repl_ast tool. In most cases, you should use CodeTemplatesFromVectorDB tool. You should use the tools below to answer the question posed of you. :", suffix: str = '\nThis is the result of `print(df.head().collect())`:\n{df}\n\nBegin!\nQuestion: {input}\n{agent_scratchpad}', input_variables: List[str] | None = None, verbose: bool = False, return_intermediate_steps: bool = False, max_iterations: int | None = 15, max_execution_time: float | None = None, early_stopping_method: str = 'force', agent_executor_kwargs: Dict[str, Any] | None = None, **kwargs: Dict[str, Any]) AgentExecutor

Construct a hana-ml agent from an LLM and dataframe.

Parameters:
llmBaseLLM

The LLM to use.

dfDataFrame

The HANA dataframe to use. It could be None.

toolsBaseTool, optional

The tools to use. Default to None.

callback_managerBaseCallbackManager, optional

The callback manager to use. Default to None.

prefixstr, optional

The prefix to use.

suffixstr, optional

The suffix to use.

input_variablesList[str], optional

The input variables to use. Default to None.

verbosebool, optional

Whether to be verbose. Default to False.

return_intermediate_stepsbool, optional

Whether to return intermediate steps. Default to False.

max_iterationsint, optional

The maximum number of iterations to use. Default to 15.

max_execution_timefloat, optional

The maximum execution time to use. Default to None.

early_stopping_methodstr, optional

The early stopping method to use. Default to "force".

agent_executor_kwargsDict[str, Any], optional

The agent executor kwargs to use. Default to None.

Examples

Assume cc is a connection to a SAP HANA instance:

>>> from hana_ai.tools.code_template_tools import GetCodeTemplateFromVectorDB
>>> from hana_ai.vectorstore.hana_vector_engine import HANAMLinVectorEngine
>>> from hana_ai.agents.hana_dataframe_agent import create_hana_dataframe_agent
>>> hana_df = cc.table("MY_DATA")
>>> hana_vec = HANAMLinVectorEngine(connection_context=cc, table_name="hana_vec_hana_ml_python_knowledge")
>>> hana_vec.create_knowledge()
>>> code_tool = GetCodeTemplateFromVectorDB()
>>> code_tool.set_vectordb(vectordb=hana_vec)
>>> agent = create_hana_dataframe_agent(llm=llm, tools=[code_tool], df=hana_df, verbose=True, handle_parsing_errors=True)
>>> agent.invoke("Create a dataset report for this dataframe.")