(refactor) Make Runtime class synchronous (#3661)

* change runtime to be synchronous

* fix test runtime with the new interface

* fix arg

* fix eval

* fix missing config attribute

* fix plugins

* fix on_event by revert it back to async

* update upload_file endpoint

* fix argument to upload file

* remove unncessary async for eval;
fix evaluation run in parallel

* use asyncio to run controller for eval

* revert file upload

* truncate eval test result output
This commit is contained in:
Xingyao Wang
2024-08-29 20:37:03 -05:00
committed by GitHub
parent b0e52f121c
commit 090c911a50
33 changed files with 844 additions and 952 deletions

View File

@@ -406,7 +406,7 @@ async def list_files(request: Request, path: str | None = None):
content={'error': 'Runtime not yet initialized'},
)
runtime: Runtime = request.state.session.agent_session.runtime
file_list = await runtime.list_files(path)
file_list = runtime.list_files(path)
return file_list
@@ -440,7 +440,7 @@ async def select_file(file: str, request: Request):
)
read_action = FileReadAction(file)
observation = await runtime.run_action(read_action)
observation = runtime.run_action(read_action)
if isinstance(observation, FileReadObservation):
content = observation.content
@@ -519,7 +519,7 @@ async def upload_file(request: Request, files: list[UploadFile]):
tmp_file.flush()
runtime: Runtime = request.state.session.agent_session.runtime
await runtime.copy_to(
runtime.copy_to(
tmp_file_path, runtime.config.workspace_mount_path_in_sandbox
)
uploaded_files.append(safe_filename)
@@ -686,7 +686,7 @@ async def save_file(request: Request):
# Save the file to the agent's runtime file store
runtime: Runtime = request.state.session.agent_session.runtime
write_action = FileWriteAction(file_path, content)
observation = await runtime.run_action(write_action)
observation = runtime.run_action(write_action)
if isinstance(observation, FileWriteObservation):
return JSONResponse(

View File

@@ -69,7 +69,7 @@ class AgentSession:
end_state.save_to_session(self.sid, self.file_store)
await self.controller.close()
if self.runtime is not None:
await self.runtime.close()
self.runtime.close()
if self.security_analyzer is not None:
await self.security_analyzer.close()
self._closed = True
@@ -95,7 +95,6 @@ class AgentSession:
sid=self.sid,
plugins=agent.sandbox_plugins,
)
await self.runtime.ainit()
async def _create_controller(
self,