Ready for first real test
This commit is contained in:
1 parent
acddf9135f
commit
b91c81ebdf
46 files changed
+34903
-26
No files matched your search
@@ -1,13 +1,14 @@
|
||||
"""run_python — the calculator. Agents call this for ALL arithmetic instead of doing
|
||||
mental math (LLMs are unreliable at it). Executes in an isolated subprocess with a hard
|
||||
timeout. Kept math-only by convention; runs model-generated code on this machine, so
|
||||
scope is deliberately narrow.
|
||||
timeout and a **scrubbed environment** (no account secrets), so model-generated code can't
|
||||
read API keys. For heavier data/analysis work, agents use run_analysis (tools/sandbox.py).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
from langchain_core.tools import tool
|
||||
|
||||
@@ -20,14 +21,17 @@ def run_python(code: str) -> str:
|
||||
|
||||
Use for ANY arithmetic: position sizing, percentages, P/E, returns, averages, ratios.
|
||||
You MUST print() the result. `math` and `statistics` are importable.
|
||||
Example: `print(round(1000 / 23.55, 4))`. No network or file access; 5s limit.
|
||||
Example: `print(round(1000 / 23.55, 4))`. No access to secrets; 5s limit.
|
||||
"""
|
||||
from tools.sandbox import scrubbed_env
|
||||
|
||||
try:
|
||||
proc = subprocess.run(
|
||||
[sys.executable, "-I", "-c", code],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=_TIMEOUT_S,
|
||||
env=scrubbed_env(tempfile.gettempdir()),
|
||||
)
|
||||
except subprocess.TimeoutExpired:
|
||||
return f"ERROR: execution timed out ({_TIMEOUT_S}s limit)."
|
||||
|
||||
Reference in new issue
Block a user