To list all tools available in your project, use the list_tools
method:
my_tools = client.tools.list_tools()
my_tools
[Tool(tool_id="xxxxxxxx", name="Tool 1"), Tool(tool_id="xxxxxxxx", name="Tool 2")]
To retrieve a specific tool, use the retrieve_tool
method with the tool_id
:
my_tool = client.tools.retrieve_tool(tool_id="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
my_tool
Tool(tool_id="xxxxxxxx", name="Tool 1")
To trigger a tool with specific parameters, use the trigger_tool
method:
params = {
"text": "Yes",
"long_text": "This is a long text",
}
tool_output = client.tools.trigger_tool(
tool_id="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
params=params
)
tool_output
ToolOutput(output="Result of the tool execution")
To get the parameters of a tool as a JSON string, use the _get_params_as_json_string
method:
params_json = client.tools._get_params_as_json_string(tool_id="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
params_json
{
"text": {
"type": "string",
"order": 0,
"title": "",
"metadata": {}
},
"long_text": {
"type": "string",
"metadata": {
"content_type": "long_text"
},
"order": 1
}
}
To get the steps of a tool as a JSON string, use the _get_steps_as_json_string
method:
steps_json = client.tools._get_steps_as_json_string(tool_id="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
steps_json
[
{
"transformation": "python_code_transformation",
"name": "python",
"params": {
"code": "\nreturn {\"params\" : params, \"steps\": steps}"
}
}
]
To delete a tool, use the delete_tool
method with the tool_id
:
success = client.tools.delete_tool(tool_id="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
success