Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Merge branch 'templates' into production
Tomas Valenta7d583169951d
diff --cc api-service/agent/smol_agent.pyindex 1f9edf0a0,c1c76edbf..4a148d947--- a/api-service/agent/smol_agent.py+++ b/api-service/agent/smol_agent.py@@@ -3,7 -3,7 +3,7 @@@ import uuiimport osimport ast- from typing import Any, Callable, Coroutine, List-from typing import Any, List++from typing import Any, Callable, Listfrom langchain.callbacks.base import AsyncCallbackManagerfrom langchain.schema import (AIMessage,@@@ -134,10 -165,11 +168,10 @@@ Begin generating the code now"properties": {**metadata,"result": filecode,- "model": "gpt-4",+ "model": model_version,- "run_id": run_id,},"type": "model",- }+ },)return filename, filecode, metadata@@@ -224,64 -256,84 +257,81 @@@playground = Nonetry:playground = Playground(env_id="PPSrlH5TIvFx", get_envs=self.get_envs)- await playground.open()- await self.on_logs(- {- "message": f"Created playground",- "properties": {- "playground": "created",- "id": playground.id,+ rootdir = "/repo"++ async def initialize_playground():+ await playground.open()+ await self.on_logs(+ {+ "message": f"Created playground",+ "properties": {+ "playground": "created",+ "id": playground.id,- "run_id": run_id,+ },+ "type": "playground",+ }+ )+ span.add_event(+ "playground-created",+ {+ "playground.id": playground.id,},- "type": "playground",- },- )- span.add_event(- "playground-created",- {- "playground.id": playground.id,- },- )+ )+ await playground.sync_clock()+ await playground.change_rootdir(rootdir)+ await playground.make_dir(rootdir)+ await playground.clone_repo(+ repo_address=repo_address,+ rootdir=rootdir,+ branch=branch,+ )- await asyncio.ensure_future(playground.sync_clock())+ await self.on_logs(+ {+ "message": f"Cloned repository",+ "properties": {+ "tool": "git",+ "repository": f"{owner}/{repo}",- "run_id": run_id,+ },+ "type": "tool",+ }+ )+ span.add_event(+ "repository-cloned",+ {+ "repository": f"{owner}/{repo}",+ },+ )- rootdir = "/repo"- await playground.change_rootdir(rootdir)- await playground.make_dir(rootdir)+ extensions = " -o ".join(+ [f'-name "*{extension}"' for extension in extensions_to_skip]+ )- await playground.clone_repo(- repo_address=repo_address,- rootdir=rootdir,- branch=branch,- )+ delete_command = f"find . -path ./.git -prune -o ! \\( {extensions} \\) -type f -exec rm -f {{}} +"- await self.on_logs(- {- "message": f"Cloned repository",- "properties": {- "tool": "git",- "repository": f"{owner}/{repo}",+ print("Delete command: ", delete_command)++ res = await playground.run_command(delete_command, rootdir)+ print("Delete command result: ", res.stdout, res.stderr)++ await self.on_logs(+ {+ "message": f"Cleaned root directory",+ "properties": {+ "tool": "filesystem",- "run_id": run_id,+ },+ "type": "tool",+ }+ )++ span.add_event(+ "files-deleted",+ {+ "path": rootdir,},- "type": "tool",- },- )- span.add_event(- "repository-cloned",- {- "repository": f"{owner}/{repo}",- },- )+ )- extensions_to_skip = [- ".png",- ".jpg",- ".jpeg",- ".gif",- ".bmp",- ".svg",- ".ico",- ".tif",- ".tiff",- ]+ initializing_playground = asyncio.ensure_future(initialize_playground())filepaths_string, metadata = await self.generate_response("""You are an AI developer who is trying to write a program that will generate code for the user based on their intent.@@@ -300,10 -352,11 +350,10 @@@ do not add any other explanation, only"properties": {**metadata,"result": filepaths_string,- "model": "gpt-4",+ "model": model_version,- "run_id": run_id,},"type": "model",- }+ },)span.add_event(@@@ -377,10 -398,11 +395,10 @@@ Exclusively focus on the names of the s"properties": {**metadata,"result": shared_dependencies,- "model": "gpt-4",+ "model": model_version,- "run_id": run_id,},"type": "model",- }+ },)span.add_event(@@@ -420,35 -420,29 +416,28 @@@# Maximum number of allowed concurrent callssemaphore = asyncio.Semaphore(4)-- async def with_semaphore(coro):- async with semaphore:- return await coro-# execute the file generation in paralell and wait for all of them to finish. Use list comprehension to generate the tasks- coros = [- with_semaphore(- self.generate_file(- name,- filepaths_string=filepaths_string,- shared_dependencies=shared_dependencies,- prompt=user_prompt,+ generated_files = await asyncio.gather(+ *[+ with_semaphore(+ semaphore,+ self.generate_file(+ name,- run_id=run_id,+ filepaths_string=filepaths_string,+ shared_dependencies=shared_dependencies,+ prompt=user_prompt,+ ),)- )- for name in list_actual- # Filter out files that end with esxtensions we don't want to generate- if not any(- name.endswith(extension) for extension in extensions_to_skip- )- ]-- generated_files = await asyncio.gather(*coros)+ for name in list_actual+ # Filter out files that end with extensions we don't want to generate+ if not any(+ name.endswith(extension) for extension in extensions_to_skip+ )+ and not name.endswith("/")+ ]+ )- for (- name,- content,- _, # metadata- ) in generated_files:+ async def save_file(name, content):filepath = os.path.join(rootdir, name)await playground.write_file(filepath, content)await self.on_logs(@@@ -537,13 -546,15 +537,13 @@@"closed-playground",{},)- await self.on_logs(- {- "message": f"Agent run finished",- "properties": {},- "type": "info",- },- )+ await self.on_logs(+ {+ "message": f"Agent run finished",- "properties": {- "run_id": run_id,- },++ "properties": {},+ "type": "info",+ }+ )async def _dev_in_background(self, instructions: Any):print("Start agent run", bool(self._dev_loop))