Tools
Create, update, and delete custom tools for your AI agents.
π Quick Start
from glaip_sdk import Client
client = Client()
# Create tool from local Python file
tool = client.create_tool(
name="my-tool",
file_path="my_tool.py"
)
# Use the tool
print(f"Created tool: {tool.name} (ID: {tool.id})")
# Clean up
tool.delete()
π οΈ Create a Tool
From File (Recommended)
from glaip_sdk import Client
client = Client()
# Create tool from Python file
tool = client.create_tool(
name="calculator-tool",
file_path="calculator.py",
description="A simple calculator tool"
)
π Tool Structure Requirements
Every tool file must follow this structure:
from gllm_plugin.tools import tool_plugin # Required: lives in gllm_plugin.tools
from langchain_core.tools import BaseTool
@tool_plugin(version="1.0.0") # Required decorator
class YourToolName(BaseTool): # Must inherit from BaseTool
"""Tool description."""
name: str = "tool_name" # Required: unique tool name
description: str = "Tool description" # Required: what the tool does
def _run(self, param1: str, param2: int = 10) -> str:
"""Tool implementation. This method is called when the tool runs."""
# Your tool logic here
result = f"Processed {param1} with {param2}"
return result
Required Elements:
@tool_plugin(version="1.0.0")
decoratorInherit from
BaseTool
name
anddescription
attributes_run
method with your tool logic
π Update a Tool
# Update tool attributes
updated_tool = client.update_tool(
"tool-id",
description="Updated description"
)
# Or use the tool object
tool = client.get_tool_by_id("tool-id")
tool.update(
description="Updated description"
)
ποΈ Delete a Tool
# Delete by ID
client.delete_tool("tool-id")
# Or use the tool object
tool = client.get_tool_by_id("tool-id")
tool.delete()
π List and Find Tools
# List all tools
all_tools = client.list_tools()
# Find tools by name
tools = client.find_tools("calculator")
# Get tool by ID
tool = client.get_tool_by_id("tool-id")
# Get tool script content
script_content = tool.get_script()
π οΈ Tool Dependencies
Note: Dependencies must be pre-installed on the AIP backend. The platform does not automatically install Python packages from requirements.txt or metadata.
Pre-installed Dependencies
Common packages like pandas
, numpy
, requests
, etc. are typically available. If you need specific packages:
Contact your AIP administrator to install required dependencies
Use only packages that are already available on the backend
Test your tools in the backend environment before deployment
Checking Available Packages
You can verify what's available by testing your tool locally with the same Python environment as the backend.
π§ Install and Uninstall Tools
# Install a tool (makes it available for use)
client.install_tool("tool-id")
# Uninstall a tool (removes it from availability)
client.uninstall_tool("tool-id")
# Check if tool is installed
tool = client.get_tool_by_id("tool-id")
print(f"Installed: {tool.is_installed}")
π― Best Practices
Tool Design
Single Purpose: Each tool should do one thing well
Clear Interface: Use descriptive parameter names and types
Error Handling: Provide helpful error messages
Documentation: Document what the tool does and how to use it
Code Quality
Type Hints: Use Python type hints for better IDE support
Docstrings: Include comprehensive docstrings
Validation: Validate inputs and handle edge cases
Testing: Test your tools before deploying
π Next Steps
MCPs: Connect external services via MCPs
Streaming: Use Streaming & Renderers for real-time tool execution
File Uploads: Process files with File Uploads
Output & Scripting: Automate workflows with Output & Scripting
π‘ Best Practices
Descriptive Names: Use clear, descriptive names for your tools
Error Handling: Implement proper error handling in your tool logic
Documentation: Add clear docstrings to your tool classes and methods
Testing: Test your tools locally before uploading
Ready to build powerful tools? Start with simple functions and gradually build more complex capabilities!