Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Improve retries and timeout handlings; Cancel individual tasks for generating files on agent failure
Tomas Valentaa835b83c9be4
diff --git a/api-service/agent/smol_agent.py b/api-service/agent/smol_agent.pyindex 623eddc94..a95a79a7f 100644--- a/api-service/agent/smol_agent.py+++ b/api-service/agent/smol_agent.py@@ -73,7 +73,7 @@ async def with_semaphore(semaphore, coro):class SmolAgent(AgentBase):- max_run_time = 60 * 60 # in seconds+ max_run_time = 2 * 60 * 60 # 2 hours in secondsdef __init__(self,@@ -248,6 +248,7 @@ Begin generating the code now.},)playground = None+ tasks: List[asyncio.Task[Any]] = []try:playground = Playground(env_id="PPSrlH5TIvFx", get_envs=self.get_envs)rootdir = "/repo"@@ -427,7 +428,7 @@ Exclusively focus on the names of the shared dependencies, and do not add any otprint("Filepaths:", ", ".join(list_actual))# Maximum number of allowed concurrent calls- semaphore = asyncio.Semaphore(4)+ semaphore = asyncio.Semaphore(2)# execute the file generation in paralell and wait for all of them to finish. Use list comprehension to generate the tasksasync def create_file(name):@@ -455,22 +456,24 @@ Exclusively focus on the names of the shared dependencies, and do not add any ot)await save_file(filename, content, group)- await asyncio.gather(- *[+ tasks = [+ asyncio.ensure_future(with_semaphore(semaphore,create_file(name,),)- 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 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("/")+ ]++ await asyncio.gather(*tasks)print("All files generated")@@ -514,6 +517,8 @@ Exclusively focus on the names of the shared dependencies, and do not add any ot})except Exception as e:+ for t in tasks:+ t.cancel()print(f"Failed agent run", e)await self.on_logs({diff --git a/api-service/models/base.py b/api-service/models/base.pyindex dbba32ab3..f9b308f2d 100644--- a/api-service/models/base.py+++ b/api-service/models/base.py@@ -51,7 +51,8 @@ def get_model(**config.args,request_timeout=3600,verbose=True,- max_retries=10,+ # The max time between retries is 1 minute so we set max_retries to 45+ max_retries=45,streaming=False,callback_manager=callback_manager,)diff --git a/api-service/playground/src/sessions/session.ts b/api-service/playground/src/sessions/session.tsindex 65238fc7a..34705ffb0 100644--- a/api-service/playground/src/sessions/session.ts+++ b/api-service/playground/src/sessions/session.ts@@ -4,7 +4,7 @@ import NodeCache from 'node-cache'import { CachedProcess, RunProcessParams } from './process'export const sessionCache = new NodeCache({- stdTTL: 3600,+ stdTTL: 7200,checkperiod: 200,useClones: false,deleteOnExpire: true,diff --git a/api-service/session/session.py b/api-service/session/session.pyindex d2e7a3f6b..3ce00793e 100644--- a/api-service/session/session.py+++ b/api-service/session/session.py@@ -18,7 +18,6 @@ configuration.verify_ssl = Falseconfiguration.ssl_ca_cert = Noneconfiguration.cert_file = None-GetEnvs = Callable[[], Coroutine[Any, Any, List[EnvVar]]]