feat: Initial library extraction from PIN LLM benchmark
DockerSandbox + LangChain file/shell tools extracted into a standalone package. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
33
docker_agent_sandbox/tools/delete_file.py
Normal file
33
docker_agent_sandbox/tools/delete_file.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""delete_file.py – tool for deleting files inside the sandbox."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from shlex import quote
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from langchain_core.tools import BaseTool, tool
|
||||
from loguru import logger
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from docker_agent_sandbox.sandbox import DockerSandbox
|
||||
|
||||
|
||||
def make_delete_file_tool(sandbox: "DockerSandbox") -> BaseTool:
|
||||
"""Return a delete_file tool bound to *sandbox*."""
|
||||
|
||||
@tool
|
||||
def delete_file(path: str) -> str:
|
||||
"""
|
||||
Delete a file or empty directory at *path*.
|
||||
|
||||
Use ``delete_file`` only for files or empty directories. To remove a
|
||||
directory tree use ``move_file`` to archive it first, or call this tool
|
||||
repeatedly. Returns a confirmation message or an error.
|
||||
"""
|
||||
logger.debug("Deleting file inside sandbox: {}", path)
|
||||
exit_code, output = sandbox.exec(f"rm -d -- {quote(path)}")
|
||||
if exit_code != 0:
|
||||
return f"[ERROR deleting {path!r}] {output.strip()}"
|
||||
return f"[OK] Deleted {path}"
|
||||
|
||||
return delete_file
|
||||
Reference in New Issue
Block a user