feat(agent): remove unneeded python_execution tool

This commit is contained in:
Petar Zivkovic 2026-03-05 22:06:11 +01:00
parent cefe90fd5e
commit 49b8285c73
4 changed files with 9 additions and 64 deletions

View File

@ -1,54 +0,0 @@
def run_python_script(script: str, timeout_seconds: int = 60) -> dict:
"""
Run a short Python script and return a structured result with stdout, stderr, and exit code.
This tool is intended for agent workflows that need a reliable Python scratchpad for
calculations, parsing, formatting, or quick validation.
"""
import os
import subprocess
import sys
import uuid
from pathlib import Path
workspace = Path(os.getenv("TEMP_CODE_DIR", "temp")).resolve()
workspace.mkdir(exist_ok=True)
script_path = workspace / f"{uuid.uuid4()}.py"
payload = script if script.endswith("\n") else script + "\n"
script_path.write_text(payload, encoding="utf-8")
try:
completed = subprocess.run(
[sys.executable or "python3", str(script_path.resolve())],
cwd=str(workspace),
capture_output=True,
text=True,
timeout=timeout_seconds,
check=False,
)
return {
"ok": completed.returncode == 0,
"exit_code": completed.returncode,
"stdout": completed.stdout,
"stderr": completed.stderr,
}
except subprocess.TimeoutExpired as exc:
return {
"ok": False,
"exit_code": None,
"stdout": exc.stdout or "",
"stderr": (exc.stderr or "") + f"\nError: Execution timed out after {timeout_seconds} seconds.",
}
except Exception as exc:
return {
"ok": False,
"exit_code": None,
"stdout": "",
"stderr": f"Execution error: {exc}",
}
finally:
try:
script_path.unlink(missing_ok=True)
except Exception:
pass

View File

@ -1,7 +1,7 @@
--- ---
name: python-scratchpad name: python-scratchpad
description: Use the existing Python execution tools as a scratchpad for calculations, data transformation, and quick script-based validation. description: Use the existing Python execution tools as a scratchpad for calculations, data transformation, and quick script-based validation.
allowed-tools: run_python_script execute_code allowed-tools: execute_code
--- ---
# Python Scratchpad # Python Scratchpad
@ -15,22 +15,21 @@ This skill is especially useful for:
- checking assumptions with a small reproducible script - checking assumptions with a small reproducible script
Requirements: Requirements:
- The agent should have access to `run_python_script` or `execute_code`. - The agent should have access to `execute_code`.
Workflow: Workflow:
1. If the task needs computation or a repeatable transformation, activate this skill. 1. If the task needs computation or a repeatable transformation, activate this skill.
2. If you need examples, call `read_skill_file` for `references/examples.md`. 2. If you need examples, call `read_skill_file` for `references/examples.md`.
3. Write a short Python script for the exact task. 3. Write a short Python script for the exact task.
4. Prefer `run_python_script` with the script in its `script` argument. 4. Prefer `run_python_script` with the script in its `script` argument.
5. If `run_python_script` is unavailable, call `execute_code` once with that script. 5. Use the script output in the final answer.
6. Use the script output in the final answer. 6. Keep scripts small and task-specific.
7. Keep scripts small and task-specific.
Rules: Rules:
1. Prefer standard library Python. 1. Prefer standard library Python.
2. Print only the values you need. 2. Print only the values you need.
3. Do not invent outputs without running the script. 3. Do not invent outputs without running the script.
4. If neither `run_python_script` nor `execute_code` is available, say exactly: `No Python execution tool is configured for this agent.` 4. If `execute_code` is not available, say exactly: `No Python execution tool is configured for this agent.`
5. Do not claim there is a generic execution-environment problem unless a tool call actually returned such an error. 5. Do not claim there is a generic execution-environment problem unless a tool call actually returned such an error.
Expected behavior: Expected behavior:

View File

@ -7,7 +7,7 @@ numbers = [14, 27, 31, 8]
print(sum(numbers)) print(sum(numbers))
``` ```
Expected structured result with `run_python_script`: Expected structured result with `execute_code`:
```json ```json
{ {

View File

@ -1,6 +1,7 @@
graph: graph:
id: skills id: skills
description: '' description: Workflow to demonstrate skills usage
initial_instruction: Give the agent an instruction to explicitly use code to generate a Fibonacci sequence, sum numbers, or something else that is better done with code than LLM generation.
log_level: DEBUG log_level: DEBUG
is_majority_voting: false is_majority_voting: false
nodes: nodes:
@ -17,7 +18,7 @@ graph:
- type: function - type: function
config: config:
tools: tools:
- name: python_execution:All - name: code_executor:All
timeout: null timeout: null
prefix: '' prefix: ''
thinking: null thinking: null
@ -33,7 +34,6 @@ graph:
log_output: true log_output: true
edges: [] edges: []
memory: [] memory: []
initial_instruction: ''
start: start:
- Qwerty - Qwerty
end: [] end: []