Skip to content

Agent Zero AI framework

Align remote exec with code execution timeouts

Alessandro8a39542dc3bd
diff --git a/plugins/_a0_connector/prompts/agent.system.tool.code_execution_remote.md b/plugins/_a0_connector/prompts/agent.system.tool.code_execution_remote.md
index 094d105ed..2e1251153 100644
--- a/plugins/_a0_connector/prompts/agent.system.tool.code_execution_remote.md
+++ b/plugins/_a0_connector/prompts/agent.system.tool.code_execution_remote.md
@@ -33,6 +33,9 @@ Runtime-specific fields:
- Use `output` to poll a running session and `runtime=reset` for a stuck session.
Use `reset: true` on a new command when you need a clean session and want to
run the replacement command immediately.
+- Execution and output polling timeouts follow the normal `_code_execution`
+ plugin settings. For builds, installs, servers, tests, training, and other
+ long work, redirect logs and poll with `runtime=output`.
- Paths and shell syntax are evaluated on the CLI host, not inside Agent Zero.
- When the user gives a relative path like `tmp/file.txt`, keep it relative to
the CLI host terminal. Do not prepend or `cd` to `/a0/usr/workdir`; that is the
diff --git a/plugins/_a0_connector/tools/code_execution_remote.py b/plugins/_a0_connector/tools/code_execution_remote.py
index 45d68a3e4..00457d6c7 100644
--- a/plugins/_a0_connector/tools/code_execution_remote.py
+++ b/plugins/_a0_connector/tools/code_execution_remote.py
@@ -9,6 +9,7 @@ from helpers.tool import Response, Tool
from helpers.ws import NAMESPACE
from helpers.ws_manager import ConnectionNotFoundError, get_shared_ws_manager
+from plugins._a0_connector.helpers.exec_config import build_exec_config
from plugins._a0_connector.helpers.ws_runtime import (
clear_pending_exec_op,
remote_exec_metadata_for_sid,
@@ -19,8 +20,15 @@ from plugins._a0_connector.helpers.ws_runtime import (
)
-EXEC_OP_TIMEOUT = 120.0
+EXEC_OP_TRANSPORT_GRACE = 15.0
+EXEC_OP_DEFAULT_TIMEOUT = 120.0
EXEC_OP_EVENT = "connector_exec_op"
+_TIMEOUT_KEYS = (
+ "first_output_timeout",
+ "between_output_timeout",
+ "max_exec_timeout",
+ "dialog_timeout",
+)
class CodeExecutionRemote(Tool):
@@ -40,6 +48,36 @@ class CodeExecutionRemote(Tool):
return value.strip().lower() in {"1", "true", "yes", "on"}
return False
+ @staticmethod
+ def _timeout_group_for_runtime(
+ runtime: str,
+ exec_config: dict[str, Any],
+ ) -> dict[str, int] | None:
+ if runtime == "output":
+ source = exec_config.get("output_timeouts")
+ elif runtime in {"terminal", "python", "nodejs", "input"}:
+ source = exec_config.get("code_exec_timeouts")
+ else:
+ return None
+
+ if not isinstance(source, dict):
+ return None
+
+ timeouts: dict[str, int] = {}
+ for key in _TIMEOUT_KEYS:
+ try:
+ timeouts[key] = max(0, int(source[key]))
+ except (KeyError, TypeError, ValueError):
+ return None
+ return timeouts
+
+ @staticmethod
+ def _wait_timeout_for_runtime(runtime: str, exec_config: dict[str, Any]) -> float:
+ timeouts = CodeExecutionRemote._timeout_group_for_runtime(runtime, exec_config)
+ if not timeouts:
+ return EXEC_OP_DEFAULT_TIMEOUT
+ return max(float(value) for value in timeouts.values()) + EXEC_OP_TRANSPORT_GRACE
+
def get_log_object(self):
import uuid
@@ -156,6 +194,11 @@ class CodeExecutionRemote(Tool):
if reason is not None:
payload["reason"] = str(reason)
+ exec_config = build_exec_config(agent=self.agent)
+ if timeouts := self._timeout_group_for_runtime(runtime, exec_config):
+ payload["timeouts"] = timeouts
+ wait_timeout = self._wait_timeout_for_runtime(runtime, exec_config)
+
loop = asyncio.get_running_loop()
future: asyncio.Future[dict[str, Any]] = loop.create_future()
store_pending_exec_op(
@@ -174,7 +217,7 @@ class CodeExecutionRemote(Tool):
payload,
handler_id=f"{self.__class__.__module__}.{self.__class__.__name__}",
)
- result = await asyncio.wait_for(future, timeout=EXEC_OP_TIMEOUT)
+ result = await asyncio.wait_for(future, timeout=wait_timeout)
except ConnectionNotFoundError:
clear_pending_exec_op(op_id)
return Response(
@@ -189,7 +232,8 @@ class CodeExecutionRemote(Tool):
return Response(
message=(
"code_execution_remote: timed out waiting for CLI to respond "
- f"to runtime={runtime!r} in session {session}"
+ f"to runtime={runtime!r} in session {session} after "
+ f"{wait_timeout:g} seconds"
),
break_loop=False,
)