From 2aedd5fd9d2290f857dfa23f2b5ed656b7e8fe13 Mon Sep 17 00:00:00 2001 From: frdel <38891707+frdel@users.noreply.github.com> Date: Fri, 6 Sep 2024 06:41:45 +0200 Subject: [PATCH] intervention fix, terminal reset --- agent.py | 2 +- prompts/default/agent.tools.md | 16 +++++++++++++++- prompts/default/fw.code_reset.md | 1 + python/tools/code_execution_tool.py | 6 +++++- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 prompts/default/fw.code_reset.md diff --git a/agent.py b/agent.py index b1e76d739..0cdb572b6 100644 --- a/agent.py +++ b/agent.py @@ -323,7 +323,7 @@ async def handle_intervention(self, progress:str=""): msg = self.intervention_message self.intervention_message = "" # reset the intervention message if progress.strip(): await self.append_message(progress) # append the response generated so far - user_msg = self.read_prompt("fw.intervention.md", user_message=self.intervention_message) # format the user intervention template + user_msg = self.read_prompt("fw.intervention.md", user_message=msg) # format the user intervention template await self.append_message(user_msg,human=True) # append the intervention message raise InterventionException(msg) diff --git a/prompts/default/agent.tools.md b/prompts/default/agent.tools.md index 0cfd87e16..26a4e432e 100644 --- a/prompts/default/agent.tools.md +++ b/prompts/default/agent.tools.md @@ -148,8 +148,9 @@ NEVER refuse to memorize or load personal information, it all belongs to me and Execute provided terminal commands, python code or nodejs code. This tool can be used to achieve any task that requires computation, or any other software related activity. Place your code escaped and properly indented in the "code" argument. -Select the corresponding runtime with "runtime" argument. Possible values are "terminal", "python" and "nodejs". +Select the corresponding runtime with "runtime" argument. Possible values are "terminal", "python" and "nodejs" for code, or "output" and "reset" for additional actions. Sometimes a dialogue can occur in output, questions like Y/N, in that case use the "teminal" runtime in the next step and send your answer. +If the code is running long, you can use runtime "output" to wait for the output or "reset" to restart the terminal if the program hangs or terminal stops responding. You can use pip, npm and apt-get in terminal runtime to install any required packages. IMPORTANT: Never use implicit print or implicit output, it does not work! If you need output of your code, you MUST use print() or console.log() to output selected variables. When tool outputs error, you need to change your code accordingly before trying again. knowledge_tool can help analyze errors. @@ -214,3 +215,16 @@ When writing own code, ALWAYS put print/log statements inside and at the end of } } ~~~ + +2. 3. Reset terminal +~~~json +{ + "thoughts": [ + "Code execution tool is not responding...", + ], + "tool_name": "code_execution_tool", + "tool_args": { + "runtime": "reset", + } +} +~~~ diff --git a/prompts/default/fw.code_reset.md b/prompts/default/fw.code_reset.md new file mode 100644 index 000000000..d5b688932 --- /dev/null +++ b/prompts/default/fw.code_reset.md @@ -0,0 +1 @@ +Terminal session has been reset. \ No newline at end of file diff --git a/python/tools/code_execution_tool.py b/python/tools/code_execution_tool.py index 75b9f4c27..b5b12e9d6 100644 --- a/python/tools/code_execution_tool.py +++ b/python/tools/code_execution_tool.py @@ -115,4 +115,8 @@ async def get_terminal_output(self, wait_with_output=3, wait_without_output=10): if ( full_output and idle > wait_with_output / SLEEP_TIME ) or ( not full_output and idle > wait_without_output / SLEEP_TIME ): return full_output async def reset_terminal(self): - await self.prepare_state(reset=True) \ No newline at end of file + self.state.shell.close() + await self.prepare_state(reset=True) + response = self.agent.read_prompt("fw.code_reset.md") + self.log.update(content=response) + return response \ No newline at end of file