Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Disable AskHuman; Use ECMA modules in mjs
Tomas Valenta7f3292241563
diff --git a/api-service/codegen/codegen.py b/api-service/codegen/codegen.pyindex 81112b8b8..0cd81fa0c 100644--- a/api-service/codegen/codegen.py+++ b/api-service/codegen/codegen.py@@ -5,7 +5,7 @@ from typing import (Dict,ClassVar,)-from codegen.tools.human.ask import AskHuman+from codegen.tools.human.ask import create_ask_human_toolfrom langchain.agents import AgentExecutorfrom pydantic import BaseModel, PrivateAttrfrom langchain.chat_models import ChatOpenAI@@ -104,12 +104,10 @@ class Codegen(BaseModel):# InvalidTool(),# OutputFinalCode(),*playground_tools,- # AskHuman(- # callback_manager=callback_manager,+ # create_ask_human_tool(# run_id=run_id,# playground=playground,- # name="AskHuman",- # description="You can ask a human for guidance when you think you got stuck or you are not sure what to do next. The input should be a question for the human.",+ # callback_manager=callback_manager,# ),# WriteCodeToFile(callback_manager=callback_manager),# DeployCode(callback_manager=callback_manager),diff --git a/api-service/codegen/tools/human/__init__.py b/api-service/codegen/tools/human/__init__.pyindex ce22369ea..e69de29bb 100644--- a/api-service/codegen/tools/human/__init__.py+++ b/api-service/codegen/tools/human/__init__.py@@ -1 +0,0 @@-from .ask import AskHumandiff --git a/api-service/codegen/tools/human/ask.py b/api-service/codegen/tools/human/ask.pyindex 4147d7a7f..b8165c30b 100644--- a/api-service/codegen/tools/human/ask.py+++ b/api-service/codegen/tools/human/ask.py@@ -1,20 +1,26 @@-from langchain.tools import BaseTool-from session.playground.base import Playground+from langchain.callbacks.base import CallbackManager+from langchain.agents import Tool+from session.playground.base import Playground-class AskHuman(BaseTool):- run_id: str- playground: Playground- name = "AskHuman"- description = "You can ask a human for guidance when you think you got stuck or you are not sure what to do next. The input should be a question for the human."- def _run(self, question: str) -> str:+def create_ask_human_tool(+ run_id: str, playground: Playground, callback_manager: CallbackManager+):+ def _run(question: str) -> str:print("Asking about")- response = self.playground.api.wait_for_human_response(- run_id=self.run_id,+ response = playground.api.wait_for_human_response(+ run_id=run_id,)-+ print("HUMAN RESPONSE", response.response)return response.response- async def _arun(self, question: str) -> str:- raise NotImplementedError("AskHuman does not support async")+ tool = Tool(+ description="You can ask a human for guidance when you think you got stuck or you are not sure what to do next. The input should be a question for the human.",+ name="AskHuman",+ func=_run,+ )++ tool.callback_manager = callback_manager++ return tooldiff --git a/api-service/codegen/tools/playground/main.py b/api-service/codegen/tools/playground/main.pyindex 559a1aaf8..7f179ac75 100644--- a/api-service/codegen/tools/playground/main.py+++ b/api-service/codegen/tools/playground/main.py@@ -31,8 +31,8 @@ def create_playground_tools(for tools in (tool_factory(playground=playground, mock=mock)for tool_factory in [- create_filesystem_tools,- create_process_tools,+ # create_filesystem_tools,+ # create_process_tools,create_code_tools,])diff --git a/api-service/codegen/tools/playground/tools/code.py b/api-service/codegen/tools/playground/tools/code.pyindex 120f956cf..68b25ce7c 100644--- a/api-service/codegen/tools/playground/tools/code.py+++ b/api-service/codegen/tools/playground/tools/code.py@@ -33,19 +33,19 @@ def create_code_tools(playground: NodeJSPlayground, mock: MockRequestFactory, **@tool("RunJavaScriptCode")def run_javascript_code(code: str) -> str:"""- Run JavaScript code and return output.+ Run JavaScript code as ECMAScript module and return output.Input should be a valid JavaScript code."""- with_require = f"""- import {{ createRequire }} from "module";- const require = createRequire(import.meta.url);- {extract_code(code)}- """+ # with_require = f"""+ # import {{ createRequire }} from "module";+ # const require = createRequire(import.meta.url);+ # {extract_code(code)}+ # """nonlocal last_javascript_code- last_javascript_code = with_require+ last_javascript_code = code- output = playground.run_javascript_code(with_require)+ output = playground.run_javascript_code(code)result = encode_command_output(output)return result if len(result) > 0 else "Code execution finished without error"diff --git a/api-service/session/playground/nodejs.py b/api-service/session/playground/nodejs.pyindex 858596a3e..9eb313505 100644--- a/api-service/session/playground/nodejs.py+++ b/api-service/session/playground/nodejs.py@@ -10,7 +10,7 @@ from session.playground import Playgroundclass NodeJSPlayground(Playground):node_js_env_id = "dCeMnVVxu01L"rootdir = "/code"- default_javascript_code_file = os.path.join(rootdir, "index.js")+ default_javascript_code_file = os.path.join(rootdir, "index.mjs")run_code_timeout = 5 # 5sdef __init__(self, envs: List[EnvVar]):