mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-12-04 09:28:56 +00:00
132 lines
4.4 KiB
Markdown
132 lines
4.4 KiB
Markdown
### code_execution_tool
|
|
run terminal, python, or nodejs commands
|
|
args:
|
|
- `runtime`: `terminal`, `python`, `nodejs`, or `output`
|
|
- `destination`: execution target from EXTRAS; default `default`
|
|
- `code`: command or script code as a single string, required for `terminal`, `python`, and `nodejs`
|
|
- `session`: terminal session id; default `0`
|
|
- `reset`: kill a session before running; `true` or `false`
|
|
rules:
|
|
- place the command or script in `code`
|
|
- for ad hoc tasks, development, builds, tests, and experiments, create a named temporary sandbox with the `sandbox` tool and reuse it for the task. Honor an explicitly requested or already assigned destination.
|
|
- save needed results outside a task sandbox before deleting it, or let the temporary sandbox expire after inactivity
|
|
- use `destination=local` only for work that requires direct access to the running Agent Zero framework or its operating system. If no sandbox is available for a task that belongs in one, report the blocker.
|
|
- keep the same `destination` for a session's commands, output polls, interactive input, and reset
|
|
- for connected-host workflows, load the `host-code-execution` skill. Use `destination=host` only when the task requires the connected computer and that computer has enabled code execution. Use `input` with the same destination and session for terminal input.
|
|
- use `runtime=output` to poll running work
|
|
- use `input` for interactive terminal prompts
|
|
- if a session is stuck, call again with the same `session` and `reset=true`
|
|
- check dependencies before running code
|
|
- replace placeholder or demo data with real values before execution
|
|
- use `print()` or `console.log()` when you need explicit output
|
|
- do not interleave other tools while waiting
|
|
- treat trailing framework `[SYSTEM: ...]` info as execution status, not command output; use it to decide whether to wait, reset, rerun, or continue
|
|
- probe cwd files tools and dependencies before expensive commands
|
|
- split long work into small commands: inspect, prepare, run, verify
|
|
- for builds installs servers training and long tests, redirect logs and poll with `runtime=output`
|
|
- after timeout or pause, inspect logs and processes before deciding wait reset or stop
|
|
- never claim success from timeout partial output or a still-running command
|
|
- stop stale background processes you started before final response
|
|
- when exact output matters, verify file path line count bytes and content with commands
|
|
examples:
|
|
1 terminal command
|
|
~~~json
|
|
{
|
|
"thoughts": [
|
|
"Need to do...",
|
|
"Need to install..."
|
|
],
|
|
"headline": "Installing zip package via terminal",
|
|
"tool_name": "code_execution_tool",
|
|
"tool_args": {
|
|
"runtime": "terminal",
|
|
"session": 0,
|
|
"reset": false,
|
|
"code": "apt-get install zip"
|
|
}
|
|
}
|
|
~~~
|
|
|
|
2 execute python code
|
|
|
|
~~~json
|
|
{
|
|
"thoughts": [
|
|
"Need to do...",
|
|
"I can use...",
|
|
"Then I can..."
|
|
],
|
|
"headline": "Executing Python code to check current directory",
|
|
"tool_name": "code_execution_tool",
|
|
"tool_args": {
|
|
"runtime": "python",
|
|
"session": 0,
|
|
"reset": false,
|
|
"code": "import os\nprint(os.getcwd())"
|
|
}
|
|
}
|
|
~~~
|
|
|
|
3 execute nodejs code
|
|
|
|
~~~json
|
|
{
|
|
"thoughts": [
|
|
"Need to do...",
|
|
"I can use...",
|
|
"Then I can..."
|
|
],
|
|
"headline": "Executing Javascript code to check current directory",
|
|
"tool_name": "code_execution_tool",
|
|
"tool_args": {
|
|
"runtime": "nodejs",
|
|
"session": 0,
|
|
"reset": false,
|
|
"code": "console.log(process.cwd());"
|
|
}
|
|
}
|
|
~~~
|
|
|
|
4 wait for output with long-running scripts
|
|
~~~json
|
|
{
|
|
"thoughts": [
|
|
"Waiting for program to finish..."
|
|
],
|
|
"headline": "Waiting for long-running program to complete",
|
|
"tool_name": "code_execution_tool",
|
|
"tool_args": {
|
|
"runtime": "output",
|
|
"session": 0
|
|
}
|
|
}
|
|
~~~
|
|
|
|
2 python snippet
|
|
~~~json
|
|
{
|
|
"thoughts": ["A short Python check is faster than using the shell."],
|
|
"headline": "Running Python snippet",
|
|
"tool_name": "code_execution_tool",
|
|
"tool_args": {
|
|
"runtime": "python",
|
|
"session": 0,
|
|
"reset": false,
|
|
"code": "import os\nprint(os.getcwd())"
|
|
}
|
|
}
|
|
~~~
|
|
|
|
3 wait for running output
|
|
~~~json
|
|
{
|
|
"thoughts": ["The previous command is still running, so I should poll for output."],
|
|
"headline": "Waiting for command output",
|
|
"tool_name": "code_execution_tool",
|
|
"tool_args": {
|
|
"runtime": "output",
|
|
"session": 0
|
|
}
|
|
}
|
|
~~~
|