HANAMLToolkit

class hana_ai.tools.toolkit.HANAMLToolkit(connection_context, used_tools=None, return_direct=None)

Toolkit for interacting with HANA SQL.

Parameters:
connection_contextConnectionContext

Connection context to the HANA database.

used_toolslist, optional

List of tools to use. If None or 'all', all tools are used. Default to None.

Attributes:
model_extra

Get extra fields set during validation.

model_fields_set

Returns the set of fields that have been explicitly set on this model instance.

Methods

Config()

Configuration for this pydantic object.

add_custom_tool(tool)

Add a custom tool to the toolkit.

copy(*[, include, exclude, update, deep])

Returns a copy of the model.

delete_tool(tool_name)

Delete a tool from the toolkit.

get_tools()

Get the tools in the toolkit.

is_port_available(port)

检查端口是否可用

launch_mcp_server([server_name, version, ...])

Launch the MCP server with the specified configuration.

model_construct([_fields_set])

Creates a new instance of the Model class with validated data.

model_copy(*[, update, deep])

!!! abstract "Usage Documentation"

model_dump(*[, mode, include, exclude, ...])

!!! abstract "Usage Documentation"

model_dump_json(*[, indent, include, ...])

!!! abstract "Usage Documentation"

model_json_schema([by_alias, ref_template, ...])

Generates a JSON schema for a model class.

model_parametrized_name(params)

Compute the class name for parametrizations of generic classes.

model_post_init(context, /)

Override this method to perform additional initialization after __init__ and model_construct.

model_rebuild(*[, force, raise_errors, ...])

Try to rebuild the pydantic-core schema for the model.

model_validate(obj, *[, strict, ...])

Validate a pydantic model instance.

model_validate_json(json_data, *[, strict, ...])

!!! abstract "Usage Documentation"

model_validate_strings(obj, *[, strict, ...])

Validate the given object with string data against the Pydantic model.

set_bas([bas])

Set the BAS mode for all tools in the toolkit.

set_vectordb(vectordb)

Set the vector database.

construct

dict

json

update_forward_refs

Examples

Assume cc is a connection to a SAP HANA instance:

>>> from hana_ai.tools.toolkit import HANAMLToolkit
>>> from hana_ai.agents.hanaml_agent_with_memory import HANAMLAgentWithMemory
>>> tools = HANAMLToolkit(connection_context=cc, used_tools='all').get_tools()
>>> chatbot = HANAMLAgentWithMemory(llm=llm, toos=tools, session_id='hana_ai_test', n_messages=10)
add_custom_tool(tool: BaseTool)

Add a custom tool to the toolkit.

Parameters:
toolBaseTool

Custom tool to add.

Note

The tool must be a subclass of BaseTool. Please follow the guide to create the custom tools https://python.langchain.com/docs/how_to/custom_tools/.

delete_tool(tool_name: str)

Delete a tool from the toolkit.

Parameters:
tool_namestr

Name of the tool to delete.

set_bas(bas=True)

Set the BAS mode for all tools in the toolkit.

set_vectordb(vectordb)

Set the vector database.

Parameters:
vectordbHANAMLinVectorEngine

Vector database.

is_port_available(port: int) bool

检查端口是否可用

launch_mcp_server(server_name: str = 'HANATools', version: str = '1.0', host: str = '127.0.0.1', transport: str = 'stdio', sse_port: int = 8001, auth_token: str | None = None, max_retries: int = 5)

Launch the MCP server with the specified configuration. This method initializes the MCP server, registers all tools, and starts the server in a background thread. If the specified port is occupied, it will try the next port up to max_retries times.

Parameters:
server_namestr

Name of the server. Default is "HANATools".

versionstr

Version of the server. Default is "1.0".

hoststr

Host address for the server.

transportstr

Transport protocol to use. Default is "stdio". Can be "sse" for Server-Sent Events.

sse_portint

Port to use for SSE transport. Default is 8001.

auth_tokenstr, optional

Authentication token for the server. If provided, the server will require this token for access.

max_retriesint

Maximum number of retries to find an available port. Default is 5.

class Config

Configuration for this pydantic object.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

get_tools() List[BaseTool]

Get the tools in the toolkit.