Tools

Create, update, and delete custom tools for your AI agents.

Tool Creation: Create tools from local Python files. The SDK uploads your files to the AIP backend where they're processed and validated.

πŸš€ 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 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"
)

File-Based Creation: This is the recommended approach. Create your tool as a Python file locally, then upload it via the SDK or CLI.

πŸ“ 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") decorator

  • Inherit from BaseTool

  • name and description 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:

  1. Contact your AIP administrator to install required dependencies

  2. Use only packages that are already available on the backend

  3. 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}")

Tool Lifecycle: Tools are automatically installed when created, but you can manually control their availability using install/uninstall operations.

🎯 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!