from vergent.interaction import AgentEnv, AgentEnvConfig
from vergent.tools import ToolConfig
run_id = str(uuid.uuid4())
impl = os.getenv("DEPLOYMENT", "vefaas").lower()
"image": "enterprise-public-2-cn-beijing.cr.volces.com/vefaas-public/python:3.12",
"command": "curl -fsSL https://****-test-empty.tos-cn-beijing.ivolces.com/bin/tos_swe_rex.sh | bash -s -- ixcprx",
"startup_timeout": 180.0,
"function_id": os.getenv("VEFAAS_FUNCTION_ID"),
"function_route": os.getenv("VEFAAS_FUNCTION_ROUTE"),
"PIP_PROGRESS_BAR": "off",
env_config = AgentEnvConfig(**env_config)
env = AgentEnv(run_id=run_id, env_config=env_config)
{"name": "execute_bash"},
{"name": "str_replace_editor"},
tools = [ToolConfig(**tool_config).get_tool() for tool_config in tools_config]
env.install_tools(tools)
out = env.communicate("which str_replace_editor")
print(f"[Tool check] which str_replace_editor\n -> {out.strip()}\n")
print(" Sandbox demo: create script -> run -> output to file -> cat")
print("\n[Step 1] Install numpy")
env.communicate("pip install numpy -q")
_script = "import numpy as np; print(np.array([1,2,3]).sum())"
print("[Step 2] str_replace_editor create /tmp/demo.py")
env.communicate(f"str_replace_editor create --path /tmp/demo.py --file_text {shlex.quote(_script)}")
print("[Step 3] Run script (python3 /tmp/demo.py > /tmp/demo_out.txt)")
env.communicate("execute_bash 'python3 /tmp/demo.py > /tmp/demo_out.txt'")
print("[Step 4] cat /tmp/demo_out.txt")
out = env.communicate("cat /tmp/demo_out.txt")
print(f" -> {out.strip()}\n")
print(" Demo done (sandbox: script + output file persisted)")