- 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.
62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
"""
|
|
Tests for zeroclaw-tools package.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
|
def test_import_main():
|
|
"""Test that main package imports work."""
|
|
from zeroclaw_tools import create_agent, shell, file_read, file_write
|
|
|
|
assert callable(create_agent)
|
|
assert hasattr(shell, "invoke")
|
|
assert hasattr(file_read, "invoke")
|
|
assert hasattr(file_write, "invoke")
|
|
|
|
|
|
def test_import_tool_decorator():
|
|
"""Test that tool decorator works."""
|
|
from zeroclaw_tools import tool
|
|
|
|
@tool
|
|
def test_func(x: str) -> str:
|
|
"""Test tool."""
|
|
return x
|
|
|
|
assert hasattr(test_func, "invoke")
|
|
|
|
|
|
def test_agent_creation():
|
|
"""Test that agent can be created with default tools."""
|
|
from zeroclaw_tools import create_agent, shell, file_read, file_write
|
|
|
|
agent = create_agent(
|
|
tools=[shell, file_read, file_write], model="test-model", api_key="test-key"
|
|
)
|
|
|
|
assert agent is not None
|
|
assert agent.model == "test-model"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_shell_tool():
|
|
"""Test shell tool execution."""
|
|
from zeroclaw_tools import shell
|
|
|
|
result = await shell.ainvoke({"command": "echo hello"})
|
|
assert "hello" in result
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_file_tools(tmp_path):
|
|
"""Test file read/write tools."""
|
|
from zeroclaw_tools import file_read, file_write
|
|
|
|
test_file = tmp_path / "test.txt"
|
|
|
|
write_result = await file_write.ainvoke({"path": str(test_file), "content": "Hello, World!"})
|
|
assert "Successfully" in write_result
|
|
|
|
read_result = await file_read.ainvoke({"path": str(test_file)})
|
|
assert "Hello, World!" in read_result
|