diff --git a/openhands/controller/agent_controller.py b/openhands/controller/agent_controller.py index d0b806a3f19b..78b27c89ff7f 100644 --- a/openhands/controller/agent_controller.py +++ b/openhands/controller/agent_controller.py @@ -42,7 +42,7 @@ ) from openhands.events.serialization.event import truncate_content from openhands.llm.llm import LLM -from openhands.runtime.utils.shutdown_listener import should_continue +from openhands.utils.shutdown_listener import should_continue # note: RESUME is only available on web GUI TRAFFIC_CONTROL_REMINDER = ( diff --git a/openhands/events/stream.py b/openhands/events/stream.py index 625abd7a5221..24e95bf98147 100644 --- a/openhands/events/stream.py +++ b/openhands/events/stream.py @@ -9,9 +9,9 @@ from openhands.core.utils import json from openhands.events.event import Event, EventSource from openhands.events.serialization.event import event_from_dict, event_to_dict -from openhands.runtime.utils.shutdown_listener import should_continue from openhands.storage import FileStore from openhands.utils.async_utils import call_sync_from_async +from openhands.utils.shutdown_listener import should_continue class EventStreamSubscriber(str, Enum): diff --git a/openhands/llm/async_llm.py b/openhands/llm/async_llm.py index f2226dcd167a..ed84273c737b 100644 --- a/openhands/llm/async_llm.py +++ b/openhands/llm/async_llm.py @@ -7,7 +7,7 @@ from openhands.core.exceptions import UserCancelledError from openhands.core.logger import openhands_logger as logger from openhands.llm.llm import LLM, LLM_RETRY_EXCEPTIONS -from openhands.runtime.utils.shutdown_listener import should_continue +from openhands.utils.shutdown_listener import should_continue class AsyncLLM(LLM): diff --git a/openhands/runtime/__init__.py b/openhands/runtime/__init__.py index 66c89dadca15..16534daf6b56 100644 --- a/openhands/runtime/__init__.py +++ b/openhands/runtime/__init__.py @@ -1,31 +1,25 @@ from openhands.core.logger import openhands_logger as logger from openhands.runtime.impl.e2b.sandbox import E2BBox +from openhands.runtime.impl.eventstream.eventstream_runtime import ( + EventStreamRuntime, +) +from openhands.runtime.impl.modal.modal_runtime import ModalRuntime +from openhands.runtime.impl.remote.remote_runtime import RemoteRuntime +from openhands.runtime.impl.runloop.runloop_runtime import RunloopRuntime def get_runtime_cls(name: str): # Local imports to avoid circular imports if name == 'eventstream': - from openhands.runtime.impl.eventstream.eventstream_runtime import ( - EventStreamRuntime, - ) - return EventStreamRuntime elif name == 'e2b': - from openhands.runtime.impl.e2b.e2b_runtime import E2BRuntime - - return E2BRuntime + return E2BBox elif name == 'remote': - from openhands.runtime.impl.remote.remote_runtime import RemoteRuntime - return RemoteRuntime elif name == 'modal': logger.debug('Using ModalRuntime') - from openhands.runtime.impl.modal.modal_runtime import ModalRuntime - return ModalRuntime elif name == 'runloop': - from openhands.runtime.impl.runloop.runloop_runtime import RunloopRuntime - return RunloopRuntime else: raise ValueError(f'Runtime {name} not supported') @@ -33,5 +27,9 @@ def get_runtime_cls(name: str): __all__ = [ 'E2BBox', + 'RemoteRuntime', + 'ModalRuntime', + 'RunloopRuntime', + 'EventStreamRuntime', 'get_runtime_cls', ] diff --git a/openhands/runtime/browser/browser_env.py b/openhands/runtime/browser/browser_env.py index 9bad97b9bb2b..d9a7fd752956 100644 --- a/openhands/runtime/browser/browser_env.py +++ b/openhands/runtime/browser/browser_env.py @@ -16,7 +16,7 @@ from openhands.core.exceptions import BrowserInitException from openhands.core.logger import openhands_logger as logger -from openhands.runtime.utils.shutdown_listener import should_continue, should_exit +from openhands.utils.shutdown_listener import should_continue, should_exit from openhands.utils.tenacity_stop import stop_if_should_exit BROWSER_EVAL_GET_GOAL_ACTION = 'GET_EVAL_GOAL' diff --git a/openhands/runtime/builder/remote.py b/openhands/runtime/builder/remote.py index b1b14752cb89..c9d3228a70af 100644 --- a/openhands/runtime/builder/remote.py +++ b/openhands/runtime/builder/remote.py @@ -8,7 +8,7 @@ from openhands.core.logger import openhands_logger as logger from openhands.runtime.builder import RuntimeBuilder from openhands.runtime.utils.request import send_request -from openhands.runtime.utils.shutdown_listener import ( +from openhands.utils.shutdown_listener import ( should_continue, sleep_if_should_continue, ) diff --git a/openhands/runtime/plugins/jupyter/__init__.py b/openhands/runtime/plugins/jupyter/__init__.py index dd9842830283..23128b60a8f9 100644 --- a/openhands/runtime/plugins/jupyter/__init__.py +++ b/openhands/runtime/plugins/jupyter/__init__.py @@ -8,7 +8,7 @@ from openhands.runtime.plugins.jupyter.execute_server import JupyterKernel from openhands.runtime.plugins.requirement import Plugin, PluginRequirement from openhands.runtime.utils import find_available_tcp_port -from openhands.runtime.utils.shutdown_listener import should_continue +from openhands.utils.shutdown_listener import should_continue @dataclass diff --git a/openhands/runtime/utils/tenacity_stop.py b/openhands/runtime/utils/tenacity_stop.py index 48fdead86647..d9aa83a6130d 100644 --- a/openhands/runtime/utils/tenacity_stop.py +++ b/openhands/runtime/utils/tenacity_stop.py @@ -1,7 +1,7 @@ from tenacity import RetryCallState from tenacity.stop import stop_base -from openhands.runtime.utils.shutdown_listener import should_exit +from openhands.utils.shutdown_listener import should_exit class stop_if_should_exit(stop_base): diff --git a/openhands/server/mock/listen.py b/openhands/server/mock/listen.py index 9b9d1560e88b..81367a855d70 100644 --- a/openhands/server/mock/listen.py +++ b/openhands/server/mock/listen.py @@ -3,7 +3,7 @@ from openhands.core.logger import openhands_logger as logger from openhands.core.schema import ActionType -from openhands.runtime.utils.shutdown_listener import should_continue +from openhands.utils.shutdown_listener import should_continue app = FastAPI() diff --git a/openhands/server/session/session.py b/openhands/server/session/session.py index 25f707f15f53..e70d80e84f3e 100644 --- a/openhands/server/session/session.py +++ b/openhands/server/session/session.py @@ -21,9 +21,9 @@ from openhands.events.serialization import event_from_dict, event_to_dict from openhands.events.stream import EventStreamSubscriber from openhands.llm.llm import LLM -from openhands.runtime.utils.shutdown_listener import should_continue from openhands.server.session.agent_session import AgentSession from openhands.storage.files import FileStore +from openhands.utils.shutdown_listener import should_continue class Session: diff --git a/openhands/runtime/utils/shutdown_listener.py b/openhands/utils/shutdown_listener.py similarity index 100% rename from openhands/runtime/utils/shutdown_listener.py rename to openhands/utils/shutdown_listener.py diff --git a/openhands/utils/tenacity_stop.py b/openhands/utils/tenacity_stop.py index 48fdead86647..d9aa83a6130d 100644 --- a/openhands/utils/tenacity_stop.py +++ b/openhands/utils/tenacity_stop.py @@ -1,7 +1,7 @@ from tenacity import RetryCallState from tenacity.stop import stop_base -from openhands.runtime.utils.shutdown_listener import should_exit +from openhands.utils.shutdown_listener import should_exit class stop_if_should_exit(stop_base):