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:
32
docker_agent_sandbox/tools/make_dir.py
Normal file
32
docker_agent_sandbox/tools/make_dir.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""make_dir.py – tool for creating directories 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_make_dir_tool(sandbox: "DockerSandbox") -> BaseTool:
|
||||
"""Return a make_dir tool bound to *sandbox*."""
|
||||
|
||||
@tool
|
||||
def make_dir(path: str) -> str:
|
||||
"""
|
||||
Create directory *path* (and all missing parents).
|
||||
|
||||
Succeeds silently if the directory already exists.
|
||||
Returns a confirmation message or an error.
|
||||
"""
|
||||
logger.debug("Creating directory inside sandbox: {}", path)
|
||||
exit_code, output = sandbox.exec(f"mkdir -p -- {quote(path)}")
|
||||
if exit_code != 0:
|
||||
return f"[ERROR creating directory {path!r}] {output.strip()}"
|
||||
return f"[OK] Directory exists: {path}"
|
||||
|
||||
return make_dir
|
||||
Reference in New Issue
Block a user