Below, you can find code snippets that show how to use PyGEAI The Lab's module to create, retrieve, list, update, publish and delete Tools.
Initiate AILabManager to create a new Tool. Define a set of parameters user input including key, data_type, description, is_required, internal configuration parameters (type, key, from_secret) and construct the Tool, assigning key metadata: name, description, scope.
from pygeai.lab.managers import AILabManager
from pygeai.lab.models import Tool, ToolParameter
parameters =
ToolParameter(
key="input",
data_type="String",
description="some input that the tool needs.",
is_required=True
),
ToolParameter(
key="some_nonsensitive_id",
data_type="String",
description="Configuration that is static, in the sense that whenever the tool is used, the value for this parameter is configured here. The llm will not know about it.",
is_required=True,
type="config",
from_secret=False,
value="b001e30b4016001f5f76b9ae9215ac40"
),
ToolParameter(
key="api_token",
data_type="String",
description="Configuration that is static, but it is sensitive information . The value is stored in secret-manager",
is_required=True,
type="config",
value="0cd84dc7-f3f5-4a03-9288-cdfd8d72fde1"
)
tool = Tool(
name="sample_tool_v5",
description="a builtin tool that does something but really does nothing cos it does not exist.",
scope="builtin",
parameters=parameters
)
manager = AILabManager()
result = manager.create_tool(
tool=tool,
automatic_publish=False
)
print(f"Created tool: {result.name}, ID: {result.id}")
print(f"Description: {result.description}")
print(f"Messages: {result.messages}")
Start AILabManager to Get a Tool by its ID (tool_id). Apply FilterSettings, including revision, version, allow_drafts to request the Tool.
from pygeai.lab.managers import AILabManager
from pygeai.lab.models import FilterSettings, Tool
manager = AILabManager()
filter_settings = FilterSettings(
revision="0",
version="0",
allow_drafts=True
)
result = manager.get_tool(
tool_id="affd8ede-97c6-4083-b1f6-2b463ad4891e",
filter_settings=filter_settings
)
print(f"Retrieved tool: {result.name}, ID: {result.id}")
print(f"Description: {result.description}")
print(f"Messages: {result.messages}")
Use AILabManager to list a Tool with specific filter settings: id, count, access_scope, allow_drafts, scope, allow_external.
You can retrieve up to 100 tools that are public, built-in.
from pygeai.lab.managers import AILabManager
from pygeai.lab.models import FilterSettings
manager = AILabManager()
filter_settings = FilterSettings(
id="",
count="100",
access_scope="public",
allow_drafts=True,
scope="builtin",
allow_external=True
)
result = manager.list_tools(
filter_settings=filter_settings
)
print(f"Found {len(result)} tools:")
for tool in result:
print(f"Tool: {tool.name}, ID: {tool.id}, Scope: {tool.scope}")
Start AILabManager to update an existing Tool. Import the information and then define parameters key,
data_type, description, is_required, internal configuration parameters (type, key, from_secret) and Tool metadad name, description, scope. Update the Tool in the system.
from pygeai.lab.managers import AILabManager
from pygeai.lab.models import Tool, ToolParameter
parameters =
ToolParameter(
key="input",
data_type="String",
description="some input that the tool needs. ",
is_required=True
),
ToolParameter(
key="some_nonsensitive_id",
data_type="String",
description="Configuration that is static, in the sense that whenever the tool is used, the value for this parameter is configured here. The llm will not know about it.",
is_required=True,
type="config",
from_secret=False,
value="b001e30b4016001f5f76b9ae9215ac40"
),
ToolParameter(
key="api_token",
data_type="String",
description="Configuration that is static, but it is sensitive information . The value is stored in secret-manager",
is_required=True,
type="config",
from_secret=True,
value="0cd84dc7-f3f5-4a03-9288-cdfd8d72fde1"
)
tool = Tool(
id="affd8ede-97c6-4083-b1f6-2b463ad4891e",
name="sample tool V5",
description="a builtin tool that does something but really does nothing cos it does not exist. UPDATED",
scope="builtin",
parameters=parameters
)
manager = AILabManager()
result = manager.update_tool(
tool=tool,
automatic_publish=False,
upsert=False
)
print(f"Updated tool: {result.name}, ID: {result.id}")
print(f"Description: {result.description}")
print(f"Messages: {result.messages}")
Initiate AILabManager interface to publish a specific revision of an existing Tool. Call manager.publish_tool_revision with the tool_id and its revision number to activate it.
from pygeai.lab.managers import AILabManager
from pygeai.lab.models import Tool
manager = AILabManager()
result = manager.publish_tool_revision(
tool_id="affd8ede-97c6-4083-b1f6-2b463ad4891e",
revision="1"
)
print(f"Published tool: {result.name}, ID: {result.id}, Revision: {result.revision}")
Use AILabManager to proceed to delete a Tool.
from pygeai.core.base.responses import EmptyResponse
from pygeai.lab.managers import AILabManager
manager = AILabManager(api_key="your-api-key")
result = manager.delete_tool(
tool_id="affd8ede-97c6-4083-b1f6-2b463ad4891e"
)
if isinstance(result, EmptyResponse):
print("Tool deleted successfully")
else:
print("Errors:", result.errors)
result = manager.delete_tool(
tool_name="sample tool V5"
)
print("Tool deleted successfully")