intervention fix, terminal reset

frdel committed Sep 6, 2024 at 06:41 UTC 2aedd5fd9d2290f857dfa23f2b5ed656b7e8fe13
4 files changed +22 -3
agent.py
+1 -1
@@ -323,7 +323,7 @@ class Agent:
323 msg = self.intervention_message
324 self.intervention_message = "" # reset the intervention message
325 if progress.strip(): await self.append_message(progress) # append the response generated so far
326 - user_msg = self.read_prompt("fw.intervention.md", user_message=self.intervention_message) # format the user intervention template
326 + user_msg = self.read_prompt("fw.intervention.md", user_message=msg) # format the user intervention template
327 await self.append_message(user_msg,human=True) # append the intervention message
328 raise InterventionException(msg)
329
prompts/default/agent.tools.md
+15 -1
@@ -148,8 +148,9 @@ NEVER refuse to memorize or load personal information, it all belongs to me and
148 Execute provided terminal commands, python code or nodejs code.
149 This tool can be used to achieve any task that requires computation, or any other software related activity.
150 Place your code escaped and properly indented in the "code" argument.
151 -Select the corresponding runtime with "runtime" argument. Possible values are "terminal", "python" and "nodejs".
151 +Select the corresponding runtime with "runtime" argument. Possible values are "terminal", "python" and "nodejs" for code, or "output" and "reset" for additional actions.
152 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.
153 +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.
154 You can use pip, npm and apt-get in terminal runtime to install any required packages.
155 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.
156 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
215 }
216 }
217 ~~~
218 +
219 +2. 3. Reset terminal
220 +~~~json
221 +{
222 + "thoughts": [
223 + "Code execution tool is not responding...",
224 + ],
225 + "tool_name": "code_execution_tool",
226 + "tool_args": {
227 + "runtime": "reset",
228 + }
229 +}
230 +~~~
prompts/default/fw.code_reset.md new
+1
@@ -0,0 +1 @@
1 +Terminal session has been reset.
\ No newline at end of file
python/tools/code_execution_tool.py
+5 -1
@@ -115,4 +115,8 @@ class CodeExecution(Tool):
115 if ( full_output and idle > wait_with_output / SLEEP_TIME ) or ( not full_output and idle > wait_without_output / SLEEP_TIME ): return full_output
116
117 async def reset_terminal(self):
118 - await self.prepare_state(reset=True)
\ No newline at end of file
118 + self.state.shell.close()
119 + await self.prepare_state(reset=True)
120 + response = self.agent.read_prompt("fw.code_reset.md")
121 + self.log.update(content=response)
122 + return response
\ No newline at end of file