🦀 ClawHub
OpenClaw LLM Tools
by @michealxie001
Universal Tool Definition System for LLM function calling. Define tools once, use with any LLM provider (OpenAI, Anthropic, Gemini, etc.). JSON Schema valida...
⚡ When to Use
💡 Examples
1. 定义工具
from llm_tools import ToolRegistry, Tool创建工具注册表
registry = ToolRegistry()定义工具
@registry.register(
name="get_weather",
description="Get current weather for a location",
parameters={
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City name"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"default": "celsius"
}
},
"required": ["location"]
}
)
def get_weather(location: str, unit: str = "celsius"):
return {"temperature": 22, "unit": unit}
2. 转换为不同 LLM 格式
# OpenAI format
openai_tools = registry.to_openai()Anthropic format
anthropic_tools = registry.to_anthropic()Google Gemini format
gemini_tools = registry.to_gemini()Ollama format
ollama_tools = registry.to_ollama()
3. 验证工具调用
# 验证参数
is_valid, error = registry.validate_call(
"get_weather",
{"location": "Beijing", "unit": "celsius"}
)执行工具
result = registry.execute("get_weather", {"location": "Beijing"})
TERMINAL
clawhub install oc-llm-tools