llms.py
Extensions

Tool Support

Support for Python function calling (Tools), allowing LLMs to interact with your local environment and custom logic.

Python Function Tools

Define tools using standard Python functions. The system automatically generates tool definitions from your function's signature, type hints, and docstrings:

def get_current_time(tz_name: Optional[str] = None) -> str:
    """
    Get current time in ISO-8601 format.

    Args:
        tz_name: Optional timezone name (e.g. 'America/New_York'). Defaults to UTC.
    """
    if tz_name:
        try:
            tz = ZoneInfo(tz_name)
        except Exception:
            return f"Error: Invalid timezone '{tz_name}'"
    else:
        tz = timezone.utc

    return datetime.now(tz).isoformat()

Register tools for function calling

You can register simple functions or provide manual definitions for complex cases.

Implicit Tool Definition

Register your tools within an extension's install method using ctx.register_tool.

def install(ctx):
    # Automatic definition from function signature
    ctx.register_tool(get_current_time)

Explicit Tool Definition

When more fine-grain configuration is needed you can use an explicit tool definition instead, e.g:

ctx.register_tool(
    get_current_time,
    {
        "type": "function",
        "function": {
            "name": "get_current_time",
            "description": "Get current time in ISO-8601 format.",
            "parameters": {
                "type": "object",
                "properties": {
                    "tz_name": {
                        "type": "string",
                        "description": "timezone name (e.g. 'America/New_York')",
                        "default": "UTC",
                    }
                },
                "required": [],
            },
        },
    },
)

ctx.register_tool(
    edit_file,
    {
        "type": "function",
        "function": {
            "name": "edit_file",
            "description": "Replaces first occurrence of old_str with new_str in file. If old_str is empty, create/overwrite file with new_str.",
            "parameters": {
                "type": "object",
                "properties": {
                    "path": {"type": "string", "description": "Path to the file to edit."},
                    "old_str": {"type": "string", "description": "String to replace."},
                    "new_str": {"type": "string", "description": "String to replace with."},
                },
                "required": ["path", "old_str", "new_str"],
            },
        },
    },
)

UI Management

Dedicated Tools Page

View all registered tools and their definitions at /tools page via the left sidebar link:

Top Panel Tools Selector

  • One-Click Enable/Disable: Use the new Tool Selector in the chat interface (top-right) to control which tools are available to the model
  • Granular Control: Select "All", "None", or specific tools for each chat session

When tools are used within AI Requests a special UI is used to render tool calls and responses.

Core Tools

See the built-in core_tools functionality enabling LLMs to interact with their environment, perform calculations, and manage persistent data.


Available Tools

All available tools are maintained in the GitHub llmspy organization repositories:

ToolDescription
geminiGoogle Gemini RAG file search with document management, auto-upload & sync capabilities
duckduckgoAdd web search tool capabilities using Duck Duck Go
xmasExample of utilizing the Extensions APIs to give llms.py some Christmas spirit

List available extensions:

llms --add

Install the duckduckgo extension and its web_search tool:

llms --add duckduckgo

This registers the web_search tool allowing LLMs to perform web searches using Duck Duck Go.

def web_search(query: str, max_results: int | None = 10, page: int = 1) -> Dict[str, Any]:

Installing external Extensions and Tools

Installing an extension clones it into your ~/.llms/extensions folder and installs any Python requirements.txt dependencies. You can remove an extension by deleting the folder from ~/.llms/extensions.

Install 3rd-party extensions:

llms --add <user>/<repo>

Manual installation:

git clone https://github.com/<user>/<repo> ~/.llms/extensions/<repo>

🤝 Feel free to submit pull requests to add new extensions to the llmspy organization to make your extension easily discoverable to everyone.