Agent Zero AI framework
code exec reset polish, history and scroller fix
frdel153f0a50230c
diff --git a/prompts/agent.system.tool.code_exe.md b/prompts/agent.system.tool.code_exe.mdindex a9cafdde9..5a0d42668 100644--- a/prompts/agent.system.tool.code_exe.md+++ b/prompts/agent.system.tool.code_exe.md@@ -2,10 +2,11 @@execute terminal commands python nodejs code for computation or software tasksplace code in "code" arg; escape carefully and indent properly-select "runtime" arg: "terminal" "python" "nodejs" "output" "reset"+select "runtime" arg: "terminal" "python" "nodejs" "output"select "session" number, 0 default, others for multitasking-if code runs long, use "output" to wait, "reset" to kill process-use "pip" "npm" "apt-get" in "terminal" to install packages+if code runs long, use runtime "output" to wait+use reset true on next call to kill previous process when stuck default false+use "pip" "npm" "apt-get" in "terminal" to install packageto output, use print() or console.log()if tool outputs error, adjust code before retrying;important: check code for placeholders or demo data; replace with real variables; don't reuse snippets@@ -14,67 +15,75 @@ check dependencies before running codeoutput may end with [SYSTEM: ...] information comming from framework, not terminalusage:-1 execute python code+1 execute terminal command~~~json{"thoughts": ["Need to do...",- "I can use...",- "Then I can...",+ "Need to install...",],- "headline": "Executing Python code to check current directory",+ "headline": "Installing zip package via terminal","tool_name": "code_execution_tool","tool_args": {- "runtime": "python",+ "runtime": "terminal","session": 0,- "code": "import os\nprint(os.getcwd())",+ "reset": false,+ "code": "apt-get install zip",}}~~~-2 execute terminal command+2 execute python code+~~~json{"thoughts": ["Need to do...",- "Need to install...",+ "I can use...",+ "Then I can...",],- "headline": "Installing zip package via terminal",+ "headline": "Executing Python code to check current directory","tool_name": "code_execution_tool","tool_args": {- "runtime": "terminal",+ "runtime": "python","session": 0,- "code": "apt-get install zip",+ "reset": false,+ "code": "import os\nprint(os.getcwd())",}}~~~-2.1 wait for output with long-running scripts+3 execute nodejs code+~~~json{"thoughts": [- "Waiting for program to finish...",+ "Need to do...",+ "I can use...",+ "Then I can...",],- "headline": "Waiting for long-running program to complete",+ "headline": "Executing Javascript code to check current directory","tool_name": "code_execution_tool","tool_args": {- "runtime": "output",+ "runtime": "nodejs","session": 0,+ "reset": false,+ "code": "console.log(process.cwd());",}}~~~-2.2 reset terminal+4 wait for output with long-running scripts~~~json{"thoughts": [- "code_execution_tool not responding...",+ "Waiting for program to finish...",],- "headline": "Resetting unresponsive terminal session",+ "headline": "Waiting for long-running program to complete","tool_name": "code_execution_tool","tool_args": {- "runtime": "reset",+ "runtime": "output","session": 0,}}diff --git a/python/helpers/history.py b/python/helpers/history.pyindex b54eb28ad..d8b7d6c5f 100644--- a/python/helpers/history.py+++ b/python/helpers/history.py@@ -521,7 +521,7 @@ def output_langchain(messages: list[OutputMessage]):for m in messages:content = _output_content_langchain(content=m["content"])if not content or (isinstance(content, str) and not content.strip()):- continue+ continue # skip empty messages, modelsif m["ai"]:result.append(AIMessage(content)) # type: ignoreelse:diff --git a/python/tools/code_execution_tool.py b/python/tools/code_execution_tool.pyindex a37056057..828a1255b 100644--- a/python/tools/code_execution_tool.py+++ b/python/tools/code_execution_tool.py@@ -64,18 +64,19 @@ class CodeExecution(Tool):runtime = self.args.get("runtime", "").lower().strip()session = int(self.args.get("session", 0))self.allow_running = bool(self.args.get("allow_running", False))+ reset = bool(self.args.get("reset", False) or runtime == "reset")if runtime == "python":response = await self.execute_python_code(- code=self.args["code"], session=session+ code=self.args["code"], session=session, reset=reset)elif runtime == "nodejs":response = await self.execute_nodejs_code(- code=self.args["code"], session=session+ code=self.args["code"], session=session, reset=reset)elif runtime == "terminal":response = await self.execute_terminal_command(- command=self.args["code"], session=session+ command=self.args["code"], session=session, reset=reset)elif runtime == "output":response = await self.get_terminal_output(diff --git a/webui/js/scroller.js b/webui/js/scroller.jsindex 783b34c55..ad48f8f1e 100644--- a/webui/js/scroller.js+++ b/webui/js/scroller.js@@ -49,7 +49,13 @@ export class Scroller {const delta = nextHeight - prevHeight;this._lastClientHeight = nextHeight;- if (this.wasAtBottom) {+ const scrollTop = this._getEffectiveScrollTop();+ const bottomDistanceBefore =+ this.element.scrollHeight - scrollTop - prevHeight;+ const wasAtBottom = bottomDistanceBefore <= this.tolerance;+ this.wasAtBottom = wasAtBottom;++ if (wasAtBottom) {this.scrollToBottom();return;}