HANAMLAgentWithMemory

class hana_ai.agents.hanaml_agent_with_memory.HANAMLAgentWithMemory(llm, tools, session_id='hanaai_chat_session', n_messages=10, max_observations=5, verbose=False, **kwargs)

A chatbot that can remember the chat history and use it to generate responses.

Parameters:
llmLLM

The language model to use.

toolslist of BaseTool

The tools to use.

session_idstr, optional

The session ID to use. Default to "hana_ai_chat_session".

n_messagesint, optional

The number of messages to remember. Default to 10.

max_observationsint, optional

The maximum number of observations to remember. Default to 5.

verbosebool, optional

Whether to be verbose. Default to False.

Methods

add_ai_message(content)

Add a response from the AI to the chat history.

add_user_message(content)

Add a message from the user to the chat history.

delete_chat_history_tool([_input])

Delete chat history tool.

run(question)

Chat with the chatbot.

set_return_direct(config)

Set the return_direct flag for a specific tool.

Examples

Assume cc is a connection to a SAP HANA instance:

>>> from hana_ai.agents.hanaml_agent_with_memory import HANAMLAgentWithMemory
>>> from hana_ai.tools.toolkit import HANAMLToolkit
>>> tools = HANAMLToolkit(connection_context=cc, used_tools='all').get_tools()
>>> chatbot = HANAMLAgentWithMemory(llm=llm, tools=tools, session_id='hana_ai_test', n_messages=10)
>>> chatbot.run(question="Analyze the data from the table MYTEST.")
add_user_message(content: str)

Add a message from the user to the chat history.

add_ai_message(content: str)

Add a response from the AI to the chat history.

set_return_direct(config: dict)

Set the return_direct flag for a specific tool.

Parameters:
configdict

A dictionary containing the tool name and the return_direct flag. Example: {"fetch_data": True}

delete_chat_history_tool(_input='')

Delete chat history tool.

run(question)

Chat with the chatbot.

Parameters:
questionstr

The question to ask.