66from langchain_core .tools import StructuredTool
77
88from .base import Skill
9- from ..config import MAX_RETRIES
109
1110
1211class RunScriptInput (BaseModel ):
@@ -19,7 +18,8 @@ class RunnerSkill(Skill):
1918 def __init__ (self , config , archive ):
2019 super ().__init__ (config , archive )
2120 self ._run_count = 0
22- self ._max_runs = config .max_retries + 1 # initial run + retries
21+ self ._max_runs = config .max_retries + 1
22+ self ._succeeded = False
2323
2424 def get_tools (self ):
2525 work_dir = self .archive .work_dir
@@ -28,17 +28,17 @@ def get_tools(self):
2828 skill = self
2929
3030 async def run_script_tool (script_name : str ) -> str :
31+ if skill ._succeeded :
32+ return "Script already ran successfully. Do not run again."
3133 skill ._run_count += 1
3234 if skill ._run_count > skill ._max_runs :
33- msg = f"RUN LIMIT REACHED ({ skill ._max_runs } runs). Stop and report the current status to the user."
34- print (f"\n { msg } " , flush = True )
35- return msg
35+ return "Run limit reached. Stop and report current status."
3636
3737 script_path = work_dir / script_name
3838 if not script_path .exists ():
3939 return f"ERROR: Script '{ script_name } ' not found"
4040
41- print (f"\n Running { script_name } ... (run { skill . _run_count } / { skill . _max_runs } ) " , flush = True )
41+ print (f"\n Running { script_name } ..." , flush = True )
4242 try :
4343 result = subprocess .run (
4444 ["python" , script_name ],
@@ -48,6 +48,7 @@ async def run_script_tool(script_name: str) -> str:
4848 timeout = timeout ,
4949 )
5050 if result .returncode == 0 :
51+ skill ._succeeded = True
5152 print ("Script ran successfully" , flush = True )
5253 return f"SUCCESS\n Output:\n { result .stdout [:500 ]} "
5354 else :
@@ -57,13 +58,13 @@ async def run_script_tool(script_name: str) -> str:
5758 f"Stdout: { result .stdout } "
5859 )
5960 print (f"Failed (code { result .returncode } )" , flush = True )
61+ if result .stderr :
62+ print (f"Error output:\n { result .stderr [:500 ]} " , flush = True )
6063 archive .archive_run_output (error_msg )
61- remaining = skill ._max_runs - skill ._run_count
6264 return (
6365 f"FAILED (code { result .returncode } )\n "
6466 f"Stderr:\n { result .stderr } \n "
65- f"Stdout:\n { result .stdout [:500 ]} \n "
66- f"\n You have { remaining } run(s) remaining."
67+ f"Stdout:\n { result .stdout [:500 ]} "
6768 )
6869 except subprocess .TimeoutExpired :
6970 return f"ERROR: Script timed out ({ timeout } s)"
0 commit comments