- Add Python package with LangGraph-based agent for consistent tool calling - Provides reliable tool execution for providers with inconsistent native support - Includes tools: shell, file_read, file_write, web_search, http_request, memory - Discord bot integration included - CLI tool for quick interactions - Works with any OpenAI-compatible provider (Z.AI, OpenRouter, Groq, etc.) Why: Some LLM providers (e.g., GLM-5/Zhipu) have inconsistent tool calling behavior. LangGraph's structured approach guarantees reliable tool execution across all providers.
46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
"""
|
|
Base utilities for creating tools.
|
|
"""
|
|
|
|
from typing import Any, Callable, Optional
|
|
|
|
from langchain_core.tools import tool as langchain_tool
|
|
|
|
|
|
def tool(
|
|
func: Optional[Callable] = None,
|
|
*,
|
|
name: Optional[str] = None,
|
|
description: Optional[str] = None,
|
|
) -> Any:
|
|
"""
|
|
Decorator to create a LangChain tool from a function.
|
|
|
|
This is a convenience wrapper around langchain_core.tools.tool that
|
|
provides a simpler interface for ZeroClaw users.
|
|
|
|
Args:
|
|
func: The function to wrap (when used without parentheses)
|
|
name: Optional custom name for the tool
|
|
description: Optional custom description
|
|
|
|
Returns:
|
|
A BaseTool instance
|
|
|
|
Example:
|
|
```python
|
|
from zeroclaw_tools import tool
|
|
|
|
@tool
|
|
def my_tool(query: str) -> str:
|
|
\"\"\"Description of what this tool does.\"\"\"
|
|
return f"Result: {query}"
|
|
```
|
|
"""
|
|
if func is not None:
|
|
return langchain_tool(func)
|
|
|
|
def decorator(f: Callable) -> Any:
|
|
return langchain_tool(f, name=name)
|
|
|
|
return decorator
|