"""Log tail tool for reading log files.""" import subprocess from langchain_core.tools import BaseTool class LogTailTool(BaseTool): """Tail the last N lines from a log file.""" name: str = "tail_log" description: str = "Tail the last N lines of a log file given its path and optional number of lines." def _run(self, path: str, lines: int = 500): # type: ignore[override] """Run the tool to tail log files.""" try: return subprocess.check_output(["tail", "-n", str(lines), path], text=True) except subprocess.CalledProcessError as e: return f"Error reading log file {path}: {e}" except FileNotFoundError: return f"Log file not found: {path}" async def _arun(self, *args, **kwargs): # noqa: D401 """Async version not implemented.""" raise NotImplementedError("Use the synchronous version of this tool.")