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/write_file.py
Normal file
32
docker_agent_sandbox/tools/write_file.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""write_file.py – tool for writing files inside the sandbox."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
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_write_file_tool(sandbox: "DockerSandbox") -> BaseTool:
|
||||
"""Return a write_file tool bound to *sandbox*."""
|
||||
|
||||
@tool
|
||||
def write_file(path: str, content: str) -> str:
|
||||
"""
|
||||
Write *content* to *path*.
|
||||
|
||||
*path* can be absolute or relative. Parent directories are created
|
||||
automatically. Returns a confirmation message or an error.
|
||||
"""
|
||||
try:
|
||||
logger.debug("Writing file inside sandbox: {}", path)
|
||||
sandbox.write_file(path, content)
|
||||
except Exception as exc:
|
||||
return f"[ERROR writing {path!r}] {exc}"
|
||||
return f"[OK] Written {len(content.encode())} bytes to {path}"
|
||||
|
||||
return write_file
|
||||
Reference in New Issue
Block a user