- 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.
32 lines
821 B
Python
32 lines
821 B
Python
"""
|
|
Shell execution tool.
|
|
"""
|
|
|
|
import subprocess
|
|
|
|
from langchain_core.tools import tool
|
|
|
|
|
|
@tool
|
|
def shell(command: str) -> str:
|
|
"""
|
|
Execute a shell command and return the output.
|
|
|
|
Args:
|
|
command: The shell command to execute
|
|
|
|
Returns:
|
|
The command output (stdout and stderr combined)
|
|
"""
|
|
try:
|
|
result = subprocess.run(command, shell=True, capture_output=True, text=True, timeout=60)
|
|
output = result.stdout
|
|
if result.stderr:
|
|
output += f"\nSTDERR: {result.stderr}"
|
|
if result.returncode != 0:
|
|
output += f"\nExit code: {result.returncode}"
|
|
return output or "(no output)"
|
|
except subprocess.TimeoutExpired:
|
|
return "Error: Command timed out after 60 seconds"
|
|
except Exception as e:
|
|
return f"Error: {e}"
|